From c069b18298c4e1018bf6ed958a60ba1ab235ca8f Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Tue, 6 Sep 2016 11:13:44 -0700 Subject: [PATCH] Add get_distro function, fix java setup in arch --- dotfiles/lib/setup_functions.sh | 29 +++++++++++++++++++++++++++++ dotfiles/lib/shellpath.sh | 27 +++++++++++++++++---------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/dotfiles/lib/setup_functions.sh b/dotfiles/lib/setup_functions.sh index ed753802..c224e476 100644 --- a/dotfiles/lib/setup_functions.sh +++ b/dotfiles/lib/setup_functions.sh @@ -19,6 +19,35 @@ function add_to_path { eval "$($_python_command $HOME/.lib/python/shell_path.py --include-assignment "$@")" } +# Taken from http://www.unix.com/shell-programming-and-scripting/27932-how-know-linux-distribution-i-am-using.html +function get_distro { + # start with uname and branch the decision from there + dist=$(uname -s 2> /dev/null) + if [ "$dist" = "Linux" ]; then + get_linux_distro && return 0 + elif [ -n "$dist" ]; then + echo "$dist" + return 0 + fi + proc_version || echo "Unknown" + return 1 +} + +function get_linux_distro { + if [ -r /etc/lsb-release ]; then + dist=$(grep 'DISTRIB_ID' /etc/lsb-release | sed 's/DISTRIB_ID=//' | head -1) + [ -n "$dist" ] && echo "$dist" && return 0 + fi + + dist=$(find /etc/ -maxdepth 1 -name '*release' 2> /dev/null | sed 's/\/etc\///' | sed 's/-release//' | head -1) + [ -n "$dist" ] && echo "$dist" && return 0 + + dist=$(find /etc/ -maxdepth 1 -name '*version' 2> /dev/null | sed 's/\/etc\///' | sed 's/-version//' | head -1) + [ -n "$dist" ] && echo "$dist" && return 0 + return 1 +} + + function is_osx() { case `uname` in 'Darwin') diff --git a/dotfiles/lib/shellpath.sh b/dotfiles/lib/shellpath.sh index 7a228026..965ed7ef 100644 --- a/dotfiles/lib/shellpath.sh +++ b/dotfiles/lib/shellpath.sh @@ -17,13 +17,17 @@ function _setup_env { } function _osx_path_setup { - hash brew 2>/dev/null && add_to_path --before "$(brew --prefix coreutils)/libexec/gnubin" + if command_exists "brew"; + add_to_path --before "$(brew --prefix coreutils)/libexec/gnubin" + # Access gnu man pages. + add_to_path "$(brew --prefix)/opt/coreutils/libexec/gnuman" --path-var "MANPATH" + then # Adds airport utility add_to_path "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources" --after - # I believe that this is here because of some issue with - # python builds in OSX + # I believe that this is here because of some issue with python builds in + # OSX export CFLAGS=-Qunused-arguments export CPPFLAGS=-Qunused-arguments } @@ -58,15 +62,18 @@ function _java_setup { export GRADLE_HOME="$(brew --prefix gradle)" export ANDROID_HOME="$(brew --prefix android-sdk)" add_to_path "$ANDROID_HOME" --after - - # Access gnu man pages. - hash brew 2> /dev/null && export MANPATH="$(brew --prefix)/opt/coreutils/libexec/gnuman:$MANPATH" - else - # This may be ubuntu/debian specific - export JAVA_HOME="$(update-alternatives --config java | get_cols ' -1' | head -n 1)" - is_osx && export VISUAL="which emacsclient -c -n" fi + case get_distro in + Arch) + # Arch does not seem to need to set JAVA_HOME + ;; + Debian) + # This may be ubuntu/debian specific + export JAVA_HOME="$(update-alternatives --config java | get_cols ' -1' | head -n 1)" + ;; + esac + add_to_path "$JAVA_HOME/bin" }