Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

248 linhas
7.0 KiB

15 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
12 anos atrás
  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" ]] \
  143. && [[ ${shell} != "fish" ]]; then
  144. echo "Unsupported shell (${shell}). Only Bash and Zsh shells are supported."
  145. exit 1
  146. fi
  147. # zsh functions
  148. if [[ $shell == "zsh" ]]; then
  149. if [[ -z $zshsharedir ]]; then
  150. # if not set, use a default
  151. if [[ $local ]]; then
  152. zshsharedir="${prefix}functions"
  153. else
  154. zshsharedir="${prefix}share/zsh/site-functions"
  155. fi
  156. fi
  157. fi
  158. # check Python version
  159. if [ ! ${force} ]; then
  160. python_version=`python -c 'import sys; print(sys.version_info[:])'`
  161. if [[ ${python_version:1:1} -eq 2 && ${python_version:4:1} -lt 6 ]]; then
  162. echo
  163. echo "Incompatible Python version, please upgrade to v2.6+."
  164. if [[ ${python_version:4:1} -ge 4 ]]; then
  165. echo
  166. echo "Alternatively, you can download v12 that supports Python v2.4+ from:"
  167. echo
  168. echo -e "\thttps://github.com/joelthelion/autojump/downloads"
  169. echo
  170. fi
  171. exit 1
  172. fi
  173. fi
  174. echo
  175. echo "Installating autojump..."
  176. echo
  177. echo "Destination: $destdir"
  178. if [[ -n $prefix ]]; then
  179. echo "Prefix: /$prefix"
  180. fi
  181. echo
  182. echo "Binary: ${destdir}${prefix}bin/"
  183. echo "Documentation: ${destdir}${prefix}share/man/man1/"
  184. echo "Icon: ${destdir}${prefix}share/autojump/"
  185. echo "Shell scripts: ${destdir}etc/profile.d/"
  186. if [[ -z $shell ]] || [[ $shell == "zsh" ]]; then
  187. echo "zsh functions: ${destdir}${zshsharedir}"
  188. fi
  189. echo
  190. if [[ $dry_run ]]; then
  191. echo "--dry_run (-n) used, stopping"
  192. exit
  193. fi
  194. # INSTALL AUTOJUMP
  195. mkdir -p ${destdir}${prefix}share/autojump/ || exit 1
  196. mkdir -p ${destdir}${prefix}bin/ || exit 1
  197. mkdir -p ${destdir}${prefix}share/man/man1/ || exit 1
  198. cp -v ./bin/icon.png ${destdir}${prefix}share/autojump/ || exit 1
  199. cp -v ./bin/autojump ${destdir}${prefix}bin/ || exit 1
  200. cp -v ./bin/autojump_argparse.py ${destdir}${prefix}bin/ || exit 1
  201. cp -v ./docs/autojump.1 ${destdir}${prefix}share/man/man1/ || exit 1
  202. mkdir -p ${destdir}etc/profile.d/ || exit 1
  203. cp -v ./bin/autojump.sh ${destdir}etc/profile.d/ || exit 1
  204. cp -v ./bin/autojump.bash ${destdir}etc/profile.d/ || exit 1
  205. cp -v ./bin/autojump.zsh ${destdir}etc/profile.d/ || exit 1
  206. cp -v ./bin/autojump.fish ${destdir}etc/profile.d/ || exit 1
  207. mkdir -p ${destdir}${zshsharedir} || exit 1
  208. # TODO: remove unused _j function (2013.02.01_1348, ting)
  209. install -v -m 0755 ./bin/_j ${destdir}${zshsharedir} || exit 1
  210. # MODIFY AUTOJUMP.SH FOR CUSTOM INSTALLS
  211. if [[ -z ${local} ]] && [[ -z ${global} ]]; then
  212. sed -i "s:#custom#\t::g" ${destdir}etc/profile.d/autojump.sh
  213. sed -i "s:destdir_install\t:${destdir}etc/profile.d:g" ${destdir}etc/profile.d/autojump.sh
  214. fi
  215. # DISPLAY ADD MESSAGE
  216. rc_file="~/.${shell}rc"
  217. if [[ `uname` == "Darwin" ]] && [[ ${shell} == "bash" ]]; then
  218. rc_file="~/.bash_profile"
  219. fi
  220. aj_shell_file="${destdir}etc/profile.d/autojump.${shell}"
  221. if [[ ${local} ]]; then
  222. aj_shell_file="~/.autojump/etc/profile.d/autojump.${shell}"
  223. fi
  224. echo
  225. echo "Please add the line to ${rc_file} :"
  226. echo
  227. echo -e "[[ -s ${aj_shell_file} ]] && . ${aj_shell_file}"
  228. echo
  229. echo "You need to run 'source ${rc_file}' before you can start using autojump. To remove autojump, run './uninstall.sh'"
  230. echo