#!/usr/bin/env bash # __rvm_select implementation version patch_level __rvm_select() { if [[ -z "$rvm_ruby_string" ]] ; then rvm_ruby_string="${rvm_ruby_interpreter}" if [[ ! -z "$rvm_ruby_version" ]] ; then rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_version" ; fi if [[ ! -z "$rvm_ruby_patch_level" ]] ; then rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_patch_level" ; fi if [[ ! -z "$rvm_ruby_revision" ]] ; then rvm_ruby_string="$rvm_ruby_string-$rvm_ruby_revision" ; fi fi __rvm_ruby_string rvm_archive_extension="tar.gz" case "$rvm_ruby_interpreter" in macruby) if [[ "Darwin" = "$(uname)" ]] ; then rvm_ruby_package_name=${rvm_ruby_interpreter}-${rvm_ruby_version} if [[ "$rvm_head_flag" -eq 1 ]] ; then unset rvm_ruby_version rvm_ruby_tag rvm_ruby_revision="head" __rvm_db "macruby_repo_url" "rvm_ruby_repo_url" rvm_url="$rvm_ruby_repo_url" rvm_ruby_string="${rvm_ruby_interpreter}-head" elif [[ "nightly" = "$rvm_ruby_version" ]] ; then __rvm_db "macruby_nightly_url" "rvm_url" rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}" rvm_ruby_package_name="${rvm_ruby_interpreter}_nightly-${rvm_ruby_version}" rvm_ruby_package_file="$rvm_ruby_package_name" else __rvm_db "macruby_version" "rvm_ruby_version" __rvm_db "macruby_url" "rvm_url" rvm_ruby_package_name="MacRuby%200.5.zip" rvm_ruby_package_file="$rvm_ruby_package_name" rvm_url="$rvm_url/$rvm_ruby_package_name" fi unset rvm_ruby_patch_level else $rvm_scripts_path/log "fail" "MacRuby can only be installed on a Darwin OS." fi ;; rbx|rubinius) rvm_ruby_interpreter="rbx" rvm_ruby_version=${rvm_ruby_version:-$(__rvm_db "rbx_version")} rvm_ruby_repo_url=${rvm_rbx_repo_url:-$(__rvm_db "rubinius_repo_url")} __rvm_db "rbx_url" "rvm_url" if [[ -z "$rvm_head_flag" ]] ; then rvm_ruby_patch_level=${rvm_ruby_patch_level:-$(__rvm_db "rbx_patch_level")} rvm_ruby_string="$rvm_ruby_interpreter-$rvm_ruby_version-p$rvm_ruby_patch_level" rvm_ruby_string="${rvm_ruby_string/-prc/-rc}" rvm_ruby_string="$(echo $rvm_ruby_string | sed 's#-pp#-p#')" rvm_ruby_file="rubinius-$rvm_ruby_version-$rvm_ruby_patch_level" else unset rvm_ruby_patch_level unset rvm_ruby_version rvm_ruby_string="$rvm_ruby_interpreter-head" fi ;; jruby) unset rvm_ruby_patch_level if [[ ! -z "$rvm_head_flag" ]] ; then rvm_ruby_version="head" rvm_ruby_string="jruby-head" rvm_ruby_repo_url="${rvm_ruby_repo_url:-$(__rvm_db "jruby_repo_url")}" rvm_url="${rvm_ruby_repo_url:-$(__rvm_db "jruby_repo_url")}" else rvm_archive_extension="zip" rvm_ruby_version="${rvm_ruby_version:-"$(__rvm_db "jruby_version")"}" rvm_ruby_package_file="${rvm_ruby_interpreter}-bin-${rvm_ruby_version}" rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}" rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}" rvm_url="http://jruby.kenai.com/downloads/${rvm_ruby_version}/${rvm_ruby_package_file}.tar.gz" fi alias jruby_ng="jruby --ng" alias jruby_ng_server="jruby --ng-server" ;; maglev) unset rvm_ruby_patch_level maglev_url="$(__rvm_db "maglev_url")" if [[ ! -z "$rvm_head_flag" ]] ; then rvm_ruby_version="head" rvm_ruby_string="maglev-head" rvm_ruby_repo_url="${rvm_ruby_repo_url:-$(__rvm_db "maglev_repo_url")}" rvm_url="${rvm_ruby_repo_url:-$(__rvm_db "maglev_repo_url")}" else system="$(uname -s)" arch="$(uname -m)" rvm_ruby_package_file="MagLev-${rvm_ruby_version}.${system}-${arch}" rvm_gemstone_package_file="GemStone-${rvm_ruby_version}.${system}-${arch}" rvm_ruby_version="${rvm_ruby_version:-"$(__rvm_db "maglev_version")"}" rvm_ruby_package_name="${rvm_ruby_interpreter}-${rvm_ruby_version}" rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}" rvm_url="${rvm_ruby_url:-"$maglev_url/${rvm_ruby_package_file}.${rvm_archive_extension}"}" rvm_gemstone_url="${rvm_gemstone_url:-"$maglev_url/${rvm_gemstone_package_file}.${rvm_archive_extension}"}" export MAGLEV_HOME="$rvm_rubies_path/$rvm_ruby_string" fi ;; ironruby) unset rvm_ruby_patch_level if [[ "$rvm_head_flag" -eq 1 ]] ; then rvm_ruby_version="head" rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}" rvm_ruby_package_name="${rvm_ruby_string}" rvm_ruby_repo_url="${rvm_ruby_repo_url:-$(__rvm_db "ironruby_repo_url")}" rvm_url="${rvm_ruby_repo_url:-$(__rvm_db "ironruby_repo_url")}" else rvm_ruby_version=${rvm_ruby_version:-"$(__rvm_db "ironruby_version")"} rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}" rvm_ruby_package_file="${rvm_ruby_string}.zip" rvm_ruby_package_name="${rvm_ruby_string}" rvm_url="$(__rvm_db "ironruby_url")${rvm_ruby_package_file}" fi ;; ree) rvm_ruby_interpreter=ree rvm_ruby_version=${rvm_ruby_version:-"$(__rvm_db "ree_version")"} if [[ ! -z "$rvm_ruby_patch_level" ]] ; then rvm_ruby_patch_level="$(echo $rvm_ruby_patch_level | sed 's#^p##')" rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}-${rvm_ruby_patch_level}" elif [[ "$rvm_head_flag" = 1 ]] ; then rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}-head" fi if [[ "$rvm_ruby_version" != "head" ]] ; then if [[ ! -z "$rvm_ruby_revision" ]] ; then unset rvm_ruby_patch_level rvm_ruby_package_file rvm_ruby_package_name="ree-$rvm_ruby_version-$rvm_ruby_revision" else rvm_ruby_package_file="ruby-enterprise-$rvm_ruby_version-$rvm_ruby_patch_level" rvm_url="$(__rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_version}_url")/$rvm_ruby_package_file.tar.gz" fi fi if ! $rvm_scripts_path/match "$rvm_ruby_version" "^1\.8" ; then $rvm_scripts_path/log "fail" "Unknown Ruby Enterprise Edition version: $rvm_ruby_version" fi ;; mput|shyouhei) rvm_ruby_interpreter="mput" rvm_ruby_version="head" rvm_ruby_string="mput-head" unset rvm_ruby_patch_level rvm_ruby_repo_url=${rvm_mput_repo_url:-"$(__rvm_db "shyouhei_repo_url")"} rvm_url=$rvm_ruby_repo_url unset rvm_ruby_configure rvm_ruby_make rvm_ruby_make_install ;; ruby) if [[ -z "$rvm_ruby_version" ]] && [[ -z "$rvm_head_flag" ]]; then $rvm_scripts_path/log "fail" "Unknown ruby version: $rvm_ruby_version" else rvm_ruby_repo_url="${rvm_ruby_repo_url:-"$(__rvm_db "ruby_repo_url")"}" fi ;; current) ruby_binary="$(which binary 2>/dev/null)" if $rvm_scripts_path/match "$ruby_binary" "rvm" ; then rvm_ruby_string="$(dirname "$ruby_binary" | xargs dirname | xargs basename)" else rvm_ruby_interpreter="system" fi ;; default|system|user) #no-op? ;; *) if [[ ! -z "$MY_RUBY_HOME" ]] ; then rvm_ruby_string=$(basename $MY_RUBY_HOME) __rvm_select else if [[ -z "$rvm_ruby_string" ]] ; then $rvm_scripts_path/log "fail" "Ruby implementation '$rvm_ruby_interpreter' is not known." return 1 fi fi esac __rvm_gems_select if [[ ! -z "$rvm_ruby_interpreter" ]] && [[ "system" != "$rvm_ruby_interpreter" ]] && [[ "default" != "$rvm_ruby_interpreter" ]] ; then if [[ ! -z "$rvm_ruby_version" ]] ; then rvm_major_version=$(echo $rvm_ruby_version | awk -F'.' '{ print $2 }') rvm_minor_version=$(echo $rvm_ruby_version | awk -F'.' '{ print $3 }') fi rvm_ruby_package_name="$rvm_ruby_string" rvm_ruby_home="$rvm_rubies_path/$rvm_ruby_string" rvm_ruby_log_path="$rvm_log_path/$rvm_ruby_string" rvm_ruby_src_path="$rvm_src_path/$rvm_ruby_string" rvm_ruby_binary="$rvm_ruby_home/bin/ruby" rvm_ruby_irbrc="$rvm_ruby_home/.irbrc" rvm_ruby_gem_home="${rvm_gems_path}/${rvm_ruby_string}" if [[ "maglev" = "$rvm_ruby_interpreter" ]] ; then export MAGLEV_HOME="$rvm_ruby_home" export GEMSTONE_GLOBAL_DIR=$MAGLEV_HOME fi if [[ ! -z "$rvm_gem_set_name" ]] ; then rvm_ruby_gem_home="${rvm_ruby_gem_home}%${rvm_gem_set_name}" fi rvm_ruby_selected_flag=1 mkdir -p $rvm_ruby_log_path export rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_url rvm_ruby_patch_level rvm_ruby_configure rvm_ruby_configure_flags rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_major_version rvm_minor_version rvm_gem_set_name rvm_gems_path rvm_ruby_gem_home rvm_path rvm_src_path rvm_bin_path rvm_ruby_binary rvm_ruby_home rvm_log_path rvm_ruby_log_path rvm_src_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string else rvm_ruby_interpreter="${rvm_ruby_interpreter:-system}" fi } __rvm_use() { if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select $* ; fi if [[ -z "$rvm_ruby_interpreter" ]] ; then rvm_ruby_interpreter="default" ; fi if [[ "default" = "$rvm_ruby_interpreter" ]] ; then new_path="$(echo $PATH | tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)" new_path="$rvm_bin_path:$new_path" if [[ -s $rvm_config_path/default ]] ; then unset new_path source $rvm_config_path/default if [[ ! -z "$rvm_verbose_flag" ]] ; then $rvm_scripts_path/log "info" "Now using default ruby." fi else rvm_ruby_interpreter="system" $rvm_scripts_path/log "warn" "no default rvm specified, defaulting to pre-rvm system." unset GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME RUBY_VERSION IRBRC if [[ -s $rvm_config_path/system ]] ; then source $rvm_config_path/system ; fi fi elif [[ "system" = "$rvm_ruby_interpreter" ]] ; then unset GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME RUBY_VERSION IRBRC new_path="$(echo $PATH | tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)" new_path="$rvm_bin_path:$new_path" if [[ -s $rvm_config_path/system ]] ; then grep "MY_RUBY_HOME='$rvm_rubies_path" "$rvm_config_path/system" > /dev/null if [[ $? -eq 0 ]] ; then rm -f $rvm_config_path/system # 'system' should *not* point to an rvm ruby. else source $rvm_config_path/system fi fi if [[ "root" = "$(whoami)" ]] ; then for binary in erb gem irb rake rdoc ri ruby testrb ; do rm -f $rvm_symlink_path/$binary done fi if [[ ! -z "$rvm_verbose_flag" ]] ; then $rvm_scripts_path/log "info" "Now using system ruby." fi export rvm_ruby_string="system" else GEM_HOME="$rvm_ruby_gem_home" GEM_PATH="$rvm_ruby_gem_path" BUNDLE_PATH="$rvm_ruby_gem_home" MY_RUBY_HOME="$rvm_ruby_home" RUBY_VERSION="$rvm_ruby_string" IRBRC="$rvm_ruby_irbrc" export GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME RUBY_VERSION IRBRC if [[ -z "$IRBRC" ]] ; then unset IRBRC ; fi if [[ ! -d $MY_RUBY_HOME ]] ; then $rvm_scripts_path/log "warn" "$rvm_ruby_interpreter $rvm_ruby_string is not installed." if [[ ! -z "$rvm_install_on_use_flag" ]] ; then $rvm_scripts_path/manage "install" "$rvm_ruby_string" else $rvm_scripts_path/log "info" "To install do: 'rvm install $rvm_ruby_string'" return 1 fi fi if [[ ! -z "$rvm_verbose_flag" ]] ; then $rvm_scripts_path/log "info" "Now using $(echo $rvm_ruby_string | tr '-' ' ')" fi new_path="$(echo $PATH | tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)" new_path="$MY_RUBY_HOME/bin:$GEM_HOME/bin:$rvm_ruby_global_gems_path/bin:$rvm_bin_path:$new_path" fi if [[ ! -z "$rvm_default_flag" ]] && [[ "default" != "$rvm_ruby_interpreter" ]] ; then if [[ "root" = "$(whoami)" ]] ; then for binary in erb gem irb rake rdoc ri ruby testrb ; do rm -f $rvm_symlink_path/$binary ln -nfs $rvm_ruby_home/bin/$binary $rvm_symlink_path/$binary rm -f $rvm_symlink_path/passenger_ruby ln -nfs $rvm_bin_path/$rvm_ruby_string $rvm_symlink_path/passenger_ruby done fi if [[ "system" = "$rvm_ruby_interpreter" ]] ; then rm -f $rvm_config_path/default rm -f $rvm_bin_path/default* else RUBY_VERSION="$($rvm_ruby_home/bin/ruby -v | sed 's#^\(.*\) (.*$#\1#')" export GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME RUBY_VERSION echo "export PATH=\"$rvm_ruby_home/bin:$rvm_ruby_gem_home/bin:$rvm_ruby_global_gems_path/bin:$rvm_bin_path:\$PATH\"" > $rvm_config_path/default for variable in RUBY_VERSION GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME IRBRC rvm_ruby_string rvm_gem_set_name MAGLEV_HOME ; do eval "export $variable" eval value=\$${variable} if [[ ! -z "$value" ]] ; then echo "export ${variable}='$value'" >> $rvm_config_path/default else echo "unset ${variable}" >> $rvm_config_path/default fi done ; unset variable value if [[ ! -z "$rvm_default_flag" ]] ; then $rvm_scripts_path/symlink "default" ; fi fi fi unset rvm_default_flag if [[ ! -z "$rvm_symlink_name" ]] ; then $rvm_scripts_path/symlink "$rvm_symlink_name" ; unset rvm_symlink_name ; fi if [[ ! -z "$rvm_editor_flag" ]] ; then $rvm_scripts_path/symlink "editor" ; unset rvm_editor_flag ; fi if [[ ! -z "$rvm_passenger_flag" ]] ; then $rvm_scripts_path/symlink "passenger" ; unset rvm_passenger_flag ; fi if [[ ! -z "$rvm_rvmrc_flag" ]] ; then __rvm_set_rvmrc ; fi # Export ruby string and gem set name for extrnal scripts to take advantage of them. if [[ ! -z "$rvm_ruby_string" ]] ; then export rvm_ruby_string ; fi if [[ ! -z "$rvm_gem_set_name" ]] ; then export rvm_gem_set_name ; fi if [[ ! -z "$new_path" ]] ; then export PATH="$new_path" ; unset new_path ; fi if [[ "maglev" = "$rvm_ruby_interpreter" ]] ; then export MAGLEV_HOME="$rvm_ruby_home" export GEMSTONE_GLOBAL_DIR=$MAGLEV_HOME if [[ -x "$MAGLEV_HOME/gemstone/bin/gslist" ]] ; then $MAGLEV_HOME/gemstone/bin/gslist -clv > /dev/null 2>&1 ; result=$? if [[ $result -eq 1 ]] ; then $rvm_ruby_home/bin/maglev start ; fi fi fi $rvm_scripts_path/hook "after_use" } __rvm_ruby_string() { # rvm_ruby_string may designate any of the following items: # * rvm_gem_set_name # * rvm_ruby_interpreter # * rvm_ruby_version # * rvm_ruby_patch_level # * rvm_ruby_revision # * rvm_ruby_tag # * rvm_ruby_patch set_name=$(echo "$rvm_ruby_string" | awk -F'%' '{print $2}') if [[ ! -z "$set_name" ]] ; then rvm_gem_set_name="$set_name" ; fi ruby_string=$(echo "$rvm_ruby_string" | awk -F'%' '{print $1}') __rvm_unset_ruby_variables for string in $(echo $ruby_string | tr '-' ' ') ; do if [[ "head" = "$string" ]] ; then rvm_ruby_revision="head" unset rvm_ruby_patch_level rvm_ruby_revision rvm_ruby_tag export rvm_head_flag=1 elif [[ "default" = "$string" ]] ; then rvm_ruby_interpreter="default" unset rvm_ruby_patch_level rvm_ruby_tag rvm_head_flag rvm_ruby_revision rvm_ruby_version rvm_gem_set_name return elif [[ "system" = "$string" ]] ; then rvm_ruby_interpreter="system" unset rvm_ruby_patch_level rvm_ruby_tag rvm_head_flag rvm_ruby_revision rvm_ruby_version rvm_gem_set_name return elif [[ "nightly" = "$string" ]] ; then rvm_ruby_version="nightly" rvm_nightly_flag=1 break elif $rvm_scripts_path/match "$string" "^preview" ; then rvm_ruby_patch_level="$string" elif $rvm_scripts_path/match "$string" "^rc[0-9]" ; then rvm_ruby_patch_level="$string" elif $rvm_scripts_path/match "$string" "^[0-9]\.[0-9]" ; then rvm_ruby_version="$string" unset rvm_ruby_revision rvm_ruby_tag elif $rvm_scripts_path/match "$string" "^p[0-9]" ; then rvm_ruby_patch_level="$string" elif $rvm_scripts_path/match "$string" "^[0-9][0-9]" ; then if [[ "ree" = "$rvm_ruby_interpreter" ]] ; then rvm_ruby_patch_level="$string" unset rvm_ruby_revision elif [[ "maglev" = "$rvm_ruby_interpreter" ]] ; then rvm_ruby_version="$string" unset rvm_ruby_revision rvm_ruby_patch_level else rvm_ruby_revision="r$string" fi elif $rvm_scripts_path/match "$string" "^r[0-9]" ; then unset rvm_ruby_patch_level rvm_ruby_revision="$string" elif $rvm_scripts_path/match "$string" "^s[0-9]" ; then unset rvm_ruby_revision rvm_ruby_sha="$string" elif $rvm_scripts_path/match "$string" "^t[v0-9]" ; then unset rvm_ruby_patch_level rvm_ruby_revision rvm_ruby_tag="$string" elif $rvm_scripts_path/match "$string" "^m[0-9]" ; then rvm_ruby_mode="$string" elif $rvm_scripts_path/match "$string" "^h[a-z0-9]" ; then unset rvm_ruby_patch_level rvm_ruby_revision rvm_ruby_tag rvm_ruby_patch="$string" elif $rvm_scripts_path/match "$string" "^u[a-z0-9]" ; then unset rvm_ruby_patch_level rvm_ruby_revision rvm_ruby_tag rvm_ruby_patch rvm_ruby_user_tag="$string" elif $rvm_scripts_path/match "$string" "^b[0-9][0-9]" ; then rvm_ruby_bits="$string" elif $rvm_scripts_path/match "ruby rbx jruby macruby ree rubinius maglev mput shyouhei ironruby " "$string " ; then # NOTE: The space at the end of each of the above strings is *very* important. rvm_ruby_interpreter="$string" else $rvm_scripts_path/log "error" "Unknown ruby string component: '$string'" return 1 fi done # Unspecified interpreter if [[ -z "$rvm_ruby_interpreter" ]] ; then if $rvm_scripts_path/match "$rvm_ruby_version" "^1\.[8-9]" ; then rvm_ruby_interpreter="ruby" elif $rvm_scripts_path/match "$rvm_ruby_version" "^0.5" ; then rvm_ruby_interpreter="macruby" elif $rvm_scripts_path/match "$rvm_ruby_version" "^1.[2-4]" ; then rvm_ruby_interpreter="jruby" fi fi # Unspecified version if [[ -z "$rvm_ruby_version" ]] && [[ -z "$rvm_head_flag" ]]; then rvm_ruby_version=${rvm_ruby_version:-"$(__rvm_db "${rvm_ruby_interpreter}_version")"} fi if [[ -z "$rvm_ruby_version" ]] ; then rvm_ruby_string="${rvm_ruby_interpreter}" else rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}" fi # Head if [[ "$rvm_head_flag" -eq 1 ]] ; then rvm_ruby_string="${rvm_ruby_string}-head" elif [[ ! -z "$rvm_ruby_revision" ]] ; then rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_revision}" elif [[ ! -z "$rvm_ruby_tag" ]] ; then rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_tag}" elif [[ ! -z "$rvm_ruby_patch_level" ]] ; then rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_patch_level}" elif [[ ! -z "$rvm_ruby_user_tag" ]] ; then rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_user_tag}" else patch_level="$(__rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_version}_patch_level")" if [[ ! -z "$patch_level" ]] ; then rvm_ruby_patch_level="p${patch_level}" ; fi if [[ ! -z "$rvm_ruby_patch_level" ]] ; then rvm_ruby_patch_level="$(echo $rvm_ruby_patch_level | sed 's#^pp#p#')" rvm_ruby_string="${rvm_ruby_string}-${rvm_ruby_patch_level}" rvm_ruby_string="$(echo $rvm_ruby_string | sed 's#-pp#-p#')" fi fi }