cli 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/functions/version"
  3. __rvm_fix_selected_ruby()
  4. {
  5. \typeset __ret=0
  6. if (( $# ))
  7. then "$@" || __ret=$?
  8. fi
  9. [[ -d "$GEM_HOME" && -d "$MY_RUBY_HOME" ]] ||
  10. {
  11. if [[ -d ${MY_RUBY_HOME%/*}/defaul ]]
  12. then __rvm_use default
  13. else __rvm_use system
  14. fi
  15. }
  16. }
  17. __rvm_path_match_gem_home_check_warn()
  18. {
  19. rvm_warn "\
  20. Warning! PATH is not properly set up, $1.
  21. <log>Usually this is caused by shell initialization files. Search for <code>PATH=...</code> entries.
  22. You can also re-add RVM to your profile by running: <code>rvm get stable --auto-dotfiles</code>
  23. To fix it temporarily in this shell session run: <code>rvm use $2</code>
  24. To ignore this error add <code>rvm_silence_path_mismatch_check_flag=1</code> to your <code>~/.rvmrc</code> file."
  25. }
  26. __rvm_path_match_gem_home_check_warning()
  27. {
  28. __rvm_path_match_gem_home_check_warn "$GEM_HOME/bin $1" "${GEM_HOME##*/}"
  29. }
  30. __rvm_path_match_gem_home_check_warning_missing()
  31. {
  32. __rvm_path_match_gem_home_check_warn "\$GEM_HOME is not set" "$1"
  33. }
  34. __rvm_path_match_gem_home_check()
  35. {
  36. (( ${rvm_silence_path_mismatch_check_flag:-0} == 0 )) || return 0
  37. if
  38. [[ -n "${GEM_HOME:-}" ]]
  39. then
  40. case "$PATH:" in
  41. ($GEM_HOME/bin:*) true ;; # all fine here
  42. (*:$GEM_HOME/bin:*)
  43. __rvm_path_match_gem_home_check_warning "is not at first place"
  44. ;;
  45. (*)
  46. __rvm_path_match_gem_home_check_warning "is not available"
  47. ;;
  48. esac
  49. else
  50. \typeset __path_to_ruby
  51. if
  52. __path_to_ruby="$( builtin command -v ruby 2>/dev/null )" &&
  53. [[ "${__path_to_ruby}" == "${rvm_path}"* ]]
  54. then
  55. # get the ruby string from path to ruby executable
  56. __path_to_ruby="${__path_to_ruby%/bin/ruby}"
  57. __path_to_ruby="${__path_to_ruby##*/}"
  58. # warning
  59. __rvm_path_match_gem_home_check_warning_missing "${__path_to_ruby}"
  60. fi
  61. fi
  62. }
  63. __rvm_use_ruby_warnings()
  64. {
  65. if [[ "${rvm_ruby_string}" == "system" || "${rvm_ruby_string}" == "" ]]
  66. then return 0
  67. fi
  68. \typeset __executable __gem_version
  69. for __executable in ruby gem irb
  70. do
  71. [[ -x "$MY_RUBY_HOME/bin/${__executable}" ]] ||
  72. rvm_warn "Warning! Executable '${__executable}' missing, something went wrong with this ruby installation!"
  73. done
  74. if
  75. [[ "${rvm_ruby_interpreter}" == "ruby" ]] &&
  76. {
  77. __rvm_version_compare "${rvm_ruby_version}" -ge 2.0.0 ||
  78. [[ "${rvm_ruby_version}" == "head" ]]
  79. } &&
  80. __rvm_which gem >/dev/null &&
  81. __gem_version="$(RUBYGEMS_GEMDEPS= gem --version)" &&
  82. [[ -n "${__gem_version}" ]] &&
  83. __rvm_version_compare "${__gem_version}" -lt "2.0.0"
  84. then
  85. rvm_warn "Warning! You have just used ruby 2.0.0 or newer, which is not fully compatible with rubygems 1.8.x or older,
  86. consider upgrading rubygems with: <code>rvm rubygems latest</code>"
  87. fi
  88. }
  89. __rvm_cli_posix_check()
  90. {
  91. if
  92. __rvm_has_opt "posix"
  93. then
  94. echo "RVM can not be run with \`set -o posix\`, please turn it off and try again."
  95. return 100
  96. fi
  97. }
  98. __rvm_cli_load_rvmrc()
  99. {
  100. if
  101. (( ${rvm_ignore_rvmrc:=0} == 0 ))
  102. then
  103. [[ -n "${rvm_stored_umask:-}" ]] || export rvm_stored_umask=$(umask)
  104. rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
  105. if
  106. [[ -n "${rvm_prefix:-}" ]] &&
  107. [[ ! "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
  108. then
  109. rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
  110. fi
  111. for rvmrc in "${rvm_rvmrc_files[@]}"
  112. do
  113. if
  114. [[ -f "$rvmrc" ]]
  115. then
  116. if
  117. __rvm_grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
  118. then
  119. printf "%b" "
  120. Error:
  121. $rvmrc is for rvm settings only.
  122. rvm CLI may NOT be called from within $rvmrc.
  123. Skipping the loading of $rvmrc"
  124. return 1
  125. else
  126. source "$rvmrc"
  127. fi
  128. fi
  129. done
  130. unset rvm_rvmrc_files
  131. fi
  132. }
  133. __rvm_cli_rvm_reload()
  134. {
  135. __rvm_project_rvmrc_lock=0
  136. rvm_reload_flag=1
  137. source "${rvm_scripts_path:-${rvm_path}/scripts}/rvm"
  138. }
  139. __rvm_cli_version_check()
  140. {
  141. \typeset disk_version
  142. disk_version="$( __rvm_version_installed )"
  143. if
  144. [[ -s "$rvm_path/VERSION" && "${rvm_version:-}" != "${disk_version:-}" && " $* " != *" reload "* ]]
  145. then
  146. if
  147. (( ${rvm_auto_reload_flag:-0} ))
  148. then
  149. __rvm_cli_rvm_reload
  150. else
  151. rvm_warn "RVM version <notify>${disk_version}</notify> is installed, yet version <error>${rvm_version}</error> is loaded.
  152. Please open a new shell or run one of the following commands:
  153. <code>rvm reload</code>
  154. <code>echo rvm_auto_reload_flag=1 >> ~/.rvmrc</code> <comment># OR for auto reload with msg</comment>
  155. <code>echo rvm_auto_reload_flag=2 >> ~/.rvmrc</code> <comment># OR for silent auto reload</comment>
  156. "
  157. return 1
  158. fi
  159. fi
  160. }
  161. __rvm_cli_autoupdate_version_old()
  162. {
  163. online_version="$( __rvm_version_remote )"
  164. version_release="$(\command \cat "$rvm_path/RELEASE" 2>/dev/null)"
  165. : version_release:"${version_release:=master}"
  166. if [[ "${online_version}-next" == "${rvm_version%% *}" ]]; then # development version newer than latest release
  167. return 1
  168. fi
  169. [[ -s "$rvm_path/VERSION" && -n "${online_version:-}" ]] && __rvm_version_compare "${rvm_version%% *}" -lt "${online_version:-}" || return $?
  170. }
  171. __rvm_cli_autoupdate_warning()
  172. {
  173. rvm_warn "Warning, new version of rvm available '${online_version}', you are using older version '${rvm_version%% *}'.
  174. You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
  175. You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
  176. You can update manually with: rvm get VERSION (e.g. 'rvm get stable')
  177. "
  178. }
  179. # duplication marker flnglfdjkngjndkfjhsbdjgfghdsgfklgg
  180. rvm_install_gpg_setup()
  181. {
  182. {
  183. rvm_gpg_command="$( \which gpg2 2>/dev/null )" &&
  184. [[ ${rvm_gpg_command} != "/cygdrive/"* ]]
  185. } || {
  186. rvm_gpg_command="$( \which gpg 2>/dev/null )" &&
  187. [[ ${rvm_gpg_command} != "/cygdrive/"* ]]
  188. } || rvm_gpg_command=""
  189. rvm_debug "Detected GPG program: '$rvm_gpg_command'"
  190. [[ -n "$rvm_gpg_command" ]] || return $?
  191. }
  192. # duplication marker rdjgndfnghdfnhgfdhbghdbfhgbfdhbn
  193. verify_package_pgp()
  194. {
  195. if
  196. "${rvm_gpg_command}" --verify "$2" "$1"
  197. then
  198. rvm_notify "GPG verified '$1'"
  199. else
  200. \typeset _return=$?
  201. rvm_error "\
  202. GPG signature verification failed for '$1' - '$3'! Try to install GPG v2 and then fetch the public key:
  203. ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  204. or if it fails:
  205. command curl -sSL https://rvm.io/mpapis.asc | ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --import -
  206. command curl -sSL https://rvm.io/pkuczynski.asc | ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --import -
  207. In case of further problems with validation please refer to https://rvm.io/rvm/security
  208. "
  209. return ${_return}
  210. fi
  211. }
  212. __rvm_cli_get_and_verify_pgp()
  213. {
  214. \typeset rvm_gpg_command
  215. if
  216. rvm_install_gpg_setup
  217. then
  218. pgp_signature_url="$( __rvm_curl -sSI https://get.rvm.io | \tr "\r" " " | __rvm_awk '/Location:/{print $2".asc"}' )"
  219. rvm_notify "Downloading $pgp_signature_url"
  220. __rvm_curl -s "${pgp_signature_url}" -o "${rvm_archives_path}/rvm-installer.asc" || return $?
  221. rvm_notify "Verifying ${rvm_archives_path}/rvm-installer.asc"
  222. verify_package_pgp "${rvm_archives_path}/rvm-installer" "${rvm_archives_path}/rvm-installer.asc" "$pgp_signature_url" || return $?
  223. else
  224. rvm_warn "No GPG software exists to validate rvm-installer, skipping."
  225. fi
  226. }
  227. __rvm_cli_get_installer_cleanup()
  228. {
  229. [[ -w "${rvm_archives_path}" ]] ||
  230. {
  231. rvm_error "Archives path '${rvm_archives_path}' not writable, aborting."
  232. return 1
  233. }
  234. [[ ! -e "${rvm_archives_path}/rvm-installer" ]] ||
  235. rm -f "${rvm_archives_path}/rvm-installer" ||
  236. {
  237. rvm_error "Previous installer '${rvm_archives_path}/rvm-installer' exists and can not be removed, aborting."
  238. return 2
  239. }
  240. }
  241. __rvm_cli_get_and_execute_installer()
  242. {
  243. __rvm_cli_get_installer_cleanup || return $?
  244. rvm_log "Downloading https://get.rvm.io"
  245. __rvm_curl -s https://get.rvm.io -o "${rvm_archives_path}/rvm-installer" ||
  246. {
  247. \typeset _ret=$?
  248. rvm_error "Could not download rvm-installer, please report to https://github.com/rvm/rvm/issues"
  249. return ${_ret}
  250. }
  251. __rvm_cli_get_and_verify_pgp || return $?
  252. bash "${rvm_archives_path}/rvm-installer" "$@" ||
  253. {
  254. \typeset _ret=$?
  255. rvm_error "Could not update RVM, please report to https://github.com/rvm/rvm/issues"
  256. return ${_ret}
  257. }
  258. }
  259. __rvm_cli_rvm_get()
  260. {
  261. case "$1" in
  262. ([0-9]*.[0-9]*.[0-9]*)
  263. rvm_warn "
  264. Hi there, it looks like you have requested updating rvm to version $1,
  265. if your intention was ruby installation use instead: rvm install $1
  266. "
  267. ;;
  268. esac
  269. case "$1" in
  270. (stable|master|head|branch|latest|latest-*|[0-9]*.[0-9]*.[0-9]*)
  271. __rvm_cli_get_and_execute_installer "$@" || return $?
  272. \typeset -x rvm_hook
  273. rvm_hook="after_update"
  274. source "${rvm_scripts_path:-"$rvm_path/scripts"}/hook"
  275. rvm_reload_flag=1
  276. ;;
  277. (*)
  278. rvm_help get
  279. ;;
  280. esac
  281. }
  282. __rvm_cli_autoupdate_execute()
  283. {
  284. printf "%b" "Found old RVM ${rvm_version%% *} - updating.\n"
  285. __rvm_cli_rvm_get "${version_release}" || return $?
  286. __rvm_cli_rvm_reload
  287. }
  288. __rvm_cli_autoupdate()
  289. {
  290. [[ " $* " == *" install "* && " $* " != *" help install "* ]] ||
  291. [[ " $* " == *" list known "* ]] ||
  292. return 0
  293. \typeset online_version version_release
  294. case "${rvm_autoupdate_flag:-1}" in
  295. (0|disabled)
  296. true
  297. ;;
  298. (1|warn)
  299. if __rvm_cli_autoupdate_version_old
  300. then __rvm_cli_autoupdate_warning
  301. fi
  302. ;;
  303. (2|enabled)
  304. if __rvm_cli_autoupdate_version_old
  305. then __rvm_cli_autoupdate_execute || return $?
  306. fi
  307. ;;
  308. esac
  309. true
  310. }
  311. __rvm_cli_autoreload()
  312. {
  313. if
  314. [[ ${rvm_reload_flag:-0} -eq 1 ]]
  315. then
  316. if
  317. [[ -s "$rvm_scripts_path/rvm" ]]
  318. then
  319. __rvm_project_rvmrc_lock=0
  320. source "$rvm_scripts_path/rvm"
  321. else
  322. echo "rvm not found in $rvm_path, please install and run 'rvm reload'"
  323. __rvm_teardown
  324. fi
  325. else
  326. __rvm_teardown
  327. fi
  328. }
  329. __rvm_cli_install_ruby()
  330. (
  331. if
  332. [[ -n "$1" ]]
  333. then
  334. \typeset __rubies __installed __missing __search_list
  335. \typeset -a __search
  336. __rvm_custom_separated_array __search , "$1"
  337. __rubies="$1"
  338. __search_list=""
  339. __rvm_cli_rubies_select || return $?
  340. if __rvm_cli_rubies_not_installed
  341. then __rvm_run_wrapper manage install "${__rubies}" || return $?
  342. fi
  343. else
  344. rvm_error "Can not use or install 'all' rubies. You can get a list of installable rubies with 'rvm list known'."
  345. false #report error
  346. fi
  347. )
  348. __rvm_cli_rubies_select()
  349. {
  350. \typeset __ruby
  351. for __ruby in "${__search[@]}"
  352. do
  353. rvm_ruby_string="${__ruby}"
  354. __rvm_select &&
  355. if [[ -n "$rvm_ruby_string" ]]
  356. then __search_list+="^$rvm_ruby_string\$|"
  357. else
  358. rvm_error "Could not detect ruby version/name for installation '${__ruby}', please be more specific."
  359. return 1
  360. fi
  361. done
  362. __search_list="${__search_list%|}"
  363. }
  364. __rvm_cli_rubies_not_installed()
  365. {
  366. if
  367. (( ${rvm_force_flag:-0} == 0 )) &&
  368. __installed="$(
  369. __rvm_list_strings | __rvm_grep -E "${__search_list}"
  370. )" &&
  371. [[ -n "${__installed}" ]]
  372. then
  373. rvm_warn "Already installed ${__installed//|/,}.
  374. To reinstall use:
  375. rvm reinstall ${__installed//|/,}
  376. "
  377. return 2
  378. fi
  379. true
  380. }