Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

245 rindas
6.9 KiB

pirms 15 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
pirms 12 gadiem
  1. #!/usr/bin/env bash
  2. function help_msg {
  3. echo "./install.sh [OPTION..]"
  4. echo
  5. echo " -a, --auto Try to determine destdir, prefix (and zshshare if applicable)"
  6. echo " -g, --global Use default global settings (destdir=/; prefix=usr)"
  7. echo " -l, --local Use default local settings (destdir=~/.autojump)"
  8. echo
  9. echo " -d, --destdir PATH Set install destination to PATH"
  10. echo " -p, --prefix PATH Use PATH as prefix"
  11. echo " -Z, --zshshare PATH Use PATH as zsh share destination"
  12. echo
  13. echo " -f, --force Ignore Python version check"
  14. echo " -n, --dry_run Only show installation paths, don't install anything"
  15. echo
  16. echo "Will install autojump into:"
  17. echo
  18. echo ' Binaries: $destdir$prefix/bin'
  19. echo ' Documentation: $destdir$prefix/share/man/man1'
  20. echo ' Icon: $destdir$prefix/share/autojump'
  21. echo ' Shell scripts: $destdir/etc/profile.d'
  22. echo ' zsh functions: $destdir$zshsharedir'
  23. echo
  24. echo 'Unless specified, $zshshare will be :'
  25. echo ' - $destdir$prefix/functions for local installations'
  26. echo ' - $destdir$prefix/share/zsh/site-functions for all other installations'
  27. }
  28. dry_run=
  29. local=
  30. global=
  31. force=
  32. shell=`echo ${SHELL} | awk -F/ '{ print $NF }'`
  33. destdir=
  34. prefix="usr/local"
  35. zshsharedir=
  36. # If no arguments passed, default to --auto.
  37. if [[ ${#} == 0 ]]; then
  38. set -- "--auto"
  39. fi
  40. # Only dry-run should also default to --auto
  41. if [[ ${#} == 1 ]] && ([[ $1 = "-n" ]] || [[ $1 = "--dry-run" ]]); then
  42. set -- "-n" "--auto"
  43. fi
  44. # Command line parsing
  45. while true; do
  46. case "$1" in
  47. -a|--auto)
  48. if [[ ${UID} -eq 0 ]]; then
  49. set -- "--global" "${@:2}"
  50. else
  51. set -- "--local" "${@:2}"
  52. fi
  53. ;;
  54. -d|--destdir)
  55. if [ $# -gt 1 ]; then
  56. destdir=$2; shift 2
  57. else
  58. echo "--destdir or -d requires an argument" 1>&2
  59. fi
  60. ;;
  61. -f|--force)
  62. force=true
  63. shift
  64. if [[ ${#} == 0 ]]; then
  65. set -- "--auto"
  66. fi
  67. ;;
  68. -g|--global)
  69. global=true
  70. destdir=
  71. prefix=usr
  72. shift
  73. ;;
  74. -h|--help|-\?)
  75. help_msg;
  76. exit 0
  77. ;;
  78. -l|--local)
  79. local=true
  80. destdir=~/.autojump
  81. prefix=
  82. shift
  83. ;;
  84. -n|--dry_run)
  85. dry_run=true
  86. shift
  87. ;;
  88. -p|--prefix)
  89. if [ $# -gt 1 ]; then
  90. prefix=$2; shift 2
  91. else
  92. echo "--prefix or -p requires an argument" 1>&2
  93. exit 1
  94. fi
  95. ;;
  96. -Z|--zshshare)
  97. if [ $# -gt 1 ]; then
  98. zshsharedir=$2; shift 2
  99. else
  100. echo "--zshshare or -Z requires an argument" 1>&2
  101. exit 1
  102. fi
  103. ;;
  104. --)
  105. shift
  106. break
  107. ;;
  108. -*)
  109. echo "invalid option: $1" 1>&2;
  110. help_msg;
  111. exit 1
  112. ;;
  113. *)
  114. break
  115. ;;
  116. esac
  117. done
  118. # destdir must be a full path, and end with a slash
  119. if [[ -n ${destdir} ]]; then
  120. if [[ ${destdir:0:1} != "/" ]]; then
  121. echo "Error: destdir must be a full path" 1>&2
  122. exit 1
  123. fi
  124. len=${#destdir}
  125. if [[ ${destdir:len - 1} != "/" ]]; then
  126. destdir="$destdir/"
  127. fi
  128. else
  129. destdir="/"
  130. fi
  131. # prefix should not start with, and end with, a slash
  132. if [[ -n ${prefix} ]]; then
  133. if [[ ${prefix:0:1} == "/" ]]; then
  134. prefix=${prefix:1}
  135. fi
  136. len=${#prefix}
  137. if [[ ${prefix:len - 1} != "/" ]]; then
  138. prefix="$prefix/"
  139. fi
  140. fi
  141. # check shell support
  142. if [[ ${shell} != "bash" ]] && [[ ${shell} != "zsh" ]]; then
  143. echo "Unsupported shell (${shell}). Only Bash and Zsh shells are supported."
  144. exit 1
  145. fi
  146. # zsh functions
  147. if [[ $shell == "zsh" ]]; then
  148. if [[ -z $zshsharedir ]]; then
  149. # if not set, use a default
  150. if [[ $local ]]; then
  151. zshsharedir="${prefix}functions"
  152. else
  153. zshsharedir="${prefix}share/zsh/site-functions"
  154. fi
  155. fi
  156. fi
  157. # check Python version
  158. if [ ! ${force} ]; then
  159. python_version=`python -c 'import sys; print(sys.version_info[:])'`
  160. if [[ ${python_version:1:1} -eq 2 && ${python_version:4:1} -lt 6 ]]; then
  161. echo
  162. echo "Incompatible Python version, please upgrade to v2.6+."
  163. if [[ ${python_version:4:1} -ge 4 ]]; then
  164. echo
  165. echo "Alternatively, you can download v12 that supports Python v2.4+ from:"
  166. echo
  167. echo -e "\thttps://github.com/joelthelion/autojump/downloads"
  168. echo
  169. fi
  170. exit 1
  171. fi
  172. fi
  173. echo
  174. echo "Installating autojump..."
  175. echo
  176. echo "Destination: $destdir"
  177. if [[ -n $prefix ]]; then
  178. echo "Prefix: /$prefix"
  179. fi
  180. echo
  181. echo "Binary: ${destdir}${prefix}bin/"
  182. echo "Documentation: ${destdir}${prefix}share/man/man1/"
  183. echo "Icon: ${destdir}${prefix}share/autojump/"
  184. echo "Shell scripts: ${destdir}etc/profile.d/"
  185. if [[ -z $shell ]] || [[ $shell == "zsh" ]]; then
  186. echo "zsh functions: ${destdir}${zshsharedir}"
  187. fi
  188. echo
  189. if [[ $dry_run ]]; then
  190. echo "--dry_run (-n) used, stopping"
  191. exit
  192. fi
  193. # INSTALL AUTOJUMP
  194. mkdir -p ${destdir}${prefix}share/autojump/ || exit 1
  195. mkdir -p ${destdir}${prefix}bin/ || exit 1
  196. mkdir -p ${destdir}${prefix}share/man/man1/ || exit 1
  197. cp -v ./bin/icon.png ${destdir}${prefix}share/autojump/ || exit 1
  198. cp -v ./bin/autojump ${destdir}${prefix}bin/ || exit 1
  199. cp -v ./bin/autojump_argparse.py ${destdir}${prefix}bin/ || exit 1
  200. cp -v ./docs/autojump.1 ${destdir}${prefix}share/man/man1/ || exit 1
  201. mkdir -p ${destdir}etc/profile.d/ || exit 1
  202. cp -v ./bin/autojump.sh ${destdir}etc/profile.d/ || exit 1
  203. cp -v ./bin/autojump.bash ${destdir}etc/profile.d/ || exit 1
  204. cp -v ./bin/autojump.zsh ${destdir}etc/profile.d/ || exit 1
  205. mkdir -p ${destdir}${zshsharedir} || exit 1
  206. # TODO: remove unused _j function (2013.02.01_1348, ting)
  207. install -v -m 0755 ./bin/_j ${destdir}${zshsharedir} || exit 1
  208. # MODIFY AUTOJUMP.SH FOR CUSTOM INSTALLS
  209. if [[ -z ${local} ]] && [[ -z ${global} ]]; then
  210. sed -i "s:custom_install:${destdir}etc/profile.d:g" ${destdir}etc/profile.d/autojump.sh
  211. fi
  212. # DISPLAY ADD MESSAGE
  213. rc_file="~/.${shell}rc"
  214. if [[ `uname` == "Darwin" ]] && [[ ${shell} == "bash" ]]; then
  215. rc_file="~/.bash_profile"
  216. fi
  217. aj_shell_file="${destdir}etc/profile.d/autojump.sh"
  218. if [[ ${local} ]]; then
  219. aj_shell_file="~/.autojump/etc/profile.d/autojump.sh"
  220. fi
  221. echo
  222. echo "Please add the line to ${rc_file} :"
  223. echo
  224. echo -e "[[ -s ${aj_shell_file} ]] && . ${aj_shell_file}"
  225. echo
  226. echo "You need to run 'source ${rc_file}' before you can start using autojump. To remove autojump, run './uninstall.sh'"
  227. echo