#!/bin/bash # __rvm_select implementation version patch_level function __rvm_select { __rvm_ruby_string rvm_ruby_interpreter="${1:-$rvm_ruby_interpreter}" rvm_ruby_interpreter="${rvm_ruby_interpreter:-ruby}" # Default is standard ruby temp=$(echo $rvm_ruby_interpreter | awk '{print substr($1, 0, 1)}') if [ ! -z "$(echo $temp | grep '[0-9]')" ] ; then rvm_ruby_version=$rvm_ruby_interpreter rvm_ruby_interpreter="ruby" fi ; unset temp if [ "$rvm_ruby_version" = "1.8" ] ; then rvm_ruby_version="1.8.6" ; fi if [ "$rvm_ruby_version" = "1.9" ] ; then rvm_ruby_version="1.9.1" ; fi case "$rvm_ruby_interpreter" in macruby) if [ "`uname`" = "Darwin" ] ; then rvm_ruby_repo_url="${rvm_ruby_repo_url:-`__rvm_db "macruby_repo_url"`}" rvm_ruby_version="${rvm_ruby_version:-`__rvm_db "macruby_version"`}" rvm_ruby_package_name=${rvm_ruby_interpreter}_nightly-${rvm_ruby_version} rvm_url="http://dl.getdropbox.com/u/163257/$rvm_ruby_package_name.pkg" # For now we are only supporting the 'nightly' builds unset rvm_ruby_patch_level else __rvm_log "fail" "MacRuby can only be installed on a Darwin OS." fi ;; rbx|rubinius) rvm_ruby_version="head" unset rvm_ruby_patch_level rvm_ruby_interpreter="rubinius" rvm_ruby_repo_url=`__rvm_db "rubinius_repo_url"` rvm_ruby_configure="" rvm_ruby_make="build" rvm_ruby_make_install="" #rvm_ruby_rev="head" ;; jruby) rvm_ruby_version="${rvm_ruby_version:-`__rvm_db "jruby_version"`}" unset rvm_ruby_patch_level if [ "$rvm_ruby_version" != "1.2.0" -a "$rvm_ruby_version" != "1.3.1" ] ; then __rvm_log "fail" "Unknown jRuby version: $rvm_ruby_version" fi alias jruby_ng="jruby --ng" alias jruby_ng_server="jruby --ng-server" ;; ruby-enterprise|ree) rvm_ruby_interpreter=`__rvm_db "ree_interpreter"` rvm_ruby_version=${rvm_ruby_version:-`__rvm_db "ree_version"`} rvm_ruby_patch_level="${3:-`__rvm_db "ree_patch_level"`}" if [ "$rvm_ruby_version" != "1.8.6" ] ; then __rvm_log "fail" "Unknown Ruby Enterprise Edition version: $rvm_ruby_version" fi ;; ruby) if [ ! -z "$rvm_ruby_tag" ] ; then rvm_ruby_version=$(echo $rvm_ruby_tag | sed 's/^v//' | sed 's/\///' | awk -F'_' '{print 1 "." $2 "." $3 }') rvm_ruby_patch_level=$rvm_ruby_tag # $(echo $rvm_ruby_tag | sed 's/^v//' | sed 's/\///' | awk -F'_' '{print $4 }') fi rvm_ruby_version=${rvm_ruby_version:-`__rvm_db "ruby_version"`} # Default verison is 1.8.6 rvm_ruby_patch_level=${rvm_ruby_patch_level:-`__rvm_db "ruby_${rvm_ruby_version}_patch_level"`} # Default verison is 1.8.6 if [ -z "rvm_ruby_patch_level" ] ; then unset rvm_ruby_patch_level ; fi if [ -z "rvm_ruby_version" ] ; then __rvm_log "fail" "Unknown ruby version: $rvm_ruby_version" fi ;; default|system|current|user) #no-op? ;; *) __rvm_log "fail" "Ruby implementation '$rvm_ruby_interpreter' is not known." esac if [ ! -z "$rvm_ruby_rev" ] ; then if [ "$rvm_ruby_rev" = "head" -o "$rvm_ruby_rev" = "trunk" ] ; then rvm_ruby_patch_level="head" else rvm_ruby_patch_level="$rvm_ruby_rev" fi fi if [ ! -z "$rvm_ruby_interpreter" -a ! -z "$rvm_ruby_version" -a "$rvm_ruby_interpreter" != "system" ] ; then rvm_major_version=$(echo $rvm_ruby_version | awk -F'.' '{ print $2 }') rvm_minor_version=$(echo $rvm_ruby_version | awk -F'.' '{ print $3 }') if [ -z "$rvm_gem_set_name" ] ; then rvm_gem_home="$rvm_gem_path/$rvm_ruby_interpreter/$rvm_ruby_version" else if [ ! -z "$rvm_gem_set_name_rm" -a -d $rvm_gem_path/$rvm_ruby_interpreter/$rvm_ruby_version-$rvm_gem_set_name ] ; then rm -rf $rvm_gem_path/$rvm_ruby_interpreter/$rvm_ruby_version-$rvm_gem_set_name/ if [ "$rvm_gem_set_name_rm" = "$rvm_gem_set_name" ] ; then unset rvm_gem_set_name ; fi else rvm_gem_home="$rvm_gem_path/$rvm_ruby_interpreter/$rvm_ruby_version-$rvm_gem_set_name" fi fi if [ ! -z "$rvm_load" ] ; then __rvm_gemset_load ; fi if [ ! -z "$rvm_dump" ] ; then __rvm_gemset_dump ; fi mkdir -p $rvm_gem_home if [ -z "$rvm_ruby_patch_level" ] ; then rvm_ruby_package_name="${rvm_ruby_package_name:-"$rvm_ruby_interpreter-$rvm_ruby_version"}" rvm_ruby_home="${rvm_ruby_home:-"$rvm_path/$rvm_ruby_interpreter-$rvm_ruby_version"}" else if [ "`echo $rvm_ruby_patch_level | awk '{print substr($1, 0, 1)}'`" != "p" ] ; then rvm_ruby_patch_level="p$rvm_ruby_patch_level" fi rvm_ruby_package_name="${rvm_ruby_package_name:-"$rvm_ruby_interpreter-$rvm_ruby_version-$rvm_ruby_patch_level"}" rvm_ruby_home="${rvm_ruby_home:-"$rvm_path/$rvm_ruby_interpreter-$rvm_ruby_version-$rvm_ruby_patch_level"}" fi rvm_ruby_log_path="$rvm_log_path/$rvm_ruby_package_name" rvm_ruby_src_path="$rvm_source_path/$rvm_ruby_package_name" rvm_ruby_binary="$rvm_ruby_home/bin/ruby" rvm_ruby_irbrc="$rvm_ruby_home/.irbrc" rvm_ruby_string="$rvm_ruby_package_name" rvm_selected=1 export rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_version rvm_ruby_package_name rvm_url rvm_ruby_patch_level rvm_ruby_configure rvm_ruby_make rvm_ruby_make_install rvm_ruby_rev rvm_ruby_tag rvm_major_version rvm_minor_version rvm_gem_set_name rvm_gem_path rvm_gem_home rvm_path rvm_source_path rvm_bin_path rvm_ruby_binary rvm_ruby_package_name rvm_ruby_home rvm_log_path rvm_ruby_log_path rvm_source_path rvm_ruby_src_path rvm_ruby_irbrc rvm_selected rvm_ruby_string else rvm_gem_home=$GEM_HOME fi } function __rvm_use { if [ -z "$rvm_selected" ] ; then __rvm_select $* ; fi if [ -z "$rvm_ruby_interpreter" ] ; then rvm_ruby_interpreter="default" ; fi if [ "$rvm_ruby_interpreter" = "default" ] ; then if [ -s $rvm_path/default ] ; then source $rvm_path/default else __rvm_log "error" "no default rvm specified, defaulting to pre-rvm sytem." unset GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION IRBRC PATH="$rvm_system_path" ; export PATH if [ -s $rvm_path/system ] ; then source $rvm_path/system ; fi fi elif [ "$rvm_ruby_interpreter" = "system" ] ; then unset GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION IRBRC PATH="$rvm_system_path" ; export PATH if [ -s $rvm_path/system ] ; then grep "^MY_RUBY_HOME='$rvm_path" "$rvm_path/system" > /dev/null if [ $? -eq 0 ] ; then rm -f $rvm_path/system # 'system' should *not* point to an rvm ruby. else source $rvm_path/system fi fi else GEM_HOME=$rvm_gem_home ; export GEM_HOME GEM_PATH=$rvm_gem_home ; export GEM_PATH MY_RUBY_HOME=$rvm_ruby_home ; export MY_RUBY_HOME RUBY_VERSION=$rvm_ruby_package_name ; export RUBY_VERSION IRBRC="$rvm_ruby_irbrc" ; export IRBRC if [ -z "$IRBRC" ] ; then unset IRBRC ; fi # Install if not installed if [ ! -d $MY_RUBY_HOME ] ; then __rvm_log "warn" "$rvm_ruby_interpreter $rvm_ruby_version is not installed." echo -n -e "Would you like rvm to install $rvm_ruby_interpreter $rvm_ruby_version for you now?\n(Y/n) ? " read response if [ "$response" = 'n' ] ; then __rvm_log "warn" "Please run 'rvm install $rvm_ruby_interpreter $rvm_ruby_version' if you wish to use it.\n" return 0 else __rvm_install-ruby $rvm_ruby_interpreter $rvm_ruby_version $rvm_ruby_patch_level fi fi __rvm_irbrc PATH="$MY_RUBY_HOME/bin:$GEM_HOME/bin:$rvm_path/bin:$rvm_system_path" ; export PATH if [ ! -z "$rvm_set_default" ] ; then RUBY_VERSION="$($MY_RUBY_HOME/bin/ruby -v | sed 's/^\(.*\) (.*$/\1/')" export GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION echo "PATH=$MY_RUBY_HOME/bin:$GEM_HOME/bin:$rvm_path/bin:\$PATH ; export PATH" > $rvm_path/default for variable in RUBY_VERSION GEM_HOME GEM_PATH MY_RUBY_HOME IRBRC ; do eval "export $variable" eval value=\$${variable} if [ ! -z "$variable" ] ; then echo "${variable}='$value' ; export ${variable}" >> $rvm_path/default else echo "unset ${variable}" >> $rvm_path/default fi done if [ -s $rvm_path/bin/$rvm_ruby_package_name ] ; then ln -fs $rvm_path/bin/$rvm_ruby_package_name $rvm_path/bin/ruby ln -fs $rvm_path/bin/$rvm_ruby_package_name $rvm_path/bin/default-ruby # So that people know what it's for :) ln -fs $rvm_path/bin/gem-$rvm_ruby_package_name $rvm_path/bin/gem ln -fs $rvm_path/bin/irb-$rvm_ruby_package_name $rvm_path/bin/irb else rm -f $rvm_path/bin/ruby rm -f $rvm_path/bin/default-ruby rm -f $rvm_path/bin/gem rm -f $rvm_path/bin/irb fi unset rvm_set_default fi fi }