scripts/utility in rvm-0.1.16 vs scripts/utility in rvm-0.1.18
- old
+ new
@@ -22,16 +22,27 @@
unset key value variable
}
# Ouput rvm environment information.
__rvm_info() {
- if [[ ! -z "$(/usr/bin/which ruby 2>/dev/null)" ]] ; then full_version=$(ruby -v) ; fi
+ if [[ ! -z "$rvm_ruby_args" ]] ; then
+ echo $(rvm_ruby_string="$rvm_ruby_args"; __rvm_select ; __rvm_use ; __rvm_environment_info)
+ echo -e $info ; unset info
+ else
+ __rvm_environment_info
+ fi
+
+}
+
+__rvm_environment_info() {
+ if [[ ! -z "$(/usr/bin/which ruby 2>/dev/null)" ]] ; then full_version=$(ruby -v) ; fi
echo -e "system:\n uname: \"$(uname -a)\""
-if [[ ! -z "$ZSH_VERSION" ]] ; then echo -e " shell: \"zsh\"\n version: \"$ZSH_VERSION\"" ; fi
-if [[ ! -z "$BASH_VERSION" ]] ; then echo -e " shell: \"bash\"\n version: \"$BASH_VERSION\"" ; fi
+ if [[ ! -z "$ZSH_VERSION" ]] ; then echo -e " shell: \"zsh\"\n version: \"$ZSH_VERSION\"" ; fi
+ if [[ ! -z "$BASH_VERSION" ]] ; then echo -e " shell: \"bash\"\n version: \"$BASH_VERSION\"" ; fi
+
cat <<Info
ruby:
interpreter: "$(echo $full_version | awk '{print $1}')"
version: "$(echo $full_version | awk '{print $2}')"
@@ -56,17 +67,19 @@
BUNDLE_PATH: "$BUNDLE_PATH"
MY_RUBY_HOME: "$MY_RUBY_HOME"
IRBRC: "$IRBRC"
Info
-if [[ ! -z "$MAGLEV_HOME" ]] ; then echo -e " MAGLEV_HOME: \"$MAGLEV_HOME\"" ; fi
+ if [[ ! -z "$MAGLEV_HOME" ]] ; then info="$info\n MAGLEV_HOME: \"$MAGLEV_HOME\"" ; fi
unset full_version
}
# Output debugging information that has been found useful to help people identify and resolve issues.
__rvm_debug() {
+ __rvm_version
+ __rvm_environment_info
$rvm_scripts_path/log "debug" "PATH:\n$(echo $PATH | awk -F":" '{print $1":"$2":"$3":"$4":"$5}')"
$rvm_scripts_path/log "debug" "uname -a: $(uname -a)"
$rvm_scripts_path/log "debug" "permissions: $(ls -la $rvm_path{,/rubies})"
if [[ "Darwin" = "$(uname)" ]] ; then
@@ -98,10 +111,26 @@
done
$rvm_scripts_path/log "debug" "gem sources:\n$(gem sources | awk '/gems/')"
}
+__rvm_strings() {
+ unset results
+ for rvm_ruby_string in $(echo $rvm_ruby_args) ; do
+ __rvm_ruby_string
+ if [[ $? -gt 0 ]] ; then
+ return 1
+ else
+ results="$results $(__rvm_select ; echo $rvm_ruby_string)"
+ unset rvm_ruby_string
+ fi
+ done
+ echo $results
+ unset results
+ return 0
+}
+
# ZSH has 1 based array indexing, bash has 0 based.
if [[ ! -z "$ZSH_VERSION" ]] ; then __shell_array_start=1 ; else __shell_array_start=0 ; fi
# Push an item onto a given array.
__rvm_push() {
@@ -144,17 +173,17 @@
if [[ $? -gt 0 ]] ; then $rvm_scripts_path/log "error" "Error running '$command', please check $rvm_ruby_log_path/$log_file_name*.log" ; __rvm_pushpop ; return 1 ; fi
unset log_file command
}
# Unset both rvm variables as well as ruby-specific variables
-# Preserve gemset if 'rvm_sticky_gems' is set (persist gemset unless clear is explicitely called).
+# Preserve gemset if 'rvm_sticky' is set (persist gemset unless clear is explicitely called).
__rvm_cleanup_variables() {
__rvm_unset_ruby_variables
- if [[ "$rvm_sticky_gems" = "1" ]] ; then export rvm_gem_set_name ; else unset rvm_gem_set_name ; fi
+ if [[ "$rvm_sticky_flag" = "1" ]] ; then export rvm_gem_set_name ; else unset rvm_gem_set_name ; fi
- unset rvm_action rvm_irbrc_file rvm_command rvm_error_message rvm_url rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_import_flag rvm_export_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag rvm_shebang_flag rvm_env_flag rvm_tail_flag rvm_use_flag rvm_dir_flag rvm_list_flag rvm_empty_flag rvm_file_name rvm_benchmark_flag rvm_clear_flag rvm_name_flag rvm_verbose_flag rvm_user_flag rvm_system_flag rvm_ruby_configure_flags rvm_uninstall_flag rvm_install_flag rvm_llvm_flag rvm_ruby_bits rvm_ruby_patch rvm_sticky_gems
+ unset rvm_action rvm_irbrc_file rvm_command rvm_error_message rvm_url rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_import_flag rvm_export_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag rvm_shebang_flag rvm_env_flag rvm_tail_flag rvm_use_flag rvm_dir_flag rvm_list_flag rvm_empty_flag rvm_file_name rvm_benchmark_flag rvm_clear_flag rvm_name_flag rvm_verbose_flag rvm_user_flag rvm_system_flag rvm_ruby_configure_flags rvm_uninstall_flag rvm_install_flag rvm_llvm_flag rvm_ruby_bits rvm_ruby_patch rvm_sticky_flag
}
# Unset ruby-specific variables
__rvm_unset_ruby_variables() {
unset rvm_ruby_interpreter rvm_ruby_version rvm_url rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_make rvm_ruby_make_install rvm_ruby_revision rvm_ruby_tag rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_ruby_binary rvm_ruby_home rvm_ruby_log_path rvm_ruby_src_path rvm_ruby_irbrc rvm_ruby_selected_flag rvm_ruby_string rvm_ruby_string rvm_ruby_src_path rvm_ruby_repo_url rvm_major_version rvm_minor_version rvm_ruby_gem_home rvm_head_flag rvm_ruby_configure rvm_ruby_mode rvm_ruby_package_file rvm_ruby_package_name rvm_ruby_gem_path
@@ -307,79 +336,110 @@
else
echo "$rvm_ruby_src_path"
fi
}
-# List all rvm installed rubies.
+# Query for valid rvm ruby strings
# This is meant to be used with scripting.
-__rvm_rubies() {
- \ls $rvm_rubies_path
+__rvm_list_strings() {
+ echo $(\ls $rvm_rubies_path)
}
# List all rvm installed rubies, default ruby and system ruby.
# Display the rubies, indicate their architecture and indicate which is currently used.
# This is not meant to be used with scripting. This is for interactive mode usage only.
__rvm_list() {
- echo
- if [[ ! -z "$rvm_all_flag" ]] ; then
- while read -r tag
- do
- prefix="$(echo ${tag/\//} | sed 's#^v1_##' | awk -F'_' '{print "(ruby-)1."$1"."$2}' | sed 's#p$##')"
- echo "${prefix}-t${tag/\//}"
- unset prefix tag
- done < <(svn list http://svn.ruby-lang.org/repos/ruby/tags/ | awk '/^v1_[8|9]/')
- echo -e "(ruby-)1.8.6(-p383)\n(ruby-)1.8.6-head\n(ruby-)1.8.7(-p248)\n(ruby-)1.8.7-head\n(ruby-)1.9.1(-p243)\n(ruby-)1.9.1(-p376)\n(ruby-)1.9.1-head\n(ruby-)1.9.2-preview1"
- echo -e "jruby-1.2.0\njruby-1.3.0\njruby-1.3.1\njruby(-1.4.0) # the default\njruby-head"
- echo -e "rbx(-prc1) # default\nrbx-head"
- echo -e "ree-1.8.6\nree(-1.8.7) # the default\nree-1.8.6-head\nree-1.8.7-head"
- echo -e "maglev(-22725)"
- echo -e "mput(-head) # shyouhei head, the default mput"
- echo -e "ironruby-0.9.3 # (1.0 RC1)\nironruby-head"
- if [[ "Darwin" = "$(uname)" ]] ; then
- echo -e "macruby(-nightly) # the default macruby\nmacruby-head # Build from the macruby git repository"
- fi
+ action="$(echo $rvm_ruby_args | awk '{print $1}')"
+ if [[ "known" = "$action" ]] ; then
+ __rvm_list_known
+ elif [[ "default" = "$action" ]] ; then
+ __rvm_list_default
+ elif [[ "rubies" = "$action" ]] ; then
+ __rvm_list_rubies
+ elif [[ "strings" = "$action" ]] ; then
+ __rvm_list_strings
else
- ruby=$(which ruby 2>/dev/null) ; current_ruby=""
- if [[ ! -z "$ruby" ]] && [[ ! -z "$(echo $ruby | awk '/rvm/')" ]] ; then
- current_ruby="$(echo $ruby | xargs dirname | xargs dirname | xargs basename 2> /dev/null)"
- fi
+ echo -e "Usage: rvm list {known,default,rubies,strings}"
+ fi
+}
- echo -e "rvm Rubies\n"
- for version in $(\ls $rvm_rubies_path/ 2> /dev/null | awk '/[a-z]*-.*/ {print $NF}') ; do
- if [[ ! -z "$(echo $version | awk '/^jruby-/')" ]] ; then
- string="[ $($rvm_rubies_path/$version/bin/ruby -v | awk '{print $NF}') ]"
- elif [[ ! -z "$(echo $version | awk '/^maglev-|^macruby-/')" ]] ; then
- string="[ x86_64 ]"
- else
- string="[ $(file $rvm_rubies_path/$version/bin/ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
- fi
- if [[ "$version" = "$current_ruby" ]] ; then echo -n "=> " ; else echo -n " " ; fi
- echo -e "$(tput setaf 2)$version$(tput sgr0) $string"
- done ; unset version
-
+__rvm_list_default() {
+ strings="$(echo $rvm_ruby_args | awk '{print $2}')"
+ if [[ "$strings" = "string" ]] ; then
+ echo $(grep 'MY_RUBY_HOME' $rvm_config_path/default | awk -F"'" '{print $2}' | xargs basename)
+ else
if [[ -f "$rvm_config_path/default" ]] && [[ -s $rvm_config_path/default ]] ; then
version=$(grep 'MY_RUBY_HOME' $rvm_config_path/default | awk -F"'" '{print $2}' | xargs basename)
if [[ ! -z "$version" ]] ; then
echo -e "\nDefault Ruby (for new shells)\n"
string="[ $(file $rvm_rubies_path/$version/bin/ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
- echo -e " $(tput setaf 2)$version$(tput sgr0) $string"
+ echo -e " $(tput setaf 2)$version$(tput sgr0) $string\n"
fi ; unset version
fi
+ fi
+}
- system_ruby="$(rvm system ; which ruby 2>/dev/null)"
- if [[ ! -z "$system_ruby" ]] && [[ -x "$system_ruby" ]]; then
- echo -e "\nSystem Ruby\n"
- system_version=$($system_ruby -v)
- string="[ $(file $system_ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
- if [[ ! -z "$system_ruby" ]] && [[ "$current_ruby" = "$system_version" ]] ; then echo -n "=> " ; else echo -n " " ; fi
- echo -e "$(tput setaf 2)system$(tput sgr0) $string"
+__rvm_list_known() {
+ while read -r tag
+ do
+ prefix="$(echo ${tag/\//} | sed 's#^v1_##' | awk -F'_' '{print "(ruby-)1."$1"."$2}' | sed 's#p$##')"
+ echo "${prefix}-t${tag/\//}"
+ unset prefix tag
+ done < <(svn list http://svn.ruby-lang.org/repos/ruby/tags/ | awk '/^v1_[8|9]/')
+ echo -e "(ruby-)1.8.6(-p383)\n(ruby-)1.8.6-head\n(ruby-)1.8.7(-p248)\n(ruby-)1.8.7-head\n(ruby-)1.9.1(-p243)\n(ruby-)1.9.1(-p376)\n(ruby-)1.9.1-head\n(ruby-)1.9.2-preview1"
+ echo -e "jruby-1.2.0\njruby-1.3.1\njruby(-1.4.0) # the default\njruby-head"
+ echo -e "rbx(-prc1) # default\nrbx-head"
+ echo -e "ree-1.8.6\nree(-1.8.7) # the default\nree-1.8.6-head\nree-1.8.7-head"
+ echo -e "maglev(-22891)\nmaglev-head"
+ echo -e "mput(-head) # shyouhei head, the default mput"
+ echo -e "ironruby-0.9.3 # (1.0 RC1)\nironruby-head"
+ if [[ "Darwin" = "$(uname)" ]] ; then
+ echo -e "macruby(-nightly) # the default macruby\nmacruby-head # Build from the macruby git repository"
+ fi
+}
+
+__rvm_list_rubies() {
+ echo
+ ruby=$(which ruby 2>/dev/null) ; current_ruby=""
+ if [[ ! -z "$ruby" ]] && [[ ! -z "$(echo $ruby | awk '/rvm/')" ]] ; then
+ current_ruby="$(echo $ruby | xargs dirname | xargs dirname | xargs basename 2> /dev/null)"
+ fi
+
+ echo -e "rvm Rubies\n"
+ for version in $(\ls $rvm_rubies_path/ 2> /dev/null | awk '/[a-z]*-.*/ {print $NF}') ; do
+ if [[ ! -z "$(echo $version | awk '/^jruby-/')" ]] ; then
+ string="[ $($rvm_rubies_path/$version/bin/ruby -v | awk '{print $NF}') ]"
+ elif [[ ! -z "$(echo $version | awk '/^maglev-|^macruby-/')" ]] ; then
+ string="[ x86_64 ]"
else
- $rvm_scripts_path/log "info" "No system ruby found."
+ string="[ $(file $rvm_rubies_path/$version/bin/ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
fi
+ if [[ "$version" = "$current_ruby" ]] ; then echo -n "=> " ; else echo -n " " ; fi
+ echo -e "$(tput setaf 2)$version$(tput sgr0) $string"
+ done ; unset version
- unset current_ruby version selected system_ruby system_version string
+ if [[ -f "$rvm_config_path/default" ]] && [[ -s $rvm_config_path/default ]] ; then
+ version=$(grep 'MY_RUBY_HOME' $rvm_config_path/default | awk -F"'" '{print $2}' | xargs basename)
+ if [[ ! -z "$version" ]] ; then
+ echo -e "\nDefault Ruby (for new shells)\n"
+ string="[ $(file $rvm_rubies_path/$version/bin/ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
+ echo -e " $(tput setaf 2)$version$(tput sgr0) $string"
+ fi ; unset version
fi
+
+ system_ruby="$(rvm system ; which ruby 2>/dev/null)"
+ if [[ ! -z "$system_ruby" ]] && [[ -x "$system_ruby" ]]; then
+ echo -e "\nSystem Ruby\n"
+ system_version=$($system_ruby -v)
+ string="[ $(file $system_ruby | awk '/x86.64/ {print "x86_64"} /386/ {print "i386"} /ppc/ {print "ppc"}' | tr "\n" ' ')]"
+ if [[ ! -z "$system_ruby" ]] && [[ "$current_ruby" = "$system_version" ]] ; then echo -n "=> " ; else echo -n " " ; fi
+ echo -e "$(tput setaf 2)system$(tput sgr0) $string"
+ else
+ $rvm_scripts_path/log "info" "No system ruby found."
+ fi
+
+ unset current_ruby version selected system_ruby system_version string
echo
}
# Initialize rvm, ensuring that the path and directories are as expected.
__rvm_initialize() {
@@ -413,36 +473,26 @@
# If --head was specified, update from git repository master branch.
__rvm_update_rvm() {
mkdir -p "$rvm_src_path"
__rvm_pushpop "$rvm_src_path"
- ruby="$(which ruby 2>/dev/null)"
- system_ruby="$(rvm system ; which ruby 2>/dev/null)"
- if [[ ! -x "$ruby" ]] ; then
- if [[ ! -x "$system" ]] ; then
- unset ruby
- else
- ruby=$system_ruby
- fi
- fi
-
if [[ "head" = "$rvm_ruby_revision" ]] || [[ -z "$system_ruby" ]] ; then
if [[ -d "$rvm_src_path/rvm/.git" ]] ; then
builtin cd $rvm_src_path/rvm/ && git pull origin master && ./scripts/install
else
builtin cd $rvm_src_path && git clone git://github.com/wayneeseguin/rvm.git && builtin cd rvm/ && ./install
fi
else
- if [[ "true" = "$($ruby -S gem list rvm --installed)" ]]; then
- $ruby -S gem update rvm $rvm_gem_options
- else
- $ruby -S gem install rvm $rvm_gem_options
- fi
- # TODO: Check all gem paths instead of simply assuming the last one...
- builtin cd "$($ruby -S gem env | grep "\- $HOME" | awk '{print $NF}' | head -n 1)/gems/rvm-$(gem list rvm | sed 's/.*(//' | sed 's/).*//' | awk -F',' '{print $1 ; exit}')" && ./install
+ stable_version=$(curl -s http://rvm.beginrescueend.com/releases/stable-version.txt)
+
+ __rvm_run "fetch" "$rvm_scripts_path/fetch 'http://rvm.beginrescueend.com/releases/rvm-${stable_version}.tar.gz'" "fetching rvm-${stable_version}.tar.gz"
+
+ __rvm_run "extract" "cat $rvm_archives_path/rvm-${stable_version}.tar.gz | gunzip | tar xf - -C $rvm_src_path" "Extracting $rvm_ruby_package_file ..."
+
+ __rvm_run "install" "builtin cd $rvm_src_path/rvm-${stable_version}/ ; ./install" "Installing rvm-${stable_version}..."
fi
- unset ruby system_ruby
+
__rvm_pushpop
$rvm_scripts_path/hook "after_update"
}
__rvm_reboot() {
@@ -728,18 +778,18 @@
}
# Select a gems(et) based on CLI set options and environment.
# This only sets 'rvm_ruby_gem_home'
__rvm_gems_select() {
- if ! which gem >/dev/null 2>&1 ; then return 0 ; fi
+ if ! which gem > /dev/null 2>&1 ; then return 0 ; fi
rvm_ruby_global_gems_path="$rvm_gems_path/$rvm_ruby_string%global"
if [[ -z "$rvm_gem_set_name" ]] ; then
# No longer defaulting to 'sticky' gem sets.
- # Set 'rvm_sticky_gems=1' in ~/.rvmrc to enable.
- if [[ ! -z "$rvm_sticky_gems" ]] ; then
+ # Set 'rvm_sticky_flag=1' in ~/.rvmrc to enable.
+ if [[ ! -z "$rvm_sticky_flag" ]] ; then
if [[ ! -z "$GEM_HOME" ]] ; then
rvm_gem_set_name=$(echo $GEM_HOME | xargs basename | awk -F'%' '{print $2}')
fi
if [[ ! -z "$rvm_ruby_gem_home" ]] ; then
rvm_gem_set_name=$(echo $rvm_ruby_gem_home | xargs basename | awk -F'%' '{print $2}')
@@ -747,11 +797,11 @@
fi
if [[ ! -z "$rvm_gem_set_name" ]] && ! $rvm_scripts_path/match "$rvm_gem_set_name" "^[0-9]\.[0-9]" ; then
rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string%$rvm_gem_set_name"
else
- if [[ ! -z "$rvm_ruby_interpreter" ]] && [[ ! -z "$rvm_ruby_version" ]] && [[ "$rvm_ruby_interpreter" != "system" ]] ; then
+ if [[ ! -z "$rvm_ruby_string" ]] && [[ "$rvm_ruby_interpreter" != "system" ]] ; then
rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string"
elif [[ -z "$GEM_HOME" ]] && [[ ! -z "$(which gem 2>/dev/null)" ]] ; then
rvm_ruby_gem_home=$(gem env gemdir)
elif [[ ! -z "$GEM_HOME" ]] ; then
rvm_ruby_gem_home="$GEM_HOME"
@@ -762,11 +812,15 @@
if [[ -z "$rvm_gem_set_name" ]] ; then unset rvm_gem_set_name ; fi
else
rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string%$rvm_gem_set_name"
fi
- if [[ ! -d "$rvm_ruby_gem_home" ]] ; then mkdir -p $rvm_ruby_gem_home ; fi
+ # If the gemset does not exist, then notify the user as such and abort the action.
+ if [[ ! -d "$rvm_ruby_gem_home" ]] && [[ ! -z "$rvm_gem_set_name" ]] && [[ -z "$rvm_create_flag" ]]; then
+ $rvm_scripts_path/log "error" "Gemset '$rvm_gem_set_name' does not exist, rvm gems create '$rvm_gem_set_name' first."
+ return 1
+ fi
rvm_ruby_gem_path="$rvm_ruby_gem_home:$rvm_ruby_global_gems_path"
# TODO: Remove next section after a several releases.
# Migrate original rvm global gem cache directory to $HOME/.gem/cache
@@ -810,11 +864,12 @@
__rvm_gems_use() {
if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select ; fi
if [[ ! -z "$rvm_ruby_gem_home" ]] ; then
if [[ ! -d "$rvm_ruby_gem_home" ]] ; then
- mkdir -p "$rvm_ruby_gem_home"
+ $rvm_scripts_path/log "error" "Gemset '$rvm_gem_set_name' does not exist, rvm gems create '$rvm_gem_set_name' first."
+ return 1
fi
if [[ "$rvm_interactive" = 1 ]] ; then
$rvm_scripts_path/log "info" "gems(et) : ${rvm_gem_set_name:-default}"
fi
@@ -822,9 +877,10 @@
export GEM_HOME="$rvm_ruby_gem_home"
export GEM_PATH="$rvm_ruby_gem_path"
export BUNDLE_PATH="$rvm_ruby_gem_home"
__rvm_use
fi
+ return 0
}
__rvm_mono_env() {
export DYLD_LIBRARY_PATH="$rvm_usr_path/lib:$DYLD_LIBRARY_PATH"
export C_INCLUDE_PATH="$rvm_usr_path/include:$C_INCLUDE_PATH"