scripts/utility in rvm-1.0.2 vs scripts/utility in rvm-1.0.3
- old
+ new
@@ -1,27 +1,31 @@
#!/usr/bin/env bash
__rvm_setup() {
# ZSH has 1 based array indexing, bash has 0 based.
- if [[ -n "$ZSH_VERSION" ]] ; then
+ if [[ -n "${ZSH_VERSION:-""}" ]] ; then
__shell_array_start=1
# Set clobber for zsh users, for compatibility with bash's append operator ( >> file ) behavior
setopt | \grep -qs '^noclobber$'
rvm_zsh_clobber=$?
setopt clobber
else
- __shell_array_start=0
+ __shell_array_start=0 # bash array indexes are 0 based.
fi ; export __shell_array_start
}
__rvm_teardown() {
- if [[ -n "$ZSH_VERSION" ]] ; then
+ declare rvm_dump_environment_flag=${rvm_dump_environment_flag:-0}
+ declare rvm_clang_flag=${rvm_clang_flag:-0}
+ declare rvm_prior_cc=${rvm_prior_cc:-""}
+
+ if [[ -n "${ZSH_VERSION:-""}" ]] ; then
if [[ "$rvm_zsh_clobber" -eq 0 ]] ; then
setopt noclobber
fi ; unset rvm_zsh_clobber
else
- :
+ : # currently we are not doing any option setting for bash.
fi
# Ruby strings are scoped to their action.
# Hence, we ensure we remove them at in
# the cleanup phase.
@@ -35,59 +39,74 @@
unset rvm_prior_cc
fi
unset rvm_ruby_strings
- [[ -n "$rvm_dump_environment_flag" ]] && __rvm_dump_environment
+ [[ $rvm_dump_environment_flag -eq 1 ]] && __rvm_dump_environment
+ return 0
}
+# Dump the current environment to a file.
__rvm_dump_environment() {
# Note: This assumes that there is a ','
local dump_environment_file="${rvm_dump_environment_flag/,*/}"
local dump_environment_type="${rvm_dump_environment_flag/*,/}"
if [[ -n "$dump_environment_file" && -n "$dump_environment_type" ]]; then
- if [[ "$dump_environment_type" == "atheis"* ]]; then
- \rm -rf "$dump_environment_file" && ln -s /dev/null "$dump_environment_file" >/dev/null 2>&1
+ if [[ "$dump_environment_type" == "atheis"* ]] && [[ -f "$dump_environment_file" ]] ; then
+ # TODO: Query Darcy about the ln.
+ \rm -f "$dump_environment_file" && ln -s /dev/null "$dump_environment_file" >/dev/null 2>&1
else
"$rvm_scripts_path/environment-convertor" "$dump_environment_type" "$(__rvm_environment_identifier)" > "$dump_environment_file"
- [[ "$?" -gt 0 ]] && \rm -rf "$dump_environment_file"
+ if [[ "$?" -gt 0 ]] && [[ -f "$dump_environment_file" ]] ; then
+ \rm -f "$dump_environment_file"
+ fi
fi
fi ; unset rvm_dump_environment_flag
+ return 0
}
# Return a list of directories under a given base path.
# Derived from rvm_ruby_string.
__rvm_ruby_string_paths_under() {
- local patch_parts="$(echo "$rvm_ruby_string" | \tr '-' ' ' | __rvm_strip)"
- while true; do
- echo "$1/$patch_parts" | \tr ' ' '/' | sed 's#\/$##'
- [[ -z "$patch_parts" ]] && break
- patch_parts="$(echo "$patch_parts" | awk '{$NF=""; print}' | __rvm_strip)"
+ local path="$1"
+ local path_parts="${rvm_ruby_string//-/ }"
+
+ while true ; do
+ echo "$path/$path_parts" | sed -e 's# #/#g' -e 's#/$##g'
+ [[ -z "$path_parts" ]] && break
+ path_parts="$(echo "$path_parts" | awk '{$NF=""; print}' | __rvm_strip)"
done
+
+ return 0
}
# Query the rvm key-value database for a specific key
# Allow overrides from user specifications in $rvm_config_path/user
__rvm_db() {
- key=$1 ; variable=$2
+ local value="" key="" variable=""
+
+ key=${1:-""}
+ variable=${2:-""}
+
if [[ -f "$rvm_config_path/user" ]] ; then
value="$($rvm_scripts_path/db "$rvm_config_path/user" "$key")"
fi
if [[ -z "$value" ]] ; then
value="$($rvm_scripts_path/db "$rvm_config_path/db" "$key")"
fi
if [[ -n "$value" ]] ; then
- if [[ -z $variable ]] ; then
+ if [[ -z "$variable" ]] ; then
echo $value
else
eval "$variable='$value'"
fi
fi
- unset key value variable
+
+ return 0
}
is_a_function() { type $1 | head -n 1 | \grep -q "function" ; }
__rvm_quote_args() {
@@ -98,19 +117,20 @@
else
quoted_string="$quoted_string $quoted_argument"
fi
done
echo "$quoted_string" | sed -e 's/^ *//g' -e 's/ *$//g'
+ return 0
}
__rvm_quote_args_with_shift() {
local shift_value="$1"; shift
while [[ "$shift_value" -gt 0 && "$#" -gt 0 ]]; do
- shift
- let shift_value=shift_value-1
+ shift ; ((shift_value--))
done
__rvm_quote_args "$@"
+ return 0
}
__rvm_warn_on_rubyopt() {
if [[ -n "$RUBYOPT" ]]; then
"$rvm_scripts_path"/log "warn" "Please note: You have the RUBYOPT environment variable set and this may interfere with normal rvm operations. We sugges unsetting it."
@@ -119,21 +139,15 @@
return 0
fi
}
__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)"
- fi
+ local strings=""
+ for rvm_ruby_string in $(echo ${rvm_ruby_args:-$rvm_ruby_string}) ; do
+ strings="$strings $(__rvm_select ; echo $rvm_ruby_string)"
done
- echo $results
- unset results
+ echo $strings
return 0
}
# Push an item onto a given array.
__rvm_push() {
@@ -166,57 +180,83 @@
builtin hash -r
}
# Run a specified command and log it.
__rvm_run() {
- log_file_name="$1" ; command="$2" ; message="$3"
+ local log_file_name="$1"
+ local command="$2"
+ local message="$3"
+
if [[ -z "$rvm_ruby_log_path" ]] ; then rvm_ruby_log_path="$rvm_log_path" ; fi
+
if [[ -n "$message" ]] ; then "$rvm_scripts_path/log" "info" "$message" ; fi
+
if [[ -n "$rvm_debug_flag" ]] ; then
"$rvm_scripts_path/log" "debug" "Executing: $command"
fi
\mkdir -p "$(dirname "$rvm_ruby_log_path/$log_file_name.log")"
+
\touch "$rvm_ruby_log_path/$log_file_name.log" "$rvm_ruby_log_path/$log_file_name.error.log" # for zsh :(
- echo "[$(date +'%Y-%m-%d %H:%M:%S')] $command" | tee "$rvm_ruby_log_path/$log_file_name.log" >> "$rvm_ruby_log_path/$log_file_name.error.log"
+
+ echo "[$(date +'%Y-%m-%d %H:%M:%S')] $command" | \tee "$rvm_ruby_log_path/$log_file_name.log" >> "$rvm_ruby_log_path/$log_file_name.error.log"
+
if [[ -z "$rvm_niceness" ]] || [[ "0" = "$rvm_niceness" ]] ; then
eval "$command" >> "$rvm_ruby_log_path/$log_file_name.log" 2>> "$rvm_ruby_log_path/$log_file_name.error.log"
else
eval "nice -n $rvm_niceness $command" >> $rvm_ruby_log_path/$log_file_name.log 2>> $rvm_ruby_log_path/$log_file_name.error.log
+ fi ; local result=$?
+
+ if [[ $result -gt 0 ]] ; then
+ "$rvm_scripts_path/log" "error" "Error running '$command', please check $rvm_ruby_log_path/$log_file_name*.log" ; __rvm_pushpop
fi
- 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
+
+ return $result
}
# Runs a command in a given env.
__rvm_run_with_env() {
- log_file_name="$1" ; env_name="$2" ; command="$3" ; message="$4"
+ local log_file_name="${1:-""}"
+ local env_name="${2:-""}"
+ local command="${3:-""}"
+ local message="${4:-""}"
+
if [[ -z "$env_name" ]]; then env_name="$(__rvm_environment_identifier)"; fi
+
if [[ -z "$rvm_ruby_log_path" ]] ; then rvm_ruby_log_path="$rvm_log_path" ; fi
+
if [[ -n "$message" ]] ; then "$rvm_scripts_path/log" "info" "$message" ; fi
+
if [[ -n "$rvm_debug_flag" ]] ; then
"$rvm_scripts_path/log" "debug" "Executing: $command in environment "$env_name""
fi
\mkdir -p "$(dirname "$rvm_ruby_log_path/$log_file_name.log")"
+
\touch "$rvm_ruby_log_path/$log_file_name.log" "$rvm_ruby_log_path/$log_file_name.error.log" # for zsh :(
+
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $command # under $env_name" | tee "$rvm_ruby_log_path/$log_file_name.log" >> "$rvm_ruby_log_path/$log_file_name.error.log"
- if [[ -z "$rvm_niceness" ]] || [[ "0" = "$rvm_niceness" ]] ; then
+
+ if [[ -z "$rvm_niceness" || "0" = "$rvm_niceness" ]] ; then
eval "__rvm_with_env '$env_name' '$command'" >> "$rvm_ruby_log_path/$log_file_name.log" 2>> "$rvm_ruby_log_path/$log_file_name.error.log"
else
eval "nice -n $rvm_niceness __rvm_with_env '$env_name' '$command'" >> $rvm_ruby_log_path/$log_file_name.log 2>> $rvm_ruby_log_path/$log_file_name.error.log
+ fi ; result=$?
+
+ if [[ $result -gt 0 ]] ; then
+ "$rvm_scripts_path/log" "error" "Error running '$command' under $env_name, please check $rvm_ruby_log_path/$log_file_name*.log" ; __rvm_pushpop
fi
- if [[ $? -gt 0 ]] ; then "$rvm_scripts_path/log" "error" "Error running '$command' under $env_name, please check $rvm_ruby_log_path/$log_file_name*.log" ; __rvm_pushpop ; return 1 ; fi
- unset log_file command env_name
+
+ return $result
}
# Unset both rvm variables as well as ruby-specific variables
# Preserve gemset if 'rvm_sticky' is set (persist gemset unless clear is explicitely called).
__rvm_cleanse_variables() {
__rvm_unset_ruby_variables
- if [[ "$rvm_sticky_flag" = "1" ]] ; then export rvm_gemset_name ; else unset rvm_gemset_name ; fi
+ if [[ ${rvm_sticky_flag:-0} -eq 1 ]] ; then export rvm_gemset_name ; else unset rvm_gemset_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_sticky_flag rvm_rvmrc_flag rvm_gems_flag rvm_only_path_flag rvm_docs_flag rvm_ruby_aliases rvm_patch_names rvm_clang_flag rvm_install_arguments rvm_dump_environment_flag rvm_ruby_alias
}
# Unset ruby-specific variables
@@ -224,31 +264,27 @@
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_release_version 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_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 rvm_ruby_name rvm_ruby_strings rvm_ruby_repo_path
}
# Usage: __rvm_with_env 'env-name' 'command'
__rvm_with_env() {
- [[ -n "$rvm_trace_flag" ]] && rvm_env_args="--trace"
- rvm_env_command="$(echo "$2" | sed "s/rvm /rvm $rvm_env_args /")"
- # Subshells!
- (
- source "$rvm_scripts_path/rvm"
- rvm "$rvm_env_args" use $1 && eval "$rvm_env_command"
- )
- unset rvm_env_args rvm_env_command
+ local environment_id="$1" command="$2"
+ ( rvm use "$environment_id" ; eval "$command" )
}
# Returns the first 1.8.7-compatible (partly) ruby for use
# with things like rbx etc which require a ruby be installed.
__rvm_18_compat_ruby() {
- rubies=""
+ local rubies=""
for ruby_name in $(\ls "$rvm_rubies_path"); do
if [[ ! -L "$rvm_rubies_path/$ruby_name" ]] && [[ "$ruby_name" =~ 1.8. || "$ruby_name" =~ rbx- || "$ruby_name" =~ ree- ]] ; then
rubies="$rubies $ruby_name"
fi
done; unset ruby_name
+
echo "$rubies" | sed 's/^ //' | \tr ' ' '\n' | sort | tail -n1
- unset rubies
+
+ return 0
}
__rvm_ensure_has_18_compat_ruby() {
if [[ -z "$(__rvm_18_compat_ruby)" ]]; then
# TODO: install currently doesn't return the correct status.
@@ -256,63 +292,77 @@
if ! ( "$rvm_scripts_path/manage" install 1.8.7 ); then
"$rvm_scripts_path/log" "fail" "To proceed rvm requires a 1.8-compatible ruby is installed. We attempted to install 1.8.7 automatically but it failed."
"$rvm_scripts_path/log" "fail" "Please install it manually (or a compatible alternative) to proceed."
compat_result=1
fi ; unset original_ruby
+ # TODO: Why are we unsetting original_ruby here
return $compat_result
fi
+
+ return 0
}
__rvm_inherit_trace_flag() {
if [[ -n "$rvm_trace_flag" ]]; then
set -x ; export rvm_trace_flag
fi
+ return 0
}
# Cleans up temp folders for a given prefix,
# typically the current process id.
__rvm_cleanup_temp_for() {
- [[ -z "$1" ]] && return 1
+ local prefix="$1"
+
+ [[ -z "$prefix" ]] && return 1
+
if [[ -d "$rvm_tmp_path/" ]]; then
- \rm -rf "$rvm_tmp_path/$1"* >/dev/null 2>&1
- fi ; exit
+ \rm -rf "$rvm_tmp_path/$prefix"* >/dev/null 2>&1
+ fi
+
+ exit
}
__rvm_cleanup_temp_on_exit() {
trap "__rvm_cleanup_temp_for '$$'" 0 1 2 3 15
}
__rvm_set_rvmrc() {
if [[ "$HOME" != "$PWD" ]] ; then
- if [[ "$rvm_verbose_flag" -eq 1 ]] ; then flags="use " ; fi
+ if [[ ${rvm_verbose_flag:-0} -eq 1 ]] ; then flags="use " ; fi
if [[ -s .rvmrc ]] ; then
mv .rvmrc .rvmrc.$(date +%m.%d.%Y-%H:%M:%S)
"$rvm_scripts_path/log" "warning" ".rvmrc is not empty, moving aside to preserve."
fi
local identifier=$(__rvm_environment_identifier)
+
printf "if [[ -n \"\$rvm_environments_path\" && -s \"\$rvm_environments_path/$identifier\" ]] ; then\n \\. \"\$rvm_environments_path/$identifier\"" > .rvmrc
printf "\nelse\n rvm --create $flags \"$identifier\"\nfi" >> .rvmrc
unset flags
else
"$rvm_scripts_path/log" "error" ".rvmrc cannot be set in your home directory. \n The home .rvmrc is for global rvm settings only."
fi
}
__rvm_load_rvmrc() {
- [[ -z "$rvm_ignore_rvmrc" ]] && return
+ rvm_ignore_rvmrc=${rvm_ignore_rvmrc:-0}
+ [[ $rvm_ignore_rvmrc -eq 1 ]] && return 0
+
for rvmrc in /etc/rvmrc $HOME/.rvmrc ; do
if [[ -f "$rvmrc" ]] ; then
if \grep -q '^\s*rvm .*$' $rvmrc ; then
"$rvm_scripts_path/log" "error" "$rvmrc is for rvm settings only.\nrvm CLI may NOT be called from within $rvmrc. \nSkipping the loading of $rvmrc"
return 1
else
source "$rvmrc"
fi
fi
done
+
+ return 0
}
# Wrap the specified ruby code file in a Benchmark.bmbm block and execute it.
__rvm_benchmark() {
code="require \"benchmark\" \n Benchmark.bmbm do |benchmark| \n benchmark.report(\"${rvm_ruby_file}\") do \n"
@@ -323,18 +373,20 @@
rvm_ruby_args="$rvm_tmp_path/$$.rb"
rvm_benchmark_flag=1
rvm_action="ruby"
if [[ -n "$rvm_debug_flag" ]] ; then printf "\n$rvm_tmp_path/$$.rb:\n$(cat $rvm_tmp_path/$$.rb)" ; fi
# Override ruby string stuff, pass through.
- old_rvm_ruby_string=$rvm_ruby_string
+ local old_rvm_ruby_string=$rvm_ruby_string
+ # TODO: We can likely do this in a subshell in order to preserve the original environment?
unset rvm_ruby_string
export rvm_ruby_strings
"$rvm_scripts_path/set" "$rvm_action" $rvm_ruby_args
result=$?
# Restore the state pre-sets.
[[ -n "$old_rvm_ruby_string" ]] && rvm_ruby_string=$old_rvm_ruby_string
- unset old_rvm_ruby_string
+
+ return $result
}
# Loop over the currently installed rubies and refresh their binscripts.
__rvm_bin_scripts() {
for rvm_ruby_binary in "$rvm_rubies_path"/*/bin/ruby ; do
@@ -342,36 +394,40 @@
rvm_ruby_string=$(dirname "$rvm_ruby_binary" | xargs dirname | xargs basename)
__rvm_select
__rvm_bin_script
fi
done
+ return 0
}
# Write the bin/ wrapper script for currently selected ruby.
# TODO: Adjust binscript to be able to handle all rubies not just the standard interpreteres.
__rvm_bin_script() {
"$rvm_scripts_path/wrapper" "$rvm_ruby_string"
+ return $?
}
# Add bin path if not present
__rvm_conditionally_add_bin_path() {
if echo "${PATH//:/ }" | \grep -vqF "$rvm_bin_path " ; then
PATH="${rvm_bin_path}:$PATH"
builtin hash -r
fi
+ return 0
}
# Reset any rvm gathered information about the system and its state.
# rvm will refresh the stored information the next time it is called after reset.
__rvm_reset() {
- __rvm_remove_rvm_from_path
- __rvm_conditionally_add_bin_path
- export PATH
+ __rvm_remove_rvm_from_path ; __rvm_conditionally_add_bin_path ; export PATH
+
builtin hash -r
- for flag in default passenger editor ; do \rm -f "$rvm_bin_path"/${flag}_* ; done
- unset flag
+ local flag=""
+ for flag in default passenger editor ; do
+ \rm -f "$rvm_bin_path"/${flag}_*
+ done
for file in system default ; do
[[ -f "${rvm_path}/${file}" ]] && \rm -f "$rvm_path/${file}"
[[ -f "${rvm_config_path}/${file}" ]] && \rm -f "$rvm_config_path/${file}"
[[ -f "${rvm_environments_path}/${file}" ]] && \rm -f "$rvm_environments_path/${file}"
@@ -384,17 +440,21 @@
for system_config in system_ruby system_gem_path system_user_gem_path ; do
"$rvm_scripts_path/db" "$rvm_config_path/user" "$system_config" "delete"
done ; unset system_config variable
\rm -f $rvm_bin_path/ruby $rvm_bin_path/gem $rvm_bin_path/rake $rvm_bin_path/irb $rvm_bin_path/default*
+
+ return 0
}
# Implode removes the entire rvm installation under $rvm_path.
__rvm_implode() {
while : ; do
"$rvm_scripts_path/log" "warn" "Are you SURE you wish for rvm to implode? This will remove $rvm_path ? (type 'yes' or 'no')"
+
read response
+
if [[ "yes" = "$response" ]] ; then
if [[ "/" = "$rvm_path" ]] ; then
"$rvm_scripts_path/log" "error" "remove '/' ?!... Ni!"
else
if [[ -d "$rvm_path" ]] ; then
@@ -409,57 +469,69 @@
elif [[ "no" = "$response" ]] ; then
"$rvm_scripts_path/log" "info" "Cancelling implosion, no harm done :)"
break
fi
done
+
+ return 0
}
# Output the current ruby's rvm source path.
__rvm_source_dir() {
if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select ; fi
+
if [[ -z "$rvm_ruby_src_path" ]] ; then
"$rvm_scripts_path/log" "fail" "No source directory exists for the default implementation."
else
echo "$rvm_ruby_src_path"
fi
+
+ return 0
}
# Initialize rvm, ensuring that the path and directories are as expected.
__rvm_initialize() {
rvm_ruby_load_path="."
rvm_ruby_require=""
- __rvm_clean_path
+ __rvm_clean_path ; __rvm_conditionally_add_bin_path ; export PATH
- __rvm_conditionally_add_bin_path
- export PATH
-
\mkdir -p "$rvm_src_path" "$rvm_bin_path" "$rvm_archives_path" "$rvm_gems_path" "$rvm_tmp_path" "$rvm_repo_path"
+
+ return 0
}
# Update rubygems or binscripts based on CLI selection.
__rvm_update() {
__rvm_pushpop $rvm_path
- if [[ "$rvm_head_flag" == "1" ]] || [[ -n "$rvm_self_flag" ]] || [[ "update" = "$rvm_action" ]] || [[ -n "$rvm_update_flag" ]] ; then
+
+ if [[ ${rvm_head_flag:-0} -eq 1 || ${rvm_self_flag:-0} -eq 1 || "update" = "${rvm_action:-""}" || ${rvm_update_flag:-0} -eq 1 ]] ; then
__rvm_version
__rvm_update_rvm
fi
- [[ -n "$rvm_bin_flag" ]] && __rvm_bin_scripts
+
+ [[ ${rvm_bin_flag:-0} -eq 1 ]] && __rvm_bin_scripts
+
# Update to the latest rubygems.
- [[ -n "$rvm_rubygems_flag" ]] && "$rvm_scripts_path/rubygems" current
+ [[ ${rvm_rubygems_flag:-0} -eq 1 ]] && "$rvm_scripts_path/rubygems" current
unset rvm_update_flag rvm_action rvm_self_flag rvm_ruby_revision rvm_bin_flag rvm_rubygems_flag
+
__rvm_pushpop
+
+ return 0
}
# Update rvm using rubygems
# If --head was specified, update from git repository master branch.
__rvm_update_rvm() {
+
\mkdir -p "$rvm_src_path"
+
__rvm_pushpop "$rvm_src_path"
- if [[ "$rvm_head_flag" == "1" ]] ; then
+ if [[ ${rvm_head_flag:-0} -eq 1 ]] ; 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 --depth 1 git://github.com/wayneeseguin/rvm.git || git clone http://github.com/wayneeseguin/rvm.git ) && builtin cd rvm/ && ./scripts/install
fi
@@ -472,47 +544,65 @@
__rvm_run "install" "builtin cd $rvm_src_path/rvm-${stable_version}/ ; ./install" "Installing rvm-${stable_version}..."
fi
__rvm_pushpop
+
rvm_hook="after_update" ; source "$rvm_scripts_path/hook"
+
+ return 0
}
__rvm_reboot() {
"$rvm_scripts_path/log" "warn" "Do you wish to reboot rvm? ('yes', or 'no')"
+
+ local response="no"
+
read response
+
if [[ "yes" = "$response" ]] ; then
builtin cd $rvm_path
+
__rvm_reset
+
mv "$rvm_path/archives" "$HOME/.archives"
+
if [[ "/" = "$rvm_path" ]] ; then
"$rvm_scripts_path/log" "error" "remove '/' ?!... NO!"
else
if [[ -d "$rvm_path" ]] ; then \rm -rf "$rvm_path/" ; fi
fi
+
gem install rvm $rvm_gem_options
+
__rvm_update_rvm
- source $rvm_path/scripts/rvm
+
+ source "$rvm_path/scripts/rvm"
else
"$rvm_scripts_path/log" "info" "Carry on then..."
- fi ; unset response
+ fi
+
+ return 0
}
# Create the irbrc for the currently selected ruby installation.
__rvm_irbrc() {
- if [[ -d "$rvm_ruby_home" ]] && [[ ! -s "$rvm_ruby_irbrc" ]] ; then
+ if [[ -d "$rvm_ruby_home" && ! -s "$rvm_ruby_irbrc" ]] ; then
\cp "$rvm_scripts_path/irbrc" "$rvm_ruby_irbrc"
fi
+ return $?
}
# Push or Pop a directory based on zero or one directory argument provided.
__rvm_pushpop() {
if [[ -z "$1" ]] ; then
popd > /dev/null 2>&1
else
pushd "$1" > /dev/null 2>&1
fi
+
+ return $?
}
# Save or restore the rvm's state. This is a toggle action.
# Meant for use before and after an operation that might reset the currently selected ruby.
__rvm_state() {
@@ -528,24 +618,37 @@
rvm_ruby_string="$rvm_state"
__rvm_select
__rvm_use
unset rvm_state
fi
+
+ return 0
}
# Output an inspection of selected 'binary' scripts, based on CLI selection.
__rvm_inspect() {
+ rvm_shebang_flag=${rvm_shebang_flag:-0}
+ rvm_env_flag=${rvm_env_flag:-0}
+ rvm_path_flag=${rvm_path_flag:-0}
+ rvm_head_flag=${rvm_head_flag:-0}
+ rvm_tail_flag=${rvm_tail_flag:-0}
+ rvm_all_flag=${rvm_all_flag:-0}
+
for binary in $rvm_ruby_args ; do
actual_file="$(command -v $binary)"
+
"$rvm_scripts_path/log" "info" "$actual_file:"
- if [[ -n "$rvm_shebang_flag" ]] ; then head -n 1 < "$actual_file" ; fi
- if [[ -n "$rvm_env_flag" ]] ; then awk '/ENV/' < "$actual_file" ; fi
- if [[ -n "$rvm_path_flag" ]] ; then awk '/PATH/' < "$actual_file" ; fi
- if [[ -n "$rvm_head_flag" ]] ; then head -n 5 < "$actual_file" ; fi
- if [[ -n "$rvm_tail_flag" ]] ; then tail -n 5 < "$actual_file" ; fi
- if [[ -n "$rvm_all_flag" ]] ; then cat $actual_file ; fi
+
+ if [[ $rvm_shebang_flag -eq 1 ]] ; then head -n 1 < "$actual_file" ; fi
+ if [[ $rvm_env_flag -eq 1 ]] ; then awk '/ENV/' < "$actual_file" ; fi
+ if [[ $rvm_path_flag -eq 1 ]] ; then awk '/PATH/' < "$actual_file" ; fi
+ if [[ $rvm_head_flag -eq 1 ]] ; then head -n 5 < "$actual_file" ; fi
+ if [[ $rvm_tail_flag -eq 1 ]] ; then tail -n 5 < "$actual_file" ; fi
+ if [[ $rvm_all_flag -eq 1 ]] ; then cat $actual_file ; fi
done
+
+ return 0
}
# Attempt to override the Darwin build settings for rubies
# This should only be used in extreme edge cases that will not work via the default way.
__rvm_make_flags() {
@@ -575,131 +678,177 @@
CFLAGS="${CFLAGS:-"-isysroot /Developer/SDKs/$rvm_sdk $rvm_archflags"}" ; export CFLAGS
LDFLAGS="${LDFLAGS:-"-Wl,-syslibroot /Developer/SDKs/$rvm_sdk $rvm_archflags"}" ; export LDFLAGS
# CXXFLAGS="-mmacosx-version-min="$(sw_vers -productVersion | awk -F'.' '{print $1"."$2}')" -isysroot /Developer/SDKs/$rvm_sdk " ; export CXXFLAGS
fi
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"
export ACLOCAL_PATH="$rvm_usr_path/share/aclocal"
export ACLOCAL_FLAGS="-I $ACLOCAL_PATH"
export PKG_CONFIG_PATH="$rvm_usr_path/lib/pkgconfig:$PKG_CONFIG_PATH"
PATH="$rvm_usr_path/bin:$PATH"
builtin hash -r
+
+ return 0
}
__rvm_become() {
- [[ -n "$1" ]] && rvm_ruby_string="$1"
+ local string="$1"
+
+ [[ -n "$string" ]] && rvm_ruby_string="$string"
+
{ __rvm_ruby_string && __rvm_select && __rvm_use; } > /dev/null 2>&1
+
+ return 0
}
__rvm_ensure_has_environment_files() {
local environment_identifier="$(__rvm_environment_identifier)"
+
local file_name="${rvm_environments_path}/$environment_identifier"
if [[ ! -s "$file_name" ]] ; then
\mkdir -p "${rvm_environments_path}"
+
echo "export PATH=\"${rvm_ruby_gem_home}/bin:${rvm_ruby_global_gems_path}/bin:${rvm_ruby_home}/bin:${rvm_bin_path}:\$PATH\"" > "$file_name"
+
for variable in RUBY_VERSION GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME IRBRC rvm_ruby_string rvm_gemset_name MAGLEV_HOME ; do
eval "export $variable"
+
eval "value=\$${variable}"
+
if [[ -n "$value" ]] ; then
printf "${variable}='$value'\nexport ${variable}\n" >> "$file_name"
else
printf "unset ${variable}\n" >> "$file_name"
fi
done ; unset variable value
fi ; unset file_name
+ local directory_name=""
+ local wrapper_identifier=""
# Next, ensure we have default wrapper files. Also, prevent it from recursing.
- if [[ -z "$rvm_creating_default_wrappers" ]]; then
+ if [[ ${rvm_creating_default_wrappers:-0} -eq 1 ]]; then
# We need to generate wrappers for both the default gemset and the global gemset.
for wrapper_identifier in "$environment_identifier" "${environment_identifier}@global" ; do
- rvm_creating_default_wrappers=1
- directory_name="$rvm_wrappers_path/$wrapper_identifier"
- if [[ ! -L "$directory_name" && ! -d "$directory_name" ]]; then
- \mkdir -p "$directory_name"
- "$rvm_scripts_path/wrapper" "$wrapper_identifier" &> /dev/null
- fi
- unset rvm_creating_default_wrappers directory_name
- done; unset wrapper_identifier
+
+ rvm_creating_default_wrappers=1
+
+ directory_name="$rvm_wrappers_path/$wrapper_identifier"
+
+ if [[ ! -L "$directory_name" && ! -d "$directory_name" ]]; then
+ \mkdir -p "$directory_name"
+
+ "$rvm_scripts_path/wrapper" "$wrapper_identifier" &> /dev/null
+ fi
+ rvm_creating_default_wrappers=0
+ done
fi
+ return 0
}
# Strip whitespace and normalize it all.
__rvm_strip() {
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/[[:space:]]\{1,\}/ /g'
+ return $?
}
__rvm_using_gemset_globalcache() {
"$rvm_scripts_path/db" "$rvm_config_path/user" "use_gemset_globalcache" | \grep -q '^true$'
+ return $?
}
__rvm_current_gemcache_dir() {
if __rvm_using_gemset_globalcache; then
echo "$rvm_gems_cache_path"
else
echo "${rvm_ruby_gem_home:-"$GEM_HOME"}/cache"
fi
+ return 0
}
__rvm_Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything() {
for index in {1..750} ; do sleep 0.25 ; echo -n '.' ; done ; printf "%d" 0x2A ; echo
+ return 0
}
__rvm_ultimate_question() {
- printf "\nI do not know the Ultimate Question, "
- printf "\nhowever I can help you build a more "
- printf "\npowerful Ruby which can compute the "
- printf "\nUltimate Question.\n"
+ printf "
+ I do not know the Ultimate Question,
+ however I can help you build a more
+ powerful Ruby which can compute the
+ Ultimate Question.
+ "
+ return 0
}
__rvm_load_env_file() {
- if [[ -f "$rvm_environments_path/$1" ]]; then
+ local string="$1"
+ if [[ -f "$rvm_environments_path/$string" ]]; then
# Restore the path to it's state minus rvm
__rvm_remove_rvm_from_path
- \. "$rvm_environments_path/$1"
+
+ # source the environment file
+ \. "$rvm_environments_path/$string"
+
+ # clear the PATH cache
builtin hash -r
+ elif [[ -n "$string" ]] ; then
+ rvm "$string"
else
- rvm use "$1" >/dev/null 2>&1
+ : # TODO: This should have some error handling in the context.
fi
+ return 0
}
__rvm_md5_for() {
if command -v md5 > /dev/null; then
echo "$1" | md5
- else
+ elif command -v md5sum > /dev/null ; then
echo "$1" | md5sum | awk '{print $1}'
+ else
+ "$rvm_path/scripts/log" "error" "Neither md5 nor md5sum were found in the PATH"
+ return 1
fi
+
+ return 0
}
__rvm_rvmrc_key() {
__rvm_md5_for "$1"
+ return $?
}
__rvm_reset_rvmrc_trust() {
touch "$rvm_config_path/rvmrcs"
"$rvm_scripts_path/db" "$rvm_config_path/rvmrcs" "$(__rvm_rvmrc_key "$1")" "delete" >/dev/null 2>&1
+ return $?
}
__rvm_trust_rvmrc() {
touch "$rvm_config_path/rvmrcs"
__rvm_reset_rvmrc_trust "$1"
"$rvm_scripts_path/db" "$rvm_config_path/rvmrcs" "$(__rvm_rvmrc_key "$1")" "1" >/dev/null 2>&1
+ return $?
}
__rvm_untrust_rvmrc() {
touch "$rvm_config_path/rvmrcs"
__rvm_reset_rvmrc_trust "$1"
"$rvm_scripts_path/db" "$rvm_config_path/rvmrcs" "$(__rvm_rvmrc_key "$1")" "0" >/dev/null 2>&1
+ return $?
}
__rvm_rvmrc_stored_trust() {
touch "$rvm_config_path/rvmrcs"
"$rvm_scripts_path/db" "$rvm_config_path/rvmrcs" "$(__rvm_rvmrc_key "$1")"
+ return $?
}
__rvm_rvmrc_tools() {
local rvmrc_action="$1"
[[ $# -gt 0 ]] && shift
@@ -726,17 +875,18 @@
else
echo "The trustiworthiness of '$rvmrc_path' is currently unknown."
fi
;;
load)
- rvm_rvmrc_cwd="" rvm_trust_rvmrcs=1 __rvm_project_rvmrc "$(dirname "$rvmrc_path")"
+ rvm_rvmrc_cwd="" rvm_trust_rvmrcs=1 __rvm_project_rvmrc "$(dirname "$rvmrc_path")"
;;
*)
echo "Usage: rvm rvmrc {trust,untrust,trusted,load,reset}"
return 1
;;
esac
+ return $?
}
__rvm_check_rvmrc_trustworthiness() {
# Trust when they have the flag... of doom!
[[ -z "$1" || "$rvm_trust_rvmrcs" = "1" ]] && return 0
@@ -744,17 +894,19 @@
if [[ -z "$value" ]] ; then
__rvm_ask_to_trust "$1"
else
[[ "$value" = "1" ]]
fi
+ return $?
}
__rvm_ask_to_trust() {
[[ -n "$rvm_promptless" ]] && return 2
printf "
============================================================
- RVM has encountered a new untrusted .rvmrc file containing:
+ RVM has encountered a not yet trusted .rvmrc file in the
+ current working directory which contains the following code:
============================================================
$(cat $1)
============================================================
@@ -787,21 +939,28 @@
}
# Checks the rvmrc for the given directory. Note that if
# argument is passed, it will be used instead of pwd.
__rvm_project_rvmrc() {
+ declare -i rvm_project_rvmrc_default=${rvm_project_rvmrc_default:-0}
+ declare rvm_rvmrc_cwd="${rvm_rvmrc_cwd:-""}"
+ declare rvm_previous_environment="${rvm_previous_environment:-""}"
+
local cwd
+
# Get the first argument or the pwd.
cwd="${1:-"$PWD"}"
while : ; do
if [[ -z "$cwd" || "$HOME" = "$cwd" || "/" = "$cwd" ]] ; then
if [[ -n "$rvm_rvmrc_cwd" ]] ; then
- if [[ "$rvm_project_rvmrc_default" = "1" ]]; then
+ if [[ $rvm_project_rvmrc_default -eq 1 ]]; then
__rvm_load_env_file "default"
elif [[ -n "$rvm_previous_environment" ]] ; then
__rvm_load_env_file "$rvm_previous_environment"
- fi ; unset rvm_rvmrc_cwd rvm_previous_environment
+ fi
+ rvm_rvmrc_cwd=""
+ rvm_previous_environment=""
fi
break
else
if [[ -f "$cwd/.rvmrc" ]] ; then
if [[ "$rvm_rvmrc_cwd" != "$cwd" ]] ; then
@@ -820,10 +979,11 @@
else
cwd="$(dirname "$cwd")"
fi
fi
done
+ return $?
}
__rvm_record_install() {
[[ -z "$1" ]] && return
local recorded_ruby_name="$($rvm_scripts_path/tools strings "$1")"
@@ -832,21 +992,22 @@
\touch "$rvm_install_record_file"
\rm -f "$rvm_install_record_file.tmp"
\grep -v "^$recorded_ruby_name " < "$rvm_install_record_file" > "$rvm_install_record_file.tmp"
echo "$rvm_install_command" >> "$rvm_install_record_file.tmp"
\rm -f "$rvm_install_record_file"
- mv "$rvm_install_record_file.tmp" "$rvm_install_record_file"
+ \mv "$rvm_install_record_file.tmp" "$rvm_install_record_file"
}
__rvm_remove_install_record() {
local recorded_ruby_name="$($rvm_scripts_path/tools strings "$1")"
local rvm_install_record_file="$rvm_config_path/installs"
if [[ -s "$rvm_install_record_file" ]]; then
- mv "$rvm_install_record_file" "$rvm_install_record_file.tmp"
+ \mv "$rvm_install_record_file" "$rvm_install_record_file.tmp"
\grep -v "^$recorded_ruby_name " < "$rvm_install_record_file.tmp" > "$rvm_install_record_file"
\rm -f "$rvm_install_record_file.tmp"
fi
+ return 0
}
__rvm_recorded_install_command() {
local recorded_ruby_name="$($rvm_scripts_path/tools strings "$1" | awk -F"$rvm_gemset_separator" '{print $1}')"
[[ -z "$recorded_ruby_name" ]] && return 1
@@ -854,37 +1015,41 @@
if [[ -s "$rvm_config_path/installs" ]] && \grep -q "$recorded_ruby_match" "$rvm_config_path/installs" ; then
\grep "$recorded_ruby_match" < "$rvm_config_path/installs" | head -n1
else
return 1
fi
+ return $?
}
__rvm_environment_identifier() {
- ruby_string="$(command -v ruby)"
-
- if [ -n "$ruby_string" ] && echo "$ruby_string" | \grep -q -F "$rvm_rubies_path"; then
- echo "$GEM_HOME" | xargs basename
- else
- echo "system"
- fi ; unset ruby_string
+ local path
+ local string
+ path="$(command -v ruby)"
+ string="${path//*rubies\//}"
+ string="${string//\/*/}"
+ echo "${string:-system}"
+ return $?
}
__rvm_expand_ruby_string() {
- if [[ -z "$1" || "$1" = "all" ]]; then
+ local string="$1"
+ if [[ -z "$string" || "$string" = "all" ]]; then
"$rvm_scripts_path/list" strings | tr ' ' "\n" | __rvm_strip
- elif [[ "$1" = "all-gemsets" ]]; then
+ elif [[ "$string" = "all-gemsets" ]]; then
"$rvm_scripts_path/list" gemsets strings | __rvm_strip
- elif [[ "$1" = "default-with-rvmrc" || "$1" = "rvmrc" ]]; then
+ elif [[ "$string" = "default-with-rvmrc" || "$string" = "rvmrc" ]]; then
"$rvm_scripts_path/tools" path-identifier "$PWD"
- elif [[ "$1" == "all-rubies" || "$1" = "rubies" ]]; then
+ elif [[ "$string" == "all-rubies" || "$string" = "rubies" ]]; then
"$rvm_scripts_path/list" rubies strings | __rvm_strip
- elif [[ "$1" == "current-ruby" || "$1" = "gemsets" ]]; then
- local current_ruby="$(__rvm_environment_identifier | awk -F"$rvm_gemset_separator" '{print $1}')"
+ elif [[ "$string" == "current-ruby" || "$string" = "gemsets" ]]; then
+ local current_ruby="$(__rvm_environment_identifier | awk -F"$rvm_gemset_separator" '{print $string}')"
rvm_silence_logging=1 "$rvm_scripts_path/gemsets" list | sed "s/^/$current_ruby$rvm_gemset_separator/" | __rvm_strip
- elif [[ "$1" = "current" ]]; then
+ elif [[ "$string" = "current" ]]; then
__rvm_environment_identifier
- elif [[ "$1" = "aliases" ]]; then
- awk -F= '{print $1}' < "$rvm_config_path/alias" | __rvm_strip
+ elif [[ "$string" = "aliases" ]]; then
+ awk -F= '{print $string}' < "$rvm_config_path/alias" | __rvm_strip
else
- echo "$1" | tr "," "\n" | __rvm_strip
+ echo "$string" | tr "," "\n" | __rvm_strip
fi
+ return $?
}
+