rvm-installer 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  1. #!/usr/bin/env bash
  2. shopt -s extglob
  3. set -o errtrace
  4. set -o errexit
  5. set -o pipefail
  6. rvm_install_initialize()
  7. {
  8. DEFAULT_SOURCES=(github.com/rvm/rvm bitbucket.org/mpapis/rvm)
  9. BASH_MIN_VERSION="3.2.25"
  10. if
  11. [[ -n "${BASH_VERSION:-}" &&
  12. "$(\printf "%b" "${BASH_VERSION:-}\n${BASH_MIN_VERSION}\n" | LC_ALL=C \sort -t"." -k1,1n -k2,2n -k3,3n | \head -n1)" != "${BASH_MIN_VERSION}"
  13. ]]
  14. then
  15. echo "BASH ${BASH_MIN_VERSION} required (you have $BASH_VERSION)"
  16. exit 1
  17. fi
  18. export HOME PS4
  19. export rvm_trace_flag rvm_debug_flag rvm_user_install_flag rvm_ignore_rvmrc rvm_prefix rvm_path
  20. PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > "
  21. }
  22. log() { printf "%b\n" "$*"; }
  23. debug(){ [[ ${rvm_debug_flag:-0} -eq 0 ]] || printf "%b\n" "$*" >&2; }
  24. warn() { log "WARN: $*" >&2 ; }
  25. fail() { fail_with_code 1 "$*" ; }
  26. fail_with_code() { code="$1" ; shift ; log "\nERROR: $*\n" >&2 ; exit "$code" ; }
  27. rvm_install_commands_setup()
  28. {
  29. \which which >/dev/null 2>&1 || fail "Could not find 'which' command, make sure it's available first before continuing installation."
  30. \which grep >/dev/null 2>&1 || fail "Could not find 'grep' command, make sure it's available first before continuing installation."
  31. if
  32. [[ -z "${rvm_tar_command:-}" ]] && builtin command -v gtar >/dev/null
  33. then
  34. rvm_tar_command=gtar
  35. elif
  36. ${rvm_tar_command:-tar} --help 2>&1 | GREP_OPTIONS="" \grep -- --strip-components >/dev/null
  37. then
  38. rvm_tar_command="${rvm_tar_command:-tar}"
  39. else
  40. case "$(uname)" in
  41. (OpenBSD)
  42. log "Trying to install GNU version of tar, might require sudo password"
  43. if (( UID ))
  44. then sudo pkg_add -z gtar-1
  45. else pkg_add -z gtar-1
  46. fi
  47. rvm_tar_command=gtar
  48. ;;
  49. (Darwin|FreeBSD|DragonFly) # it's not possible to autodetect on OSX, the help/man does not mention all flags
  50. rvm_tar_command=tar
  51. ;;
  52. (SunOS)
  53. case "$(uname -r)" in
  54. (5.10)
  55. log "Trying to install GNU version of tar, might require sudo password"
  56. if (( UID ))
  57. then
  58. if \which sudo >/dev/null 2>&1
  59. then sudo_10=sudo
  60. elif \which /opt/csw/bin/sudo >/dev/null 2>&1
  61. then sudo_10=/opt/csw/bin/sudo
  62. else fail "sudo is required but not found. You may install sudo from OpenCSW repository (https://www.opencsw.org/about)"
  63. fi
  64. pkginfo -q CSWpkgutil || $sudo_10 pkgadd -a $rvm_path/config/solaris/noask -d https://get.opencsw.org/now CSWpkgutil
  65. sudo /opt/csw/bin/pkgutil -iy CSWgtar -t https://mirror.opencsw.org/opencsw/unstable
  66. else
  67. pkginfo -q CSWpkgutil || pkgadd -a $rvm_path/config/solaris/noask -d https://get.opencsw.org/now CSWpkgutil
  68. /opt/csw/bin/pkgutil -iy CSWgtar -t https://mirror.opencsw.org/opencsw/unstable
  69. fi
  70. rvm_tar_command=/opt/csw/bin/gtar
  71. ;;
  72. (*)
  73. rvm_tar_command=tar
  74. ;;
  75. esac
  76. esac
  77. builtin command -v ${rvm_tar_command:-gtar} >/dev/null ||
  78. fail "Could not find GNU compatible version of 'tar' command, make sure it's available first before continuing installation."
  79. fi
  80. if
  81. [[ " ${rvm_tar_options:-} " != *" --no-same-owner "* ]] &&
  82. $rvm_tar_command --help 2>&1 | GREP_OPTIONS="" \grep -- --no-same-owner >/dev/null
  83. then
  84. rvm_tar_options="${rvm_tar_options:-}${rvm_tar_options:+ }--no-same-owner"
  85. fi
  86. }
  87. usage()
  88. {
  89. printf "%b" "
  90. Usage
  91. rvm-installer [options] [action]
  92. Options
  93. [[--]version] <version>
  94. The version or tag to install. Valid values are:
  95. latest - The latest tagged version.
  96. latest-minor - The latest minor version of the current major version.
  97. latest-<x> - The latest minor version of version x.
  98. latest-<x>.<y> - The latest patch version of version x.y.
  99. <x>.<y>.<z> - Major version x, minor version y and patch z.
  100. [--]branch <branch>
  101. The name of the branch from which RVM is installed. This option can be used
  102. with the following formats for <branch>:
  103. <account>/
  104. If account is rvm or mpapis, installs from one of the following:
  105. https://github.com/rvm/rvm/archive/master.tar.gz
  106. https://bitbucket.org/mpapis/rvm/get/master.tar.gz
  107. Otherwise, installs from:
  108. https://github.com/<account>/rvm/archive/master.tar.gz
  109. <account>/<branch>
  110. If account is rvm or mpapis, installs from one of the following:
  111. https://github.com/rvm/rvm/archive/<branch>.tar.gz
  112. https://bitbucket.org/mpapis/rvm/get/<branch>.tar.gz
  113. Otherwise, installs from:
  114. https://github.com/<account>/rvm/archive/<branch>.tar.gz
  115. [/]<branch>
  116. Installs the branch from one of the following:
  117. https://github.com/rvm/rvm/archive/<branch>.tar.gz
  118. https://bitbucket.org/mpapis/rvm/get/<branch>.tar.gz
  119. [--]source <source>
  120. Defines the repository from which RVM is retrieved and installed in the format:
  121. <domain>/<account>/<repo>
  122. Where:
  123. <domain> - Is bitbucket.org, github.com or a github enterprise site serving
  124. an RVM repository.
  125. <account> - Is the user account in which the RVM repository resides.
  126. <repo> - Is the name of the RVM repository.
  127. Note that when using the [--]source option, one should only use the [/]branch format
  128. with the [--]branch option. Failure to do so will result in undefined behavior.
  129. --trace
  130. Provides debug logging for the installation script.
  131. Actions
  132. master - Installs RVM from the master branch at rvm/rvm on github or mpapis/rvm
  133. on bitbucket.org.
  134. stable - Installs RVM from the stable branch a rvm/rvm on github or mpapis/rvm
  135. on bitbucket.org.
  136. help - Displays this output.
  137. "
  138. }
  139. ## duplication marker 32fosjfjsznkjneuera48jae
  140. __rvm_curl_output_control()
  141. {
  142. if
  143. (( ${rvm_quiet_curl_flag:-0} == 1 ))
  144. then
  145. __flags+=( "--silent" "--show-error" )
  146. elif
  147. [[ " $*" == *" -s"* || " $*" == *" --silent"* ]]
  148. then
  149. # make sure --show-error is used with --silent
  150. [[ " $*" == *" -S"* || " $*" == *" -sS"* || " $*" == *" --show-error"* ]] ||
  151. {
  152. __flags+=( "--show-error" )
  153. }
  154. fi
  155. }
  156. ## duplication marker 32fosjfjsznkjneuera48jae
  157. # -S is automatically added to -s
  158. __rvm_curl()
  159. (
  160. __rvm_which curl >/dev/null ||
  161. {
  162. rvm_error "RVM requires 'curl'. Install 'curl' first and try again."
  163. return 200
  164. }
  165. typeset -a __flags
  166. __flags=( --fail --location --max-redirs 10 )
  167. [[ "$*" == *"--max-time"* ]] ||
  168. [[ "$*" == *"--connect-timeout"* ]] ||
  169. __flags+=( --connect-timeout 30 --retry-delay 2 --retry 3 )
  170. if [[ -n "${rvm_proxy:-}" ]]
  171. then __flags+=( --proxy "${rvm_proxy:-}" )
  172. fi
  173. __rvm_curl_output_control
  174. unset curl
  175. __rvm_debug_command \curl "${__flags[@]}" "$@" || return $?
  176. )
  177. rvm_error() { printf "ERROR: %b\n" "$*"; }
  178. __rvm_which(){ which "$@" || return $?; true; }
  179. __rvm_debug_command()
  180. {
  181. debug "Running($#): $*"
  182. "$@" || return $?
  183. true
  184. }
  185. rvm_is_a_shell_function()
  186. {
  187. [[ -t 0 && -t 1 ]] || return $?
  188. return ${rvm_is_not_a_shell_function:-0}
  189. }
  190. # Searches the tags for the highest available version matching a given pattern.
  191. # fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) 1.10. -> 1.10.3
  192. # fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) 1.10. -> 1.10.3
  193. # fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) 1. -> 1.11.0
  194. # fetch_version (github.com/rvm/rvm bitbucket.org/mpapis/rvm) "" -> 2.0.1
  195. fetch_version()
  196. {
  197. typeset _account _domain _pattern _repo _sources _values _version
  198. _sources=(${!1})
  199. _pattern=$2
  200. for _source in "${_sources[@]}"
  201. do
  202. IFS='/' read -r _domain _account _repo <<< "${_source}"
  203. _version="$(
  204. fetch_versions ${_domain} ${_account} ${_repo} |
  205. GREP_OPTIONS="" \grep "^${_pattern:-}" | tail -n 1
  206. )"
  207. if
  208. [[ -n ${_version} ]]
  209. then
  210. echo "${_version}"
  211. return 0
  212. fi
  213. done
  214. fail_with_code 4 "Exhausted all sources trying to fetch version '$version' of RVM!"
  215. }
  216. # Returns a sorted list of most recent tags from a repository
  217. fetch_versions()
  218. {
  219. typeset _account _domain _repo _url
  220. _domain=$1
  221. _account=$2
  222. _repo=$3
  223. case ${_domain} in
  224. (bitbucket.org)
  225. _url="https://api.${_domain}/2.0/repositories/${_account}/${_repo}/refs/tags?sort=-name&pagelen=20"
  226. ;;
  227. (github.com)
  228. _url=https://api.${_domain}/repos/${_account}/${_repo}/tags
  229. ;;
  230. (*)
  231. _url=https://${_domain}/api/v3/repos/${_account}/${_repo}/tags
  232. ;;
  233. esac
  234. { __rvm_curl -sS "${_url}" || warn "...the preceeding error with code $? occurred while fetching $_url" ; } |
  235. \awk -v RS=',|values":' -v FS='"' '$2=="name"&&$4!="rvm"{print $4}' |
  236. sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n
  237. }
  238. install_release()
  239. {
  240. typeset _source _sources _url _version _verify_pgp
  241. _sources=(${!1})
  242. _version=$2
  243. debug "Downloading RVM version ${_version}"
  244. for _source in "${_sources[@]}"
  245. do
  246. case ${_source} in
  247. (bitbucket.org*)
  248. _url="https://${_source}/get/${_version}.tar.gz"
  249. _verify_pgp="https://${_source}/downloads/${_version}.tar.gz.asc"
  250. ;;
  251. (*)
  252. _url="https://${_source}/archive/${_version}.tar.gz"
  253. _verify_pgp="https://${_source}/releases/download/${_version}/${_version}.tar.gz.asc"
  254. ;;
  255. esac
  256. get_and_unpack "${_url}" "rvm-${_version}.tgz" "$_verify_pgp" && return
  257. done
  258. return $?
  259. }
  260. install_head()
  261. {
  262. typeset _branch _source _sources _url
  263. _sources=(${!1})
  264. _branch=$2
  265. debug "Selected RVM branch ${_branch}"
  266. for _source in "${_sources[@]}"
  267. do
  268. case ${_source} in
  269. (bitbucket.org*)
  270. _url=https://${_source}/get/${_branch}.tar.gz
  271. ;;
  272. (*)
  273. _url=https://${_source}/archive/${_branch}.tar.gz
  274. ;;
  275. esac
  276. get_and_unpack "${_url}" "rvm-${_branch//\//_}.tgz" && return
  277. done
  278. return $?
  279. }
  280. # duplication marker dfkjdjngdfjngjcszncv
  281. # Drop in cd which _doesn't_ respect cdpath
  282. __rvm_cd()
  283. {
  284. typeset old_cdpath ret
  285. ret=0
  286. old_cdpath="${CDPATH}"
  287. CDPATH="."
  288. chpwd_functions="" builtin cd "$@" || ret=$?
  289. CDPATH="${old_cdpath}"
  290. return $ret
  291. }
  292. get_package()
  293. {
  294. typeset _url _file
  295. _url="$1"
  296. _file="$2"
  297. log "Downloading ${_url}"
  298. __rvm_curl -sS ${_url} > ${rvm_archives_path}/${_file} ||
  299. {
  300. _return=$?
  301. case $_return in
  302. # duplication marker lfdgzkngdkjvnfjknkjvcnbjkncvjxbn
  303. (60)
  304. log "
  305. Could not download '${_url}', you can read more about it here:
  306. https://rvm.io/support/fixing-broken-ssl-certificates/
  307. To continue in insecure mode run 'echo insecure >> ~/.curlrc'.
  308. "
  309. ;;
  310. # duplication marker lfdgzkngdkjvnfjknkjvcnbjkncvjxbn
  311. (77)
  312. log "
  313. It looks like you have old certificates, you can read more about it here:
  314. https://rvm.io/support/fixing-broken-ssl-certificates/
  315. "
  316. ;;
  317. # duplication marker lfdgzkngdkjvnfjknkjvcnbjkncvjxbn
  318. (141)
  319. log "
  320. Curl returned 141 - it is result of a segfault which means it's Curls fault.
  321. Try again and if it crashes more than a couple of times you either need to
  322. reinstall Curl or consult with your distribution manual and contact support.
  323. "
  324. ;;
  325. (*)
  326. log "
  327. Could not download '${_url}'.
  328. curl returned status '$_return'.
  329. "
  330. ;;
  331. esac
  332. return $_return
  333. }
  334. }
  335. # duplication marker flnglfdjkngjndkfjhsbdjgfghdsgfklgg
  336. rvm_install_gpg_setup()
  337. {
  338. export rvm_gpg_command
  339. {
  340. rvm_gpg_command="$( \which gpg2 2>/dev/null )" &&
  341. [[ ${rvm_gpg_command} != "/cygdrive/"* ]]
  342. } || {
  343. rvm_gpg_command="$( \which gpg 2>/dev/null )" &&
  344. [[ ${rvm_gpg_command} != "/cygdrive/"* ]]
  345. } || rvm_gpg_command=""
  346. debug "Detected GPG program: '$rvm_gpg_command'"
  347. [[ -n "$rvm_gpg_command" ]] || return $?
  348. }
  349. # duplication marker rdjgndfnghdfnhgfdhbghdbfhgbfdhbn
  350. verify_package_pgp()
  351. {
  352. if
  353. "${rvm_gpg_command}" --verify "$2" "$1"
  354. then
  355. log "GPG verified '$1'"
  356. else
  357. typeset _return=$?
  358. log "\
  359. GPG signature verification failed for '$1' - '$3'! Try to install GPG v2 and then fetch the public key:
  360. ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  361. or if it fails:
  362. command curl -sSL https://rvm.io/mpapis.asc | ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --import -
  363. command curl -sSL https://rvm.io/pkuczynski.asc | ${SUDO_USER:+sudo }${rvm_gpg_command##*/} --import -
  364. In case of further problems with validation please refer to https://rvm.io/rvm/security
  365. "
  366. exit ${_return}
  367. fi
  368. }
  369. verify_pgp()
  370. {
  371. [[ -n "${1:-}" ]] ||
  372. {
  373. debug "No PGP url given, skipping."
  374. return 0
  375. }
  376. get_package "$1" "$2.asc" ||
  377. {
  378. debug "PGP url given but does not exist: '$1'"
  379. return 0
  380. }
  381. rvm_install_gpg_setup ||
  382. {
  383. log "Found PGP signature at: '$1',
  384. but no GPG software exists to validate it, skipping."
  385. return 0
  386. }
  387. verify_package_pgp "${rvm_archives_path}/$2" "${rvm_archives_path}/$2.asc" "$1"
  388. }
  389. get_and_unpack()
  390. {
  391. typeset _url _file _patern _return _verify_pgp
  392. _url="$1"
  393. _file="$2"
  394. _verify_pgp="$3"
  395. get_package "$_url" "$_file" || return $?
  396. verify_pgp "$_verify_pgp" "$_file" || return $?
  397. [[ -d "${rvm_src_path}/rvm" ]] || \mkdir -p "${rvm_src_path}/rvm"
  398. __rvm_cd "${rvm_src_path}/rvm" ||
  399. {
  400. _return=$?
  401. log "Could not change directory '${rvm_src_path}/rvm'."
  402. return $_return
  403. }
  404. # Remove existing installation
  405. typeset _cleanup_cmd
  406. _cleanup_cmd="rm -rf ${rvm_src_path}/rvm/{,.[!.],..?}*"
  407. $_cleanup_cmd || {
  408. _return=$?
  409. log "Could not remove old RVM sources. Try:\n\n\tsudo $_cleanup_cmd\n\nThen retry your task again."
  410. return $_return
  411. }
  412. # Unpack sources
  413. __rvm_debug_command $rvm_tar_command xzf ${rvm_archives_path}/${_file} ${rvm_tar_options:-} --strip-components 1 ||
  414. {
  415. _return=$?
  416. log "Could not extract RVM sources."
  417. return $_return
  418. }
  419. }
  420. rvm_install_default_settings()
  421. {
  422. # Tracing, if asked for.
  423. if
  424. [[ "$*" == *--trace* ]] || (( ${rvm_trace_flag:-0} > 0 ))
  425. then
  426. set -o xtrace
  427. rvm_trace_flag=1
  428. fi
  429. # Variable initialization, remove trailing slashes if they exist on HOME
  430. true \
  431. ${rvm_trace_flag:=0} ${rvm_debug_flag:=0}\
  432. ${rvm_ignore_rvmrc:=0} HOME="${HOME%%+(\/)}"
  433. if
  434. (( rvm_ignore_rvmrc == 0 ))
  435. then
  436. for rvmrc in /etc/rvmrc "$HOME/.rvmrc"
  437. do
  438. if
  439. [[ -s "$rvmrc" ]]
  440. then
  441. if
  442. GREP_OPTIONS="" \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
  443. then
  444. printf "%b" "
  445. Error: $rvmrc is for rvm settings only.
  446. rvm CLI may NOT be called from within $rvmrc.
  447. Skipping the loading of $rvmrc
  448. "
  449. exit 1
  450. else
  451. source "$rvmrc"
  452. fi
  453. fi
  454. done
  455. fi
  456. if
  457. [[ -z "${rvm_path:-}" ]]
  458. then
  459. if
  460. (( UID == 0 ))
  461. then
  462. rvm_user_install_flag=0
  463. rvm_prefix="/usr/local"
  464. rvm_path="${rvm_prefix}/rvm"
  465. else
  466. rvm_user_install_flag=1
  467. rvm_prefix="$HOME"
  468. rvm_path="${rvm_prefix}/.rvm"
  469. fi
  470. fi
  471. if [[ -z "${rvm_prefix}" ]]
  472. then rvm_prefix=$( dirname $rvm_path )
  473. fi
  474. # duplication marker kkdfkgnjfndgjkndfjkgnkfjdgn
  475. [[ -n "${rvm_user_install_flag:-}" ]] ||
  476. case "$rvm_path" in
  477. (/usr/local/rvm) rvm_user_install_flag=0 ;;
  478. ($HOME/*|/${USER// /_}*) rvm_user_install_flag=1 ;;
  479. (*) rvm_user_install_flag=0 ;;
  480. esac
  481. }
  482. rvm_install_parse_params()
  483. {
  484. install_rubies=()
  485. install_gems=()
  486. flags=( ./scripts/install )
  487. forwarded_flags=()
  488. while
  489. (( $# > 0 ))
  490. do
  491. token="$1"
  492. shift
  493. case "$token" in
  494. (--trace)
  495. set -o xtrace
  496. rvm_trace_flag=1
  497. flags=( -x "${flags[@]}" "$token" )
  498. forwarded_flags+=( "$token" )
  499. ;;
  500. (--debug|--quiet-curl)
  501. flags+=( "$token" )
  502. forwarded_flags+=( "$token" )
  503. token=${token#--}
  504. token=${token//-/_}
  505. export "rvm_${token}_flag"=1
  506. printf "%b" "Turning on ${token/_/ } mode.\n"
  507. ;;
  508. (--path)
  509. if [[ -n "${1:-}" ]]
  510. then
  511. rvm_path="$1"
  512. shift
  513. else
  514. fail "--path must be followed by a path."
  515. fi
  516. ;;
  517. (--branch|branch) # Install RVM from a given branch
  518. if [[ -n "${1:-}" ]]
  519. then
  520. case "$1" in
  521. (/*)
  522. branch=${1#/}
  523. ;;
  524. (*/)
  525. branch=master
  526. if [[ "${1%/}" -ne rvm ]] && [[ "${1%/}" -ne mpapis ]]
  527. then sources=(github.com/${1%/}/rvm)
  528. fi
  529. ;;
  530. (*/*)
  531. branch=${1#*/}
  532. if [[ "${1%%/*}" -ne rvm ]] && [[ "${1%%/*}" -ne mpapis ]]
  533. then sources=(github.com/${1%%/*}/rvm)
  534. fi
  535. ;;
  536. (*)
  537. branch="$1"
  538. ;;
  539. esac
  540. shift
  541. else
  542. fail "--branch must be followed by a branchname."
  543. fi
  544. ;;
  545. (--source|source)
  546. if [[ -n "${1:-}" ]]
  547. then
  548. if [[ "$1" = */*/* ]]
  549. then
  550. sources=($1)
  551. shift
  552. else
  553. fail "--source must be in the format <domain>/<account>/<repo>."
  554. fi
  555. else
  556. fail "--source must be followed by a source."
  557. fi
  558. ;;
  559. (--user-install|--ignore-dotfiles)
  560. token=${token#--}
  561. token=${token//-/_}
  562. export "rvm_${token}_flag"=1
  563. printf "%b" "Turning on ${token/_/ } mode.\n"
  564. ;;
  565. (--auto-dotfiles)
  566. flags+=( "$token" )
  567. export "rvm_auto_dotfiles_flag"=1
  568. printf "%b" "Turning on auto dotfiles mode.\n"
  569. ;;
  570. (--auto)
  571. export "rvm_auto_dotfiles_flag"=1
  572. printf "%b" "Warning, --auto is deprecated in favor of --auto-dotfiles.\n"
  573. ;;
  574. (--verify-downloads)
  575. if [[ -n "${1:-}" ]]
  576. then
  577. export rvm_verify_downloads_flag="$1"
  578. forwarded_flags+=( "$token" "$1" )
  579. shift
  580. else
  581. fail "--verify-downloads must be followed by level(0|1|2)."
  582. fi
  583. ;;
  584. (--autolibs=*)
  585. flags+=( "$token" )
  586. export rvm_autolibs_flag="${token#--autolibs=}"
  587. forwarded_flags+=( "$token" )
  588. ;;
  589. (--without-gems=*|--with-gems=*|--with-default-gems=*)
  590. flags+=( "$token" )
  591. value="${token#*=}"
  592. token="${token%%=*}"
  593. token="${token#--}"
  594. token="${token//-/_}"
  595. export "rvm_${token}"="${value}"
  596. printf "%b" "Installing RVM ${token/_/ }: ${value}.\n"
  597. ;;
  598. (--version|version)
  599. version="$1"
  600. shift
  601. ;;
  602. (head|master)
  603. version="head"
  604. branch="master"
  605. ;;
  606. (stable)
  607. version="latest"
  608. ;;
  609. (latest|latest-*|+([[:digit:]]).+([[:digit:]]).+([[:digit:]]))
  610. version="$token"
  611. ;;
  612. (--ruby)
  613. install_rubies+=( ruby )
  614. ;;
  615. (--ruby=*)
  616. token=${token#--ruby=}
  617. install_rubies+=( ${token//,/ } )
  618. ;;
  619. (--rails)
  620. install_gems+=( rails )
  621. ;;
  622. (--gems=*)
  623. token=${token#--gems=}
  624. install_gems+=( ${token//,/ } )
  625. ;;
  626. (--add-to-rvm-group)
  627. export rvm_add_users_to_rvm_group="$1"
  628. shift
  629. ;;
  630. (help)
  631. usage
  632. exit 0
  633. ;;
  634. (*)
  635. usage
  636. exit 1
  637. ;;
  638. esac
  639. done
  640. if (( ${#install_gems[@]} > 0 && ${#install_rubies[@]} == 0 ))
  641. then install_rubies=( ruby )
  642. fi
  643. true "${version:=head}"
  644. true "${branch:=master}"
  645. if [[ -z "${sources[@]}" ]]
  646. then sources=("${DEFAULT_SOURCES[@]}")
  647. fi
  648. rvm_src_path="$rvm_path/src"
  649. rvm_archives_path="$rvm_path/archives"
  650. rvm_releases_url="https://rvm.io/releases"
  651. }
  652. rvm_install_validate_rvm_path()
  653. {
  654. case "$rvm_path" in
  655. (*[[:space:]]*)
  656. printf "%b" "
  657. It looks you are one of the happy *space* users (in home dir name),
  658. RVM is not yet fully ready for it, use this trick to fix it:
  659. sudo mkdir -p /${USER// /_}.rvm
  660. sudo chown -R \"$USER:\" /${USER// /_}.rvm
  661. echo \"export rvm_path=/${USER// /_}.rvm\" >> \"$HOME/.rvmrc\"
  662. and start installing again.
  663. "
  664. exit 2
  665. ;;
  666. (/usr/share/ruby-rvm)
  667. printf "%b" "
  668. It looks you are one of the happy Ubuntu users,
  669. RVM packaged by Ubuntu is old and broken,
  670. follow this link for details how to fix:
  671. https://stackoverflow.com/a/9056395/497756
  672. "
  673. [[ "${rvm_uses_broken_ubuntu_path:-no}" == "yes" ]] || exit 3
  674. ;;
  675. esac
  676. if [[ "$rvm_path" != "/"* ]]
  677. then fail "The rvm install path must be fully qualified. Tried $rvm_path"
  678. fi
  679. }
  680. rvm_install_validate_volume_mount_mode()
  681. {
  682. \typeset path partition test_exec
  683. path=$rvm_path
  684. # Directory $rvm_path might not exists at this point so we need to traverse the tree upwards
  685. while [[ -n "$path" ]]
  686. do
  687. if [[ -d $path ]]
  688. then
  689. partition=`df -P $path | awk 'END{print $1}'`
  690. test_exec=$(mktemp $path/rvm-exec-test.XXXXXX)
  691. echo '#!/bin/sh' > "$test_exec"
  692. chmod +x "$test_exec"
  693. if ! "$test_exec"
  694. then
  695. rm -f "$test_exec"
  696. printf "%b" "
  697. It looks that scripts located in ${path}, which would be RVM destination ${rvm_path},
  698. are not executable. One of the reasons might be that partition ${partition} holding this location
  699. is mounted in *noexec* mode, which prevents RVM from working correctly. Please verify your setup
  700. and re-mount partition ${partition} without the noexec option."
  701. exit 2
  702. fi
  703. rm -f "$test_exec"
  704. break
  705. fi
  706. path=${path%/*}
  707. done
  708. }
  709. rvm_install_select_and_get_version()
  710. {
  711. typeset dir _version_release _version
  712. for dir in "$rvm_src_path" "$rvm_archives_path"
  713. do
  714. [[ -d "$dir" ]] || mkdir -p "$dir"
  715. done
  716. _version_release="${version}"
  717. case "${version}" in
  718. (head)
  719. _version_release="${branch}"
  720. install_head sources[@] ${branch:-master}
  721. ;;
  722. (latest)
  723. _version=$(fetch_version sources[@])
  724. install_release sources[@] "$_version"
  725. ;;
  726. (latest-minor)
  727. version="$(<"$rvm_path/VERSION")"
  728. _version=$(fetch_version sources[@] ${version%.*})
  729. install_release sources[@] "$_version"
  730. ;;
  731. (latest-*)
  732. _version=$(fetch_version sources[@] ${version#latest-})
  733. install_release sources[@] "$_version"
  734. ;;
  735. (+([[:digit:]]).+([[:digit:]]).+([[:digit:]])) # x.y.z
  736. install_release sources[@] ${version}
  737. ;;
  738. (*)
  739. fail "Something went wrong, unrecognized version '$version'"
  740. ;;
  741. esac
  742. echo "${_version_release}" > "$rvm_path/RELEASE"
  743. }
  744. rvm_install_main()
  745. {
  746. [[ -f ./scripts/install ]] ||
  747. {
  748. log "'./scripts/install' can not be found for installation, something went wrong, it usually means your 'tar' is broken, please report it here: https://github.com/rvm/rvm/issues"
  749. return 127
  750. }
  751. # required flag - path to install
  752. flags+=( --path "$rvm_path" )
  753. \command bash "${flags[@]}"
  754. }
  755. rvm_install_ruby_and_gems()
  756. (
  757. if
  758. (( ${#install_rubies[@]} > 0 ))
  759. then
  760. source ${rvm_scripts_path:-${rvm_path}/scripts}/rvm
  761. source ${rvm_scripts_path:-${rvm_path}/scripts}/functions/version
  762. __rvm_print_headline
  763. for _ruby in ${install_rubies[@]}
  764. do command rvm "${forwarded_flags[@]}" install ${_ruby}
  765. done
  766. # set the first one as default, skip rest
  767. for _ruby in ${install_rubies[@]}
  768. do
  769. rvm "${forwarded_flags[@]}" alias create default ${_ruby}
  770. break
  771. done
  772. for _gem in ${install_gems[@]}
  773. do rvm "${forwarded_flags[@]}" all do gem install ${_gem}
  774. done
  775. printf "%b" "
  776. * To start using RVM you need to run \`source $rvm_path/scripts/rvm\`
  777. in all your open shell windows, in rare cases you need to reopen all shell windows.
  778. "
  779. if
  780. [[ "${install_gems[*]}" == *"rails"* ]]
  781. then
  782. printf "%b" "
  783. * To start using rails you need to run \`rails new <project_dir>\`.
  784. "
  785. fi
  786. fi
  787. )
  788. rvm_install()
  789. {
  790. rvm_install_initialize
  791. rvm_install_commands_setup
  792. rvm_install_default_settings
  793. rvm_install_parse_params "$@"
  794. rvm_install_validate_rvm_path
  795. rvm_install_validate_volume_mount_mode
  796. rvm_install_select_and_get_version
  797. rvm_install_main
  798. rvm_install_ruby_and_gems
  799. }
  800. rvm_install "$@"