1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00

add default installation location depending on user id (globally for root, otherwise local)

This commit is contained in:
William Ting 2012-03-15 10:52:25 -10:00
parent bbe54c3b22
commit d4e5895edf

View File

@ -34,13 +34,26 @@ function add_msg {
} }
function help_msg { function help_msg {
echo "sudo ./install.sh [--local] [--prefix /usr/local] [--zsh]" echo
echo "./install.sh [--global or --local] [--bash or --zsh] [--prefix /usr/] "
echo
echo "If run without any arguments, the installer will:"
echo
echo -e "\t- as root install globally into /usr/"
echo -e "\t- as non-root install locally to ~/.autojump/"
echo -e "\t- version will be based on \$SHELL environmental variable"
echo
} }
# Default install directory. # Default install directory.
prefix=/usr
shell=`echo ${SHELL} | awk -F/ '{ print $NF }'` shell=`echo ${SHELL} | awk -F/ '{ print $NF }'`
local= if [[ ${UID} -eq 0 ]]; then
local=
prefix=/usr
else
local=true
prefix=~/.autojump
fi
user=${SUDO_USER:-${USER}} user=${SUDO_USER:-${USER}}
OS=`uname` OS=`uname`
@ -59,6 +72,10 @@ while true; do
shell="bash" shell="bash"
shift shift
;; ;;
-g|--global)
local=
shift
;;
-h|--help|-\?) -h|--help|-\?)
help_msg; help_msg;
exit 0 exit 0
@ -72,7 +89,7 @@ while true; do
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
prefix=$2; shift 2 prefix=$2; shift 2
else else
echo "--prefix or -p require an argument" 1>&2 echo "--prefix or -p requires an argument" 1>&2
exit 1 exit 1
fi fi
;; ;;
@ -95,13 +112,18 @@ while true; do
esac esac
done done
# check for valid local install options
if [[ ${UID} != 0 ]] && [ ! ${local} ]; then
echo
echo "Please rerun as root or use the --local option."
echo
exit 1
fi
# check shell if supported # check shell if supported
if [[ ${shell} != "bash" ]] && [[ ${shell} != "zsh" ]]; then if [[ ${shell} != "bash" ]] && [[ ${shell} != "zsh" ]]; then
echo "Unsupported shell (${shell}). Use --bash or --zsh to explicitly define shell." echo "Unsupported shell (${shell}). Use --bash or --zsh to explicitly define shell."
exit 1 exit 1
else
echo "Installing ${shell} version."
exit 0
fi fi
# check Python version # check Python version
@ -119,16 +141,8 @@ if [[ ${python_version:1:1} -eq 2 && ${python_version:4:1} -lt 6 ]]; then
exit 1 exit 1
fi fi
# check for valid options
if [[ ${UID} != 0 ]] && [ ! ${local} ]; then
echo
echo "Please rerun as root or use the --local option."
echo
exit 1
fi
echo echo
echo "Installing files to ${prefix} ..." echo "Installing ${shell} version of autojump to ${prefix} ..."
echo echo
# add git revision to autojump # add git revision to autojump