2011-01-05 19:05:36 +00:00
|
|
|
#!/usr/bin/env bash
|
2009-05-13 09:32:19 +00:00
|
|
|
|
2012-11-16 13:42:48 +00:00
|
|
|
function help_msg {
|
|
|
|
echo "./install.sh [OPTION..]"
|
2012-02-08 19:22:39 +00:00
|
|
|
echo
|
2013-02-13 18:14:52 +00:00
|
|
|
echo " -a, --auto Try to determine destdir, prefix (and zshshare if applicable)"
|
2012-11-16 13:42:48 +00:00
|
|
|
echo " -g, --global Use default global settings (destdir=/; prefix=usr)"
|
|
|
|
echo " -l, --local Use default local settings (destdir=~/.autojump)"
|
2012-02-08 19:22:39 +00:00
|
|
|
echo
|
2012-11-16 13:42:48 +00:00
|
|
|
echo " -d, --destdir PATH Set install destination to PATH"
|
|
|
|
echo " -p, --prefix PATH Use PATH as prefix"
|
2013-02-13 18:14:52 +00:00
|
|
|
echo " -Z, --zshshare PATH Use PATH as zsh share destination"
|
2012-03-15 20:52:25 +00:00
|
|
|
echo
|
2012-11-22 20:51:46 +00:00
|
|
|
echo " -f, --force Ignore Python version check"
|
2012-11-22 17:37:36 +00:00
|
|
|
echo " -n, --dry_run Only show installation paths, don't install anything"
|
2012-03-15 20:52:25 +00:00
|
|
|
echo
|
2012-11-16 13:42:48 +00:00
|
|
|
echo "Will install autojump into:"
|
2012-11-22 18:01:21 +00:00
|
|
|
echo
|
2012-11-16 13:42:48 +00:00
|
|
|
echo ' Binaries: $destdir$prefix/bin'
|
|
|
|
echo ' Documentation: $destdir$prefix/share/man/man1'
|
|
|
|
echo ' Icon: $destdir$prefix/share/autojump'
|
|
|
|
echo ' Shell scripts: $destdir/etc/profile.d'
|
2013-02-13 18:14:52 +00:00
|
|
|
echo ' zsh functions: $destdir$zshsharedir'
|
|
|
|
echo
|
|
|
|
echo 'Unless specified, $zshshare will be :'
|
|
|
|
echo ' - $destdir$prefix/functions for local installations'
|
|
|
|
echo ' - $destdir$prefix/share/zsh/site-functions for all other installations'
|
2012-02-07 05:56:46 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 17:37:36 +00:00
|
|
|
dry_run=
|
2012-11-16 13:42:48 +00:00
|
|
|
local=
|
2012-11-22 22:33:05 +00:00
|
|
|
global=
|
2012-04-12 09:03:03 +00:00
|
|
|
force=
|
2012-11-22 18:01:21 +00:00
|
|
|
shell=`echo ${SHELL} | awk -F/ '{ print $NF }'`
|
2012-11-16 13:42:48 +00:00
|
|
|
destdir=
|
|
|
|
prefix="usr/local"
|
2013-02-13 18:14:52 +00:00
|
|
|
zshsharedir=
|
2010-06-07 09:10:22 +00:00
|
|
|
|
2012-11-22 17:21:31 +00:00
|
|
|
# If no arguments passed, default to --auto.
|
|
|
|
if [[ ${#} == 0 ]]; then
|
|
|
|
set -- "--auto"
|
|
|
|
fi
|
|
|
|
|
2012-11-23 09:42:02 +00:00
|
|
|
# Only dry-run should also default to --auto
|
|
|
|
if [[ ${#} == 1 ]] && ([[ $1 = "-n" ]] || [[ $1 = "--dry-run" ]]); then
|
|
|
|
set -- "-n" "--auto"
|
|
|
|
fi
|
|
|
|
|
2010-07-11 20:39:41 +00:00
|
|
|
# Command line parsing
|
2010-06-07 09:10:22 +00:00
|
|
|
while true; do
|
|
|
|
case "$1" in
|
2012-11-16 13:42:48 +00:00
|
|
|
-a|--auto)
|
|
|
|
if [[ ${UID} -eq 0 ]]; then
|
2012-11-22 17:21:31 +00:00
|
|
|
set -- "--global" "${@:2}"
|
2012-11-16 13:42:48 +00:00
|
|
|
else
|
2012-11-22 17:21:31 +00:00
|
|
|
set -- "--local" "${@:2}"
|
2012-11-16 13:42:48 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
-d|--destdir)
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
destdir=$2; shift 2
|
|
|
|
else
|
|
|
|
echo "--destdir or -d requires an argument" 1>&2
|
|
|
|
fi
|
|
|
|
;;
|
2012-04-12 09:03:03 +00:00
|
|
|
-f|--force)
|
|
|
|
force=true
|
|
|
|
shift
|
2012-11-22 20:45:10 +00:00
|
|
|
if [[ ${#} == 0 ]]; then
|
|
|
|
set -- "--auto"
|
|
|
|
fi
|
2012-04-12 09:03:03 +00:00
|
|
|
;;
|
2012-03-15 20:52:25 +00:00
|
|
|
-g|--global)
|
2012-11-22 22:33:05 +00:00
|
|
|
global=true
|
2012-11-16 13:42:48 +00:00
|
|
|
destdir=
|
|
|
|
prefix=usr
|
2012-03-15 20:52:25 +00:00
|
|
|
shift
|
|
|
|
;;
|
2012-02-08 01:40:57 +00:00
|
|
|
-h|--help|-\?)
|
2012-02-08 19:22:39 +00:00
|
|
|
help_msg;
|
2012-02-08 01:40:57 +00:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-l|--local)
|
2012-02-08 02:21:37 +00:00
|
|
|
local=true
|
2012-11-16 13:42:48 +00:00
|
|
|
destdir=~/.autojump
|
|
|
|
prefix=
|
|
|
|
shift
|
|
|
|
;;
|
2012-11-22 17:37:36 +00:00
|
|
|
-n|--dry_run)
|
|
|
|
dry_run=true
|
2012-02-08 01:40:57 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-p|--prefix)
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
prefix=$2; shift 2
|
|
|
|
else
|
2012-03-15 20:52:25 +00:00
|
|
|
echo "--prefix or -p requires an argument" 1>&2
|
2012-02-08 09:32:30 +00:00
|
|
|
exit 1
|
2012-02-08 01:40:57 +00:00
|
|
|
fi
|
|
|
|
;;
|
2013-02-13 18:14:52 +00:00
|
|
|
-Z|--zshshare)
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
zshsharedir=$2; shift 2
|
|
|
|
else
|
|
|
|
echo "--zshshare or -Z requires an argument" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
2012-02-08 01:40:57 +00:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
-*)
|
|
|
|
echo "invalid option: $1" 1>&2;
|
2012-02-08 19:22:39 +00:00
|
|
|
help_msg;
|
2012-02-08 01:40:57 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
2010-06-07 09:10:22 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2012-11-16 13:42:48 +00:00
|
|
|
# destdir must be a full path, and end with a slash
|
|
|
|
if [[ -n ${destdir} ]]; then
|
|
|
|
if [[ ${destdir:0:1} != "/" ]]; then
|
|
|
|
echo "Error: destdir must be a full path" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
len=${#destdir}
|
|
|
|
if [[ ${destdir:len - 1} != "/" ]]; then
|
|
|
|
destdir="$destdir/"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
destdir="/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# prefix should not start with, and end with, a slash
|
|
|
|
if [[ -n ${prefix} ]]; then
|
|
|
|
if [[ ${prefix:0:1} == "/" ]]; then
|
|
|
|
prefix=${prefix:1}
|
|
|
|
fi
|
|
|
|
len=${#prefix}
|
|
|
|
if [[ ${prefix:len - 1} != "/" ]]; then
|
|
|
|
prefix="$prefix/"
|
|
|
|
fi
|
2012-03-15 20:52:25 +00:00
|
|
|
fi
|
|
|
|
|
2012-11-22 18:01:21 +00:00
|
|
|
# check shell support
|
|
|
|
if [[ ${shell} != "bash" ]] && [[ ${shell} != "zsh" ]]; then
|
2012-11-22 20:51:46 +00:00
|
|
|
echo "Unsupported shell (${shell}). Only Bash and Zsh shells are supported."
|
2012-03-15 20:16:33 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2013-02-13 18:14:52 +00:00
|
|
|
# zsh functions
|
|
|
|
if [[ $shell == "zsh" ]]; then
|
|
|
|
if [[ -z $zshsharedir ]]; then
|
|
|
|
# if not set, use a default
|
|
|
|
if [[ $local ]]; then
|
|
|
|
zshsharedir="${prefix}functions"
|
|
|
|
else
|
|
|
|
zshsharedir="${prefix}share/zsh/site-functions"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-02-09 19:24:46 +00:00
|
|
|
# check Python version
|
2012-04-12 09:03:03 +00:00
|
|
|
if [ ! ${force} ]; then
|
|
|
|
python_version=`python -c 'import sys; print(sys.version_info[:])'`
|
|
|
|
|
2012-09-26 20:04:45 +00:00
|
|
|
if [[ ${python_version:1:1} -eq 2 && ${python_version:4:1} -lt 6 ]]; then
|
2012-04-12 09:03:03 +00:00
|
|
|
echo
|
2012-09-26 20:04:45 +00:00
|
|
|
echo "Incompatible Python version, please upgrade to v2.6+."
|
|
|
|
if [[ ${python_version:4:1} -ge 4 ]]; then
|
2012-04-12 09:03:03 +00:00
|
|
|
echo
|
|
|
|
echo "Alternatively, you can download v12 that supports Python v2.4+ from:"
|
|
|
|
echo
|
|
|
|
echo -e "\thttps://github.com/joelthelion/autojump/downloads"
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
exit 1
|
2012-02-10 21:06:24 +00:00
|
|
|
fi
|
2012-02-09 19:24:46 +00:00
|
|
|
fi
|
|
|
|
|
2012-02-08 20:04:41 +00:00
|
|
|
echo
|
2012-11-16 13:42:48 +00:00
|
|
|
echo "Installating autojump..."
|
|
|
|
echo
|
|
|
|
echo "Destination: $destdir"
|
|
|
|
if [[ -n $prefix ]]; then
|
|
|
|
echo "Prefix: /$prefix"
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
echo "Binary: ${destdir}${prefix}bin/"
|
|
|
|
echo "Documentation: ${destdir}${prefix}share/man/man1/"
|
|
|
|
echo "Icon: ${destdir}${prefix}share/autojump/"
|
|
|
|
echo "Shell scripts: ${destdir}etc/profile.d/"
|
2013-02-13 18:14:52 +00:00
|
|
|
if [[ -z $shell ]] || [[ $shell == "zsh" ]]; then
|
|
|
|
echo "zsh functions: ${destdir}${zshsharedir}"
|
|
|
|
fi
|
2012-02-08 20:04:41 +00:00
|
|
|
echo
|
2010-06-07 09:10:22 +00:00
|
|
|
|
2012-11-22 17:37:36 +00:00
|
|
|
if [[ $dry_run ]]; then
|
|
|
|
echo "--dry_run (-n) used, stopping"
|
2012-11-16 13:42:48 +00:00
|
|
|
exit
|
|
|
|
fi
|
2012-02-08 19:22:39 +00:00
|
|
|
|
2012-11-16 13:42:48 +00:00
|
|
|
# INSTALL AUTOJUMP
|
2012-11-22 18:27:38 +00:00
|
|
|
mkdir -p ${destdir}${prefix}share/autojump/ || exit 1
|
|
|
|
mkdir -p ${destdir}${prefix}bin/ || exit 1
|
|
|
|
mkdir -p ${destdir}${prefix}share/man/man1/ || exit 1
|
|
|
|
cp -v ./bin/icon.png ${destdir}${prefix}share/autojump/ || exit 1
|
|
|
|
cp -v ./bin/autojump ${destdir}${prefix}bin/ || exit 1
|
|
|
|
cp -v ./bin/autojump_argparse.py ${destdir}${prefix}bin/ || exit 1
|
|
|
|
cp -v ./docs/autojump.1 ${destdir}${prefix}share/man/man1/ || exit 1
|
|
|
|
mkdir -p ${destdir}etc/profile.d/ || exit 1
|
|
|
|
cp -v ./bin/autojump.sh ${destdir}etc/profile.d/ || exit 1
|
|
|
|
cp -v ./bin/autojump.bash ${destdir}etc/profile.d/ || exit 1
|
|
|
|
cp -v ./bin/autojump.zsh ${destdir}etc/profile.d/ || exit 1
|
2013-02-13 18:14:52 +00:00
|
|
|
mkdir -p ${destdir}${zshsharedir} || exit 1
|
|
|
|
# TODO: remove unused _j function (2013.02.01_1348, ting)
|
|
|
|
install -v -m 0755 ./bin/_j ${destdir}${zshsharedir} || exit 1
|
2010-07-11 20:39:41 +00:00
|
|
|
|
2012-11-22 22:33:05 +00:00
|
|
|
# MODIFY AUTOJUMP.SH FOR CUSTOM INSTALLS
|
|
|
|
if [[ -z ${local} ]] && [[ -z ${global} ]]; then
|
2013-04-25 00:05:56 +00:00
|
|
|
sed -i "s:#custom#\t::g" ${destdir}etc/profile.d/autojump.sh
|
|
|
|
sed -i "s:destdir_install\t:${destdir}etc/profile.d:g" ${destdir}etc/profile.d/autojump.sh
|
2012-11-22 22:33:05 +00:00
|
|
|
fi
|
|
|
|
|
2012-11-22 18:24:39 +00:00
|
|
|
# DISPLAY ADD MESSAGE
|
2012-11-22 19:57:17 +00:00
|
|
|
rc_file="~/.${shell}rc"
|
2012-11-22 18:24:39 +00:00
|
|
|
if [[ `uname` == "Darwin" ]] && [[ ${shell} == "bash" ]]; then
|
2012-11-22 19:57:17 +00:00
|
|
|
rc_file="~/.bash_profile"
|
|
|
|
fi
|
|
|
|
|
2012-11-22 22:33:05 +00:00
|
|
|
aj_shell_file="${destdir}etc/profile.d/autojump.sh"
|
2012-11-22 19:57:17 +00:00
|
|
|
if [[ ${local} ]]; then
|
2012-11-22 22:33:05 +00:00
|
|
|
aj_shell_file="~/.autojump/etc/profile.d/autojump.sh"
|
2012-11-22 18:24:39 +00:00
|
|
|
fi
|
2012-11-22 19:57:17 +00:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Please add the line to ${rc_file} :"
|
|
|
|
echo
|
|
|
|
echo -e "[[ -s ${aj_shell_file} ]] && . ${aj_shell_file}"
|
2012-11-22 18:24:39 +00:00
|
|
|
echo
|
2012-11-22 19:57:17 +00:00
|
|
|
echo "You need to run 'source ${rc_file}' before you can start using autojump. To remove autojump, run './uninstall.sh'"
|
2012-11-22 18:24:39 +00:00
|
|
|
echo
|