Loading

rvm-installer

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