#!/usr/bin/env bash # 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 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 [[ ! -z "$value" ]] ; then if [[ -z $variable ]] ; then echo $value else eval "$variable=$value" fi fi unset key value variable } is_a_function() { type $1 | head -n 1 | grep -q "function" ; } # Ouput rvm environment information. __rvm_info() { if [[ ! -z "$rvm_ruby_args" ]] ; then cat < <(rvm_ruby_string="$rvm_ruby_args"; __rvm_select ; __rvm_use ; __rvm_environment_info; echo -e "$environment_info") else __rvm_environment_info echo -e "$environment_info" fi } __rvm_environment_info() { environment_info="" ; full_version="" ruby=$(command -v ruby) if [[ $? -eq 0 ]] && [[ -x "$ruby" ]] ; then full_version="$($ruby -v)" ; fi environment_info="$environment_info\nsystem:\n uname: \"$(uname -a)\"" if [[ ! -z "$ZSH_VERSION" ]] ; then environment_info="$environment_info\n shell: \"zsh\"\n version: \"$ZSH_VERSION\"" fi if [[ ! -z "$BASH_VERSION" ]] ; then environment_info="$environment_info\n shell: \"bash\"\n version: \"$BASH_VERSION\"" fi environment_info="$environment_info\n\nrvm:" environment_info="$environment_info\n type: \"$(head -n 1 < <(type rvm))\"" environment_info="$environment_info\n version: \"$(__rvm_version | tr "\n" ' ' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')\"" environment_info="$environment_info\n\nruby:" environment_info="$environment_info\n interpreter: \"$(echo "${full_version}" | awk '{print $1}')\"" environment_info="$environment_info\n version: \"$(echo "${full_version}" | awk '{print $2}')\"" environment_info="$environment_info\n date: \"$(echo "${full_version}" | sed 's/^.*(\([0-9]\{4\}\(-[0-9][0-9]\)\{2\}\).*$/\1/')\"" environment_info="$environment_info\n platform: \"$(echo "${full_version}" | sed 's/^.*\[//' | sed 's/\].*$//')\"" environment_info="$environment_info\n patchlevel: \"$(echo "${full_version}" | sed 's/^.*(//' | sed 's/).*$//')\"" environment_info="$environment_info\n full_version: \"${full_version}\"" environment_info="$environment_info\n\nhomes:" environment_info="$environment_info\n gem: \"${GEM_HOME:-'not set'}\"" environment_info="$environment_info\n ruby: \"${MY_RUBY_HOME:-'not set'}\"" environment_info="$environment_info\n\nbinaries:" environment_info="$environment_info\n ruby: \"$(command -v ruby)\"" environment_info="$environment_info\n irb: \"$(command -v irb)\"" environment_info="$environment_info\n gem: \"$(command -v gem)\"" environment_info="$environment_info\n rake: \"$(command -v rake)\"" environment_info="$environment_info\n\nenvironment:" environment_info="$environment_info\n GEM_HOME: \"$GEM_HOME\"" environment_info="$environment_info\n GEM_PATH: \"$GEM_PATH\"" environment_info="$environment_info\n BUNDLE_PATH: \"$BUNDLE_PATH\"" environment_info="$environment_info\n MY_RUBY_HOME: \"$MY_RUBY_HOME\"" environment_info="$environment_info\n IRBRC: \"$IRBRC\"" environment_info="$environment_info\n RUBYOPT: \"$RUBYOPT\"" environment_info="$environment_info\n gemset: \"$(echo $GEM_HOME | awk -F${rvm_gemset_separator:-'@'} '{print $2}')\"\n" if [[ ! -z "$MAGLEV_HOME" ]] ; then environment_info="$environment_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 $rvm_scripts_path/log "debug" "uname -r: $(uname -r)" $rvm_scripts_path/log "debug" "uname -m: $(uname -m)" $rvm_scripts_path/log "debug" "sw_vers: $(sw_vers | tr "\n" ',')" $rvm_scripts_path/log "debug" "ARCHFLAGS: $ARCHFLAGS" $rvm_scripts_path/log "debug" "LDFLAGS: $LDFLAGS" $rvm_scripts_path/log "debug" "CFLAGS: $CFLAGS" $rvm_scripts_path/log "debug" "/Developer/SDKs/*:$(/usr/bin/basename -a /Developer/SDKs/* | tr "\n" ',')" fi for file_name in $(echo $rc_files) ; do if [[ -s "$file_name" ]] ; then $rvm_scripts_path/log "debug" "$file_name:\n$(grep 'rvm' $file_name 2>/dev/null)" fi done if [[ "root" = "$(whoami)" ]] ; then debug_files="$rvm_config_path/default $rvm_config_path/system $rvm_config_path/db /etc/rvmrc /etc/gemrc" else debug_files="$rvm_config_path/default $rvm_config_path/system $rvm_config_path/db $HOME/.rvmrc $HOME/.gemrc" fi for file_name in $(echo $debug_files); do if [[ -f "$file_name" ]] && [[ -s "$file_name" ]] ; then $rvm_scripts_path/log "debug" "$file_name \(filtered\):\n$(cat $file_name | awk '!/assword|_key/')\n" fi 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)" 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() { array=$1 ; shift ; item=$2 # TODO: allow loop over more arguments. eval "index=\$((\${#${array}[*]} + $__shell_array_start))" eval "${array}[${index}]=${item}" unset array item } # Clean all *duplicate* items out of the path. (keep first occurrence of each) __rvm_clean_path() { PATH=$(echo $PATH | tr -s ':' '\n' | awk '!($0 in a){a[$0];print}' | tr -s '\n' ':' | sed 's#:$##') export PATH } # Clean all rvm items out of the current working path. __rvm_remove_rvm_from_path() { PATH=$(echo $PATH | tr -s ':' '\n' | grep -v "\.rvm" | tr -s '\n' ':' | sed 's#:$##') export PATH } # Run a specified command and log it. __rvm_run() { log_file_name="$1" ; command="$2" ; message="$3" if [[ -z "$rvm_ruby_log_path" ]] ; then rvm_ruby_log_path="$rvm_log_path" ; fi if [[ ! -z "$message" ]] ; then $rvm_scripts_path/log "info" "$message" ; fi if [[ ! -z "$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" 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 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' is set (persist gemset unless clear is explicitely called). __rvm_cleanup_variables() { __rvm_unset_ruby_variables if [[ "$rvm_sticky_flag" = "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_ruby_patch rvm_sticky_flagrvm_rvmrc_flag rvm_gems_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_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_alias } __rvm_set_rvmrc() { if [[ "$HOME" != "$(pwd)" ]] ; then if [[ "$rvm_create_flag" -eq 1 ]] ; then flags="--create " ; fi if [[ "$rvm_verbose_flag" -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 echo "rvm $flags $(basename $rvm_ruby_gem_home)" > .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() { 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 } # 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" echo -e "$code" > "$rvm_tmp_path/$$.rb" unset code cat $rvm_ruby_file >> "$rvm_tmp_path/$$.rb" echo -e "\n end \nend\n" >> "$rvm_tmp_path/$$.rb" rvm_ruby_args="$rvm_tmp_path/$$.rb" rvm_benchmark_flag=1 rvm_action="ruby" if [[ ! -z "$rvm_debug_flag" ]] ; then echo -e "$rvm_tmp_path/$$.rb:\n$(cat $rvm_tmp_path/$$.rb)" ; fi $rvm_scripts_path/set $rvm_action $rvm_ruby_args } # Loop over the currently installed rubies and refresh their binscripts. __rvm_bin_scripts() { for rvm_ruby_binary in $rvm_rubies_path/*/bin/ruby ; do if [[ -x "$rvm_ruby_binary" ]] ; then rvm_ruby_string=$(dirname "$rvm_ruby_binary" | xargs dirname | xargs basename) __rvm_select __rvm_bin_script fi done } # 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() { if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select ; fi ruby_wrapper=$(cat < $rvm_bin_path/$rvm_ruby_package_name unset ruby_wrapper chmod +x $rvm_bin_path/$rvm_ruby_package_name } # Load default ruby, if default is not set load system ruby. __rvm_load_defaults() { if [[ ! -s "$rvm_config_path/system" ]] && [[ "root" != "$(whoami)" ]] ; then for variable in RUBY_VERSION GEM_HOME GEM_PATH BUNDLE_PATH MY_RUBY_HOME ; do eval value=\$${variable} if [[ -z "${value/ /}" ]] ; then echo "unset ${variable}" >> $rvm_config_path/system else eval "export $variable" eval value=\$${variable} echo "${variable}='$value' ; export ${variable}" >> $rvm_config_path/system fi done fi __rvm_db "system_ruby" "rvm_system_ruby" if [[ ! -z "$rvm_system_ruby" ]] ; then rvm_system_ruby=$(command -v ruby) if [[ $? -ne 0 ]] ; then $rvm_scripts_path/log "info" "System ruby not found, no system default will be stored." else $rvm_scripts_path/db "$rvm_config_path/user" "system_ruby" "$rvm_system_ruby" # Now store system system & user gem paths if [[ ! -z "$(command -v gem)" ]] ; then __rvm_db "system_user_gem_path" "rvm_system_user_gem_path" if [[ -z "$rvm_system_user_gem_path" ]] ; then rvm_system_user_gem_path=$( rvm system ; gem env gemdir user; ) $rvm_scripts_path/db "$rvm_config_path/user" "system_user_gem_path" "$rvm_system_user_gem_path" fi __rvm_db "system_gem_path" "rvm_system_gem_path" if [[ -z "$rvm_system_gem_path" ]] ; then rvm_system_gem_path=$( rvm system ; gem env gemdir; ) $rvm_scripts_path/db "$rvm_config_path/user" "system_gem_path" "$rvm_system_gem_path" fi fi fi fi } # 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() { PATH="$(echo $PATH | tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)" PATH="$rvm_bin_path:$PATH" ; export PATH for variable in RUBY_VERSION GEM_HOME BUNDLE_PATH MY_RUBY_HOME ; do unset $variable ; done for flag in default passenger editor ; do rm -f "$rvm_bin_path"/${flag}_* ; done for file in system default ; do if [[ -f "$rvm_path/$file" ]] ; then rm -f $rvm_path/$file ; fi if [[ -f "$rvm_config_path/$file" ]] ; then rm -f $rvm_config_path/$file ; fi done rvm_ruby_interpreter="system" __rvm_select 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* } # 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 '/' ?!... NO!" else if [[ -d "$rvm_path" ]] ; then $rvm_scripts_path/log "info" "Hai! Removing $rvm_path" rm -rf $rvm_path/ echo "$rvm_path has been removed." else $rvm_scripts_path/log "info" "It appears that $rvm_path is already non existant." fi fi break elif [[ "no" = "$response" ]] ; then $rvm_scripts_path/log "info" "Cancelling implosion, no harm done :)" break fi done } # 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 } # Query for valid rvm ruby strings # This is meant to be used with scripting. __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() { action="$(echo $rvm_ruby_args | awk '{print $1}')" if [[ "known" = "$action" ]] ; then __rvm_list_known elif [[ "default" = "$action" ]] ; then __rvm_list_default elif [[ -z "$action" ]] || [[ "rubies" = "$action" ]] ; then __rvm_list_rubies elif [[ "strings" = "$action" ]] ; then __rvm_list_strings else # help echo -e "Usage: rvm list {known,default,rubies,strings}" fi } __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\n" fi ; unset version fi fi } __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(-p399)\n(ruby-)1.8.6-head\n(ruby-)1.8.7(-p249)\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\n(ruby-)1.9.2-head\nruby-head\n" echo -e "jruby-1.2.0\njruby-1.3.1\njruby-1.4.0\njruby(-1.5.0) # the default\njruby-head" echo -e "rbx(-prc5) # 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(-23464)\nmaglev-head" echo -e "mput(-head) # shyouhei head, the default mput" echo -e "ironruby-0.9.3\nironruby-1.0-rc2\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=$(command -v ruby) ; 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 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 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 ; command -v ruby)" if [[ ! -z "$system_ruby" ]] && [[ -x "$system_ruby" ]] ; then echo -e "\nSystem Ruby\n" system_version=$($system_ruby -v) binary=$(\ls -l "$system_ruby" | awk '{print $NF}') # Account for symbolic links. string="[ $(file $binary | 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" fi unset current_ruby version selected system_ruby system_version string binary echo } # Initialize rvm, ensuring that the path and directories are as expected. __rvm_initialize() { rvm_ruby_load_path="." rvm_ruby_require="" __rvm_clean_path if echo $PATH | grep -q 'rvm\/bin:' ; then PATH=$rvm_bin_path:$PATH ; export PATH fi mkdir -p $rvm_src_path $rvm_bin_path $rvm_archives_path $rvm_gems_path $rvm_tmp_path } # Update rubygems or binscripts based on CLI selection. __rvm_update() { __rvm_pushpop $rvm_path if [[ "head" = "$rvm_ruby_revision" ]] || [[ ! -z "$rvm_self_flag" ]] || [[ "update" = "$rvm_action" ]] || [[ ! -z "$rvm_update_flag" ]] ; then __rvm_version __rvm_update_rvm fi if [[ ! -z "$rvm_bin_flag" ]] ; then __rvm_bin_scripts ; fi if [[ ! -z "$rvm_rubygems_flag" ]] ; then __rvm_rubygems_setup ; fi unset rvm_update_flag rvm_action rvm_self_flag rvm_ruby_revision rvm_bin_flag rvm_rubygems_flag __rvm_pushpop } # 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 [[ "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 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 __rvm_pushpop rvm_hook="after_update" ; source $rvm_scripts_path/hook } __rvm_reboot() { $rvm_scripts_path/log "warn" "Do you wish to reboot rvm? ('yes', or 'no')" read response if [[ "yes" = "$response" ]] ; then builtin cd $rvm_path __rvm_reset mv $rvm_path/archives ~/.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 else $rvm_scripts_path/log "info" "Carry on then..." fi ; unset response } # Create the irbrc for the currently selected ruby installation. __rvm_irbrc() { if [[ -d "$rvm_ruby_home" ]] && [[ ! -s "$rvm_ruby_irbrc" ]] ; then cp $rvm_scripts_path/irbrc $rvm_ruby_irbrc fi } # 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 } # 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() { if [[ -z "$rvm_state" ]] ; then if [[ -z "$(command -v ruby | awk /$(basename $rvm_rubies_path)/)" ]] ; then rvm_state=system else rvm_state="$(dirname "$(command -v ruby)" | xargs dirname | xargs basename)" fi else rvm_ruby_string="$rvm_state" __rvm_select __rvm_use unset rvm_state fi } # Output an inspection of selected 'binary' scripts, based on CLI selection. __rvm_inspect() { for binary in $rvm_ruby_args ; do actual_file="$(command -v $binary)" $rvm_scripts_path/log "info" "$actual_file:" if [[ ! -z "$rvm_shebang_flag" ]] ; then cat $actual_file | head -n 1 ; fi if [[ ! -z "$rvm_env_flag" ]] ; then cat $actual_file | awk '/ENV/' ; fi if [[ ! -z "$rvm_path_flag" ]] ; then cat $actual_file | awk '/PATH/' ; fi if [[ ! -z "$rvm_head_flag" ]] ; then cat $actual_file | head -n 5 ; fi if [[ ! -z "$rvm_tail_flag" ]] ; then cat $actual_file | tail -n 5 ; fi if [[ ! -z "$rvm_all_flag" ]] ; then cat $actual_file ; fi done } # 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() { # This is only an issue with Darwin :/ if [[ "Darwin" = "$(uname)" ]] ; then # \ls /usr/lib/gcc/x86_64-apple-darwin10 # Set the build & host type if [[ "Power Macintosh" = "$(sysctl hw.machine | awk -F: '{print $2}' | sed 's/^ //')" ]] ; then : # Do nothing ? elif [[ $(sysctl hw.cpu64bit_capable | awk '{print $2}') = 1 ]] ; then # we could also use: sysctl hw.optional.x86_64 # 64 bit capable if [[ "-arch x86_64" = "$rvm_archflags" ]] ; then rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=x86_64-apple-darwin$(uname -r) --host=x86_64-apple-darwin$(uname -r)" elif [[ "-arch i386" = "$rvm_archflags" ]] ; then rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=i386-apple-darwin$(uname -r) --host=i386-apple-darwin$(uname -r)" else rvm_archflags="-arch x86_64" rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=x86_64-apple-darwin$(uname -r) --host=x86_64-apple-darwin$(uname -r)" fi else # 32 bit capable only if [[ -z "$rvm_archflags" ]] ; then rvm_archflags="-arch i386" ; fi rvm_ruby_configure_flags="${rvm_ruby_configure_flags} --build=i386-apple-darwin$(uname -r) --host=i386-apple-darwin$(uname -r)" fi if [[ ! -z "$rvm_archflags" ]] ; then ARCHFLAGS="$rvm_archflags" ; export ARCHFLAGS # Use the latest sdk available. if [[ -z "$rvm_sdk" ]] ; then rvm_sdk="$(/usr/bin/basename -a /Developer/SDKs/* | awk '/^M/' | sort | tail -n 1)" ; fi 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 } # Select a gemset based on CLI set options and environment. # This only sets 'rvm_ruby_gem_home' __rvm_gemset_select() { command -v gem > /dev/null if [[ $? -gt 0 ]] ; then return 0 ; fi # Stop if no 'gem' command is available. rvm_ruby_global_gems_path="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}global" #if [[ -z "$(echo $rvm_ruby_gem_home | grep "$rvm_path")" ]] ; then # $rvm_scripts_path/log "warn" "Gemsets cannot be used with system ruby installs (yet)." #fi if [[ -z "$rvm_gemset_name" ]] ; then # No longer defaulting to 'sticky' gem sets. # Set 'rvm_sticky_flag=1' in ~/.rvmrc to enable. if [[ ! -z "$rvm_sticky_flag" ]] ; then if [[ ! -z "$GEM_HOME" ]] ; then rvm_gemset_name=$(echo $GEM_HOME | xargs basename | awk -F${rvm_gemset_separator} '{print $2}') fi if [[ ! -z "$rvm_ruby_gem_home" ]] ; then rvm_gemset_name=$(echo $rvm_ruby_gem_home | xargs basename | awk -F${rvm_gemset_separator} '{print $2}') fi fi if [[ ! -z "$rvm_gemset_name" ]] && ! $rvm_scripts_path/match "$rvm_gemset_name" "^[0-9]\.[0-9]" ; then rvm_ruby_gem_home="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}${rvm_gemset_name}" else 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 "$(command -v gem)" ]] ; then rvm_ruby_gem_home=$(gem env gemdir) elif [[ ! -z "$GEM_HOME" ]] ; then rvm_ruby_gem_home="$GEM_HOME" else unset rvm_ruby_gem_home fi fi if [[ -z "$rvm_gemset_name" ]] ; then unset rvm_gemset_name ; fi else gemset=$(echo "$rvm_ruby_gem_home" | awk -F'@' '{print $NF}') if [[ -z "$rvm_ruby_string" ]] && [[ ! -z "${GEM_HOME/@*/}" ]] ; then rvm_ruby_string=$(basename ${GEM_HOME/@*/}) fi if [[ ! -z "$rvm_ruby_string" ]] ; then if [[ -z "$rvm_ruby_gem_home" ]] || [[ ! -z "$gemset" ]] ; then rvm_ruby_gem_home="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}${rvm_gemset_name}" elif [[ ! -z "$gemset" ]] && [[ "$rvm_gemset_name" != "$gemset" ]] ; then rvm_ruby_gem_home="$rvm_gems_path/${rvm_ruby_string}${rvm_gemset_separator}${rvm_gemset_name}" fi ; unset gemset else $rvm_scripts_path/log "error" "Gemsets can not be used with non rvm controlled rubies (currently)." return 1 fi fi # If the gemset does not exist, then notify the user as such and abort the action. if [[ ! -z "$rvm_gemset_name" ]] && [[ ! -d "$rvm_ruby_gem_home" ]] ; then if [[ "$rvm_gemset_create_on_use_flag" -ne 1 ]] && [[ "$rvm_create_flag" -ne 1 ]] && [[ "$rvm_delete_flag" -ne 1 ]] ; then $rvm_scripts_path/log "error" "Gemset '$rvm_gemset_name' does not exist, rvm gemset create '$rvm_gemset_name' first." return 1 fi elif [[ "$rvm_delete_flag" -eq 1 ]] ; then return 1 fi if [[ -z "$rvm_ruby_gem_home" ]] && [[ ! -z $rvm_ruby_string ]] ; then rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string" rvm_ruby_global_gems_path="$rvm_gems_path/$rvm_ruby_string${rvm_gemset_separator}global" fi rvm_ruby_gem_path="$rvm_ruby_gem_home:$rvm_ruby_global_gems_path" # Careful not to nuke system gems cache. if [[ ! -z "$rvm_ruby_gem_home" ]] && [[ ! -z "$(echo $rvm_ruby_gem_home | awk '/rvm/')" ]] ; then # Ensure that the ruby gem home exists. mkdir -p "$rvm_ruby_gem_home" # If there is a cache *directory* already, # move all the gems to the global cache directory and remove it. if [[ -d "$rvm_ruby_gem_home/cache" ]] && [[ ! -L "$rvm_ruby_gem_home/cache" ]] ; then if [[ ! -z "$(\ls -A "$rvm_ruby_gem_home"/cache/)" ]] ; then mv "$rvm_ruby_gem_home"/cache/* "$HOME"/.gem/cache/ fi rmdir "$rvm_ruby_gem_home"/cache fi # If the ruby's gems cache directory is not a symlink to the global cache, symlink it if [[ ! -L "$rvm_ruby_gem_home/cache" ]] ; then ln -nfs "$HOME/.gem/cache" "$rvm_ruby_gem_home/cache" fi fi ; export rvm_ruby_gem_path rvm_ruby_gem_home } # Use a gemset specified by 'rvm_ruby_gem_home' __rvm_gemset_use() { #if [[ -z "$(echo $rvm_ruby_gem_home | grep "rvm")" ]] ; then # $rvm_scripts_path/log "warn" "Gemsets cannot be used with system ruby installs (yet)." #fi if [[ ! -z "$rvm_ruby_gem_home" ]] ; then if [[ ! -d "$rvm_ruby_gem_home" ]] ; then if [[ "$rvm_gemset_create_on_use_flag" -eq 1 ]] || [[ "$rvm_create_flag" -eq 1 ]]; then $rvm_scripts_path/gemsets create $rvm_gemset_name else $rvm_scripts_path/log "error" "Gemset '$rvm_gemset_name' does not exist, rvm gemset create '$rvm_gemset_name' first." return 1 fi fi if [[ "$rvm_interactive" -eq 1 ]] || [[ "$rvm_verbose_flag" -eq 1 ]] ; then $rvm_scripts_path/log "info" "Now using gemset '${rvm_gemset_name:-default}'" fi rvm_ruby_gem_home="$(echo $GEM_HOME | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}${rvm_gemset_name}" GEM_HOME="$rvm_ruby_gem_home" BUNDLE_PATH="$rvm_ruby_gem_home" GEM_PATH="$rvm_ruby_gem_home/bin:$(echo $GEM_HOME | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}global/bin" export rvm_ruby_gem_home GEM_HOME BUNDLE_PATH GEM_PATH __rvm_use # Now ensure the selection takes effect for the environment. fi return 0 } __rvm_gemset_clear() { unset rvm_gemset_name ; shift rvm_ruby_gem_home="$(echo $GEM_HOME | sed "s#${rvm_gemset_separator:-'@'}.*\$##g")" rvm_ruby_global_gems_path="$(echo $GEM_HOME | sed 's/'${rvm_gemset_separator}'.*$//')${rvm_gemset_separator}global" GEM_HOME=$rvm_ruby_gem_home BUNDLE_PATH="$rvm_ruby_gem_home" GEM_PATH="$rvm_ruby_gem_home/bin:$rvm_ruby_global_gems_path/bin" export rvm_ruby_gem_home rvm_ruby_global_gems_path GEM_HOME BUNDLE_PATH GEM_PATH __rvm_use # Now ensure the selection takes effect for the environment. } __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" } __rvm_Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything() { for index in {1..750} ; do perl -e 'sleep 0.2'; echo -n '.' ; done ; printf "%d" 0x2A ; echo } __rvm_ultimate_question() { echo "I do not know the Ultimate Question, " echo "however I can help you build a more " echo "powerful Ruby which can compute the " echo "Ultimate Question." }