scripts/utility in rvm-0.0.61 vs scripts/utility in rvm-0.0.62

- old
+ new

@@ -35,32 +35,32 @@ function __rvm_debug { __rvm_log "debug" "\nPATH:\n$(echo $PATH | awk -F":" '{print $1":"$2":"$3":"$4":"$5}')" for file_name in ~/.bash_profile ~/.bashrc ~/.zshrc ; do - if [ -s $file_name ] ; then + if [[ -s "$file_name" ]] ; then __rvm_log "debug" "\n$file_name:\n$(grep 'rvm' $file_name)" fi done for file_name in $rvm_path/default $rvm_path/system $rvm_path/config/db ~/.rvmrc ~/.gemrc; do - if [ -f $file_name -a -s $file_name ] ; then + if [[ -f "$file_name" ]] && [[ -s "$file_name" ]] ; then __rvm_log "debug" "$file_name (filtered):\n$(cat $file_name | awk '!/assword|_key/')\n" fi done __rvm_log "debug" "gem sources:\n$(gem sources | awk '/gems/')" - if [ -f $rvm_path/bin/rvm ] ; then + if [[ -f "$rvm_path/bin/rvm" ]] ; then __rvm_log "error" "rvm script in bin! \n$(ls -laht $rvm_path/bin/rvm)" fi } # Logging functions based on level # TODO: Allow specification of a base file name to output to. function __rvm_log { - if [ ! -z "$2" ] ; then level=$1 ; shift ; else level="info" ; fi + if [[ ! -z "$2" ]] ; then level=$1 ; shift ; else level="info" ; fi message=$1 case "$level" in debug) shift ; ((rvm_debug_flag)) && echo -e "$(tput setaf 5)<d>$(tput sgr0) $message $(tput setaf 5)</d> $(tput sgr0) " ;; @@ -70,11 +70,11 @@ fail) shift ; echo -e "$(tput setaf 1)<f>$(tput sgr0) $message $(tput setaf 1)</f> $(tput sgr0) " ; __rvm_pushpop ; return 1 ;; *) echo -e "$message" esac } -if [ ! -z "$ZSH_VERSION" ] ; then __shell_array_start=1 ; else __shell_array_start=0 ; fi +if [[ ! -z "$ZSH_VERSION" ]] ; then __shell_array_start=1 ; else __shell_array_start=0 ; fi __rvm_push() { array=$1 ; shift ; item=$2 # TODO: allow loop over more arguments. eval "index=\$((\${#${array}[*]} + $__shell_array_start))" eval "${array}[${index}]=${item}" @@ -96,20 +96,20 @@ function __rvm_run { log_file_name="$1" ; command="$2" ; message="$3" rvm_ruby_log_path="${rvm_ruby_log_path:-$rvm_path/log}" mkdir -p $(dirname "$rvm_ruby_log_path/$log_file_name.log") - if [ ! -z "$message" ] ; then __rvm_log "info" "$message" ; fi + if [[ ! -z "$message" ]] ; then __rvm_log "info" "$message" ; fi __rvm_log "debug" "Executing: $command" 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" -o "0" = "$rvm_niceness" ] ; then + 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_log "error" "Error running '$command', please check $rvm_ruby_log_path/$log_file_name.error.log" ; __rvm_pushpop ; return 1 ; fi + if [[ $? -gt 0 ]] ; then __rvm_log "error" "Error running '$command', please check $rvm_ruby_log_path/$log_file_name.error.log" ; __rvm_pushpop ; return 1 ; fi unset log_file command } function __rvm_cleanup_variables { __rvm_unset_ruby_variables @@ -120,25 +120,25 @@ unset rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_configure 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 } # TODO: root user loadng of /etc/rvmrc function __rvm_load_rvmrc { - if [ -s ~/.rvmrc ] ; then source ~/.rvmrc ; fi + if [[ -s ~/.rvmrc ]] ; then source ~/.rvmrc ; fi } function __rvm_bin_scripts { for rvm_ruby_binary in $(/bin/ls $rvm_path/*/bin/ruby 2> /dev/null) ; do - if [ -x $rvm_ruby_binary ] ; then - rvm_ruby_string=$(dirname $rvm_ruby_binary | xargs dirname | xargs basename) + if [[ -x "$rvm_ruby_binary" ]] ; then + rvm_ruby_string=$(dirname "$rvm_ruby_binary" | xargs dirname | xargs basename) __rvm_select __rvm_bin_script fi done } function __rvm_bin_script { - if [ -z "$rvm_ruby_selected_flag" ] ; then __rvm_select $* ; fi + if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select $* ; fi ruby_wrapper=$(cat <<RubyWrapper #!/bin/bash GEM_HOME=$rvm_ruby_gem_home ; export GEM_HOME GEM_PATH=$rvm_ruby_gem_home ; export GEM_PATH @@ -154,16 +154,17 @@ chmod +x $rvm_path/bin/$rvm_ruby_package_name } function __rvm_fetch { __rvm_pushpop $rvm_archives_path - archive=$(basename "$1") + if [[ -z "$1" ]] ; then log "fail" "BUG: __rvm_fetch called without an argument :/" ; return 1 ; fi + archive=$(basename "$1") ; downlaod=1 __rvm_log "debug" "Fetching $archive" # Check first if we have the correct archive - if [ -e "$archive" ] && [ -e "$archive.md5" ] ; then + if [[ -e "$archive" ]] && [[ -e "$archive.md5" ]] ; then __rvm_log "debug" "Found archive and its md5, testing correctness" - if [ $(md5sum --status -c "$archive.md5") -gt 0 ] ; then + if [[ $(md5sum --status -c "$archive.md5") -gt 0 ]] ; then __rvm_log "debug" "Archive is bad, downloading" download=1 else __rvm_log "debug" "Archive is good, not downloading" download=0 @@ -171,34 +172,33 @@ fi else __rvm_log "debug" "No archive or no MD5, downloading" download=1 fi - - if [ $download -gt 0 ] ; then + if [[ $download -gt 0 ]] ; then eval $rvm_fetch "$1" result=$? - if [ $result -gt 0 ] ; then - unset retry - if [ $result -eq 78 ] ; then + if [[ $result -gt 0 ]] ; then + retry=0 + if [[ $result -eq 78 ]] ; then __rvm_log "error" "The requested url does not exist: '$1'" - elif [ $result -eq 18 ] ; then + elif [[ $result -eq 18 ]] ; then __rvm_log "error" "Partial file. Only a part of the file was transferred. Removing partial and re-trying." rm -f "$archive" retry=1 - elif [ $result -eq 33 ] ; then + elif [[ $result -eq 33 ]] ; then __rvm_log "debug" "Server does not support 'range' command, removing '$archive'" rm -f "$archive" retry=1 else __rvm_log "error" "There was an error, please check $rvm_ruby_log_path/*.error.log" fi - if [ $retry -eq 1 ] ; then + if [[ $retry -eq 1 ]] ; then eval $rvm_fetch "$1" result=$? - if [ $result -gt 0 ] ; then + if [[ $result -gt 0 ]] ; then __rvm_log "error" "There was an error, please check $rvm_ruby_log_path/*.error.log" fi fi fi @@ -209,39 +209,39 @@ unset download return $result } function __rvm_load_defaults { - if [ ! -s $rvm_path/system ] ; then + if [[ ! -s "$rvm_path/system" ]] ; then for variable in RUBY_VERSION GEM_HOME GEM_PATH MY_RUBY_HOME ; do eval value=\$${variable} - if [ -z "$value" ] ; then + if [[ -z "$value" ]] ; then echo "unset ${variable}" >> $rvm_path/system else eval "export $variable" eval value=\$${variable} echo "${variable}='$value' ; export ${variable}" >> $rvm_path/system fi done fi rvm_system_ruby=$(__rvm_db "system_ruby") - if [ ! -z "$rvm_system_ruby" ] ; then + if [[ ! -z "$rvm_system_ruby" ]] ; then rvm_system_ruby=$(which ruby) - if [ $? -ne 0 ] ; then + if [[ $? -ne 0 ]] ; then __rvm_log "info" "System ruby not found, no db will be stored." else __rvm_db "system_ruby" "$rvm_system_ruby" # Now store system system & user gem paths rvm_system_user_gem_path=$(__rvm_db "system_user_gem_path") - if [ -z "$rvm_system_user_gem_path" ] ; then + if [[ -z "$rvm_system_user_gem_path" ]] ; then rvm_system_user_gem_path=$( rvm system ; gem env gemdir user; ) __rvm_db "system_user_gem_path" "$rvm_system_user_gem_path" fi rvm_system_gem_path=$(__rvm_db "system_gem_path") - if [ -z "$rvm_system_gem_path" ] ; then + if [[ -z "$rvm_system_gem_path" ]] ; then rvm_system_gem_path=$( rvm system ; gem env gemdir; ) __rvm_db "system_gem_path" "$rvm_system_gem_path" fi fi fi @@ -252,11 +252,11 @@ PATH=$rvm_bin_path:$PATH ; export PATH for variable in RUBY_VERSION GEM_HOME MY_RUBY_HOME ; do unset $variable ; done for file in system default ; do - if [ -f $rvm_path/$file ] ; then rm -f $rvm_path/$file ; fi + if [[ -f "$rvm_path/$file" ]] ; then rm -f $rvm_path/$file ; fi done rvm_ruby_interpreter="system" __rvm_select for system_config in system_ruby system_gem_path system_user_gem_path ; do @@ -268,70 +268,70 @@ function __rvm_implode { while : ; do __rvm_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 + if [[ "yes" = "$response" ]] ; then + if [[ "/" = "$rvm_path" ]] ; then __rvm_log "error" "remove '/' ?!... NO!" else - if [ -d $rvm_path ] ; then + if [[ -d "$rvm_path" ]] ; then __rvm_log "info" "Hai! Removing $rvm_path" rm -rf $rvm_path/ __rvm_log "info" "$rvm_path has been removed." else __rvm_log "info" "It appears that $rvm_path is already non existant." fi fi break - elif [ "no" = "$response" ] ; then + elif [[ "no" = "$response" ]] ; then __rvm_log "info" "Cancelling implosion, no harm done :)" break fi done } function __rvm_gemdir { - if [ -z "$rvm_ruby_selected_flag" ] ; then __rvm_select $* ; fi + if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select $* ; fi mkdir -p $rvm_ruby_gem_home echo $rvm_ruby_gem_home } function __rvm_source_dir { - if [ -z "$rvm_ruby_selected_flag" ] ; then __rvm_select $* ; fi - if [ -z "$rvm_ruby_src_path" ] ; then + if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select $* ; fi + if [[ -z "$rvm_ruby_src_path" ]] ; then __rvm_log "fail" "No source directory exists for the default implementation." else echo "$rvm_ruby_src_path" fi } # clones from source implementation/version to default # TODO: Merge this into 'rvm sync' function __rvm_gemdup { - if [ -z "$rvm_ruby_selected_flag" ] ; then __rvm_select $* ; fi + if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select $* ; fi __rvm_log "debug" "$rvm_ruby_interpreter" - if [ "default" = "$rvm_ruby_interpreter" ] ; then + if [[ "default" = "$rvm_ruby_interpreter" ]] ; then # TODO: ~/.rvm/default first, then system user rvm_source_gem_path="$rvm_system_user_gem_path" - elif [ "user" = "$rvm_ruby_interpreter" ] ; then + elif [[ "user" = "$rvm_ruby_interpreter" ]] ; then rvm_source_gem_path="$rvm_system_user_gem_path" - elif [ "system" = "$rvm_ruby_interpreter" ] ; then + elif [[ "system" = "$rvm_ruby_interpreter" ]] ; then rvm_source_gem_path="$rvm_system_gem_path" else # TODO: use selector for this? rvm_source_gem_path=${rvm_ruby_gem_home/$rvm_ruby_interpreter/$rvm_ruby_version} fi __rvm_gem_sync } function __rvm_gem_sync { - if [ ! -z "$rvm_source_gem_path" ] ; then + if [[ ! -z "$rvm_source_gem_path" ]] ; then for rvm_gem_name_version in $rvm_source_gem_path/gems/* ; do rvm_gem_name="${rvm_gem_name_version%-*}" rvm_gem_version="${rvm_gem_name_version##*-}" - if [ -d $GEM_HOME/gems/$rvm_gem_name_version ] ; then + if [[ -d $GEM_HOME/gems/$rvm_gem_name_version ]] ; then echo "$rvm_gem_name_version already installed." else __rvm_gi "$rvm_source_gem_path/cache/$rvm_gem_name-$rvm_gem_version.gem" fi done @@ -345,38 +345,38 @@ function __rvm_db { rvm_hash_file="$rvm_config_path/db" touch $rvm_hash_file key="$1" ; shift - if [ -z "$key" ] ; then + if [[ -z "$key" ]] ; then __rvm_log "fail" "__rvm_db must be called with at least one argument: __rvm_db key [value]" else value="$*" - if [ "unset" = "$value" -o "delete" = "$value" ] ; then - sed -i.tmp "s#^$key=.*$\##" $rvm_hash_file + if [[ "unset" = "$value" ]] || [[ "delete" = "$value" ]] ; then + sed -i.tmp "s#^$key=.*\$##" $rvm_hash_file else - if [ -z "$value" ] ; then # get - grep "^$key=" $rvm_hash_file | head -n 1 | awk -F'=' '{print $2}' + if [[ -z "$value" ]] ; then # get + awk -F= '/^'"$key"'=/{print $2}' $rvm_hash_file else # set - if [ -z "$(grep "^$key=" $rvm_hash_file)" ] ; then # append + if [[ -z "$(awk -F= "/^'"$key"'=/{print $2}" $rvm_hash_file)" ]] ; then # append echo "$key=$value" >> $rvm_hash_file else # overwrite - sed -i.tmp "s#^$key=.*$\#$key=$value#" $rvm_hash_file + sed -i.tmp "s#^$key=.*\$#$key=$value#" $rvm_hash_file fi fi fi fi } function __rvm_list { - if [ "$rvm_all_flag" ] ; then + if [[ ! -z "$rvm_all_flag" ]] ; then svn list http://svn.ruby-lang.org/repos/ruby/tags/ | grep 'v1_[8|9]' | sed 's#^v1_##' | sed 's#/$##' | awk -F'_' '{print "1."$1"."$2 " -l "$3}' | sed 's#p$##' echo -e "jruby 1.2.0\njruby 1.3.0\njruby (1.3.1, the default)\njruby 1.4.1\njruby --head" echo -e "rbx head (rubinius head, the default)\nrbx head --jit" echo -e "ree 1.8.6 --head\nree (1.8.7, the default)" else - current_ruby=$(which ruby | xargs dirname | xargs dirname | xargs basename 2> /dev/null) + current_ruby="$(which ruby | xargs dirname | xargs dirname | xargs basename 2> /dev/null)" echo -e "\nruby:\n" for version in $(/bin/ls -l $rvm_path/ 2> /dev/null | awk '/ ruby-[1-2].*/ { print $NF }') ; do string=$($rvm_path/$version/bin/ruby -v) if [[ "$version" = "$current_ruby" ]] ; then echo -e "=> $version : $string" @@ -406,13 +406,13 @@ else echo -e " $version : $string" fi done ; unset version - if [ -f $rvm_path/default -a -s $rvm_path/default ] ; then + if [[ -f "$rvm_path/default" ]] && [[ -s $rvm_path/default ]] ; then version=$(grep '^MY_RUBY_HOME' ~/.rvm/default | awk -F"'" '{print $2}' | xargs basename) - if [ ! -z "$version" ] ; then + if [[ ! -z "$version" ]] ; then echo -e "\ndefault:\n" string=$($rvm_path/$version/bin/ruby -v) if [[ "$version" = "$current_ruby" ]] ; then echo -e "=> $version : $string" selected="1" @@ -422,11 +422,11 @@ fi ; unset version fi echo -e "\nsystem:\n" system_version=$(rvm system ; ruby -v 2> /dev/null) - if [ ! -z "$system_version" ] ; then + if [[ ! -z "$system_version" ]] ; then if [[ "$($(which ruby) -v)" = "$system_version" ]] ; then echo -e "=> $system_version\n" else echo -e " $system_version\n" fi @@ -434,24 +434,24 @@ fi } function __rvm_initialize { rvm_fetch=$(which curl) - if [ $? -ne 0 ] ; then + if [[ $? -ne 0 ]] ; then __rvm_log "fail" "rvm requires curl, which does not seem to exist in your path :(" else rvm_fetch="$rvm_fetch -O -L --create-dirs -C - " # -s for silent fi # TODO: Sanitize user input, ensure that there is a / a the end... - if [ "root" = "$(whoami)" ] ; then + if [[ "root" = "$(whoami)" ]] ; then __rvm_log "fail" "root user support is not yet implemented." rvm_prefix_path="${rvm_prefix_path:-/usr/local/}" else rvm_prefix_path="${rvm_prefix_path:-"$HOME/."}" fi - if [ "${rvm_prefix_path#${rvm_prefix_path%?}}" = '.' -o "${rvm_prefix_path#${rvm_prefix_path%?}}" = '/' ] ; then + if [[ "${rvm_prefix_path#${rvm_prefix_path%?}}" = '.' ]] || [[ "${rvm_prefix_path#${rvm_prefix_path%?}}" = '/' ]] ; then rvm_path="${rvm_prefix_path}rvm" else rvm_path="${rvm_prefix_path}/rvm" fi rvm_archives_path="${rvm_archives_path:-"$rvm_path/archives"}" @@ -469,33 +469,32 @@ rvm_ruby_load_path="." rvm_ruby_require="" __rvm_clean_path rvm_result=$(echo $PATH | grep 'rvm\/bin:') - if [ -z $rvm_result ] ; then + if [[ -z "$rvm_result" ]] ; then PATH=$rvm_bin_path:$PATH ; export PATH fi mkdir -p $rvm_src_path $rvm_bin_path $rvm_archives_path $rvm_gem_path $rvm_temp_path } function __rvm_update { - if [ "head" = "$rvm_ruby_revision" -o ! -z "$rvm_self_flag" -o "update" = "$rvm_action" -o ! -z "$rvm_update_flag" ] ; then + if [[ "head" = "$rvm_ruby_revision" ]] || [[ ! -z "$rvm_self_flag" ]] || [[ "update" = "$rvm_action" ]] || [[ ! -z "$rvm_update_flag" ]] ; then __rvm_version __rvm_update_rvm __rvm_version fi __rvm_reload - # if [ "$rvm_gem_flag" ] ; then __rvm_gem_scripts ; fi - if [ "$rvm_bin_flag" ] ; then __rvm_bin_scripts ; fi - if [ "$rvm_rubygems_flag" ] ; then __rvm_rubygems_setup ; fi + if [[ ! -z "$rvm_bin_flag" ]] ; then __rvm_bin_scripts ; fi + if [[ ! -z "$rvm_rubygems_flag" ]] ; then __rvm_rubygems_setup ; fi } function __rvm_update_rvm { mkdir -p $rvm_src_path - if [ "head" = "$rvm_ruby_revision" ] ; then - if [ -d $rvm_src_path/rvm/.git ] ; then + if [[ "head" = "$rvm_ruby_revision" ]] ; then + if [[ -d "$rvm_src_path/rvm/.git" ]] ; then cd $rvm_src_path/rvm/ && git pull origin master && ./scripts/install else cd $rvm_src_path && git clone git://github.com/wayneeseguin/rvm.git && cd rvm/ && ./install fi else @@ -503,74 +502,68 @@ GEM_HOME="${GEM_HOME:-$(gem env gemdir user)}" gem install rvm --no-rdoc --no-ri -q && $GEM_HOME/bin/rvm-install && source ~/.rvm/scripts/rvm fi } -function __rvm_reboot { +__rvm_reboot() { __rvm_log "warn" "Do you wish to reset rvm? ('yes', or 'no')" read response - if [ "yes" = "$response" ] ; then + if [[ "yes" = "$response" ]] ; then cd __rvm_reset mv ~/.rvm/archives ~/.archives - if [ "/" = "$rvm_path" ] ; then + if [[ "/" = "$rvm_path" ]] ; then __rvm_log "error" "remove '/' ?!... NO!" else - if [ -d $rvm_path ] ; then - rm -rf $rvm_path/ - fi + if [[ -d "$rvm_path" ]] ; then rm -rf "$rvm_path/" ; fi fi gem install rvm --no-rdoc --no-ri -q which rvm-install 2> /dev/null - if [ $? -gt 0 ] ; then - if [ -e ~/.gem/ruby/1.8/bin/rvm-install ] ; then + if [[ $? -gt 0 ]] ; then + if [[ -x "~/.gem/ruby/1.8/bin/rvm-install" ]] ; then ~/.gem/ruby/1.8/bin/rvm-install else - __rvm_log "error" "Could not find rvm-install in your path :(" + __rvm_log "error" "Could not find an executable rvm-install in your path :(" fi else rvm-install fi source ~/.rvm/scripts/rvm else __rvm_log "info" "Carry on then..." fi ; unset response } -__rvm_reload() { - source $rvm_path/scripts/rvm -} - __rvm_ruby_do() { __rvm_select __rvm_use binary="$(echo $rvm_action | sed 's#do$##')" - if [ -x $rvm_ruby_home/bin/$binary ] ; then + if [[ -x "$rvm_ruby_home/bin/$binary" ]] ; then load_path="$rvm_ruby_home/bin:$rvm_ruby_load_path" - if [ "ruby" = "$binary" ] ; then - if [ -z "$(echo $rvm_ruby_args | awk '/\.rb$/')" ] ; then + if [[ "ruby" = "$binary" ]] ; then + if [[ -z "$(echo $rvm_ruby_args | awk '/\.rb$/')" ]] ; then #if [[ $rvm_ruby_args =~ '\.rb$' ]] ; then - if [ -z "$prefix" ] ; then prefix="-S" ; fi + if [[ -z "$prefix" ]] ; then prefix="-S" ; fi if [[ ! -z "$rvm_ruby_args" ]] && [[ ! "$rvm_ruby_args" =~ "$prefix" ]] ; then rvm_ruby_args="$prefix $rvm_ruby_args" fi fi rvm_command="$rvm_ruby_home/bin/$binary $rvm_ruby_require -I$load_path $rvm_ruby_args" else rvm_command="$rvm_ruby_home/bin/$binary $rvm_ruby_args" fi - if [ ! -z "$rvm_json_flag" -o ! -z "$rvm_yaml_flag" -o ! -z "$rvm_summary_flag" ] ; then + if [[ ! -z "$rvm_json_flag" ]] || [[ ! -z "$rvm_yaml_flag" ]] || [[ ! -z "$rvm_summary_flag" ]] ; then mkdir -p ./log/$rvm_ruby_string/ touch ./log/$rvm_ruby_string/$rvm_action.log ./log/$rvm_ruby_string/$rvm_action.error.log eval "$rvm_command" >> ./log/$rvm_ruby_string/$rvm_action.log 2>> ./log/$rvm_ruby_string/$rvm_action.error.log else echo -e "\n\n\033[0;32m$rvm_ruby_string: $($rvm_ruby_home/bin/$binary -v | tr "\n" ' ')\033[0m\n" eval "$rvm_command" fi result=$? - if [ $result -eq 0 ]; then + if [[ $result -eq 0 ]]; then eval "successes=(${successes[*]} $rvm_ruby_string)" else eval "errors=(${errors[*]} $rvm_ruby_string)" fi eval "rubies=(${rubies[*]} $rvm_ruby_string)" @@ -579,55 +572,55 @@ __rvm_log "warn" "'$rvm_ruby_home/bin/$binary' either does not exist or is not executable? :(" fi __rvm_unset_ruby_variables } -function __rvm_do { +__rvm_do() { __rvm_state rubies=() ; successes=() ; errors=() ; statuses=() # TODO: Extract the common functionality out of the if below - if [ ! -z "$rvm_ruby_string" ] ; then + if [[ ! -z "$rvm_ruby_string" ]] ; then unset rvm_ruby_interpreter rvm_ruby_version __rvm_ruby_do - elif [ ! -z "$rvm_ruby_version" ] ;then + elif [[ ! -z "$rvm_ruby_version" ]] ;then for rvm_ruby_string in $(echo $rvm_ruby_version | tr ',' ' ') ; do __rvm_ruby_do done - elif [ ! -z "$rvm_ruby_interpreter" ] ; then + elif [[ ! -z "$rvm_ruby_interpreter" ]] ; then unset rvm_ruby_string rvm_ruby_version __rvm_ruby_do else # all while read bin_line do # Keep this on second line damnit! - if [ -x $bin_line ] ; then + if [[ -x "$bin_line" ]] ; then rvm_ruby_string="$(dirname $bin_line | xargs dirname | xargs basename)" __rvm_ruby_do fi done < <(/bin/ls $rvm_path/*/bin/ruby 2> /dev/null) fi - if [ ! -z "$rvm_summary_flag" ] ; then __rvm_summary ; fi - if [ ! -z "$rvm_yaml_flag" ] ; then __rvm_yaml ; fi - if [ ! -z "$rvm_json_flag" ] ; then __rvm_json ; fi + if [[ ! -z "$rvm_summary_flag" ]] ; then __rvm_summary ; fi + if [[ ! -z "$rvm_yaml_flag" ]] ; then __rvm_yaml ; fi + if [[ ! -z "$rvm_json_flag" ]] ; then __rvm_json ; fi __rvm_state return ${#errors[*]} } function __rvm_summary { export successes errors statuses summary="\nSummary:\n\n" - if [ ${#successes[*]} -gt 0 ] ; then + if [[ ${#successes[*]} -gt 0 ]] ; then summary="$summary \033[0;32m${#successes[*]} successful: $(echo "${successes[*]}" | sed 's# #, #g')\033[0m\n" fi - if [ ${#errors[*]} -gt 0 ] ; then + if [[ ${#errors[*]} -gt 0 ]] ; then summary="$summary \033[0;31m${#errors[*]} errors: $(echo "${errors[*]}" | sed 's# #, #g')\033[0m\n" fi total=${#rubies[*]} - if [ ! -z "$ZSH_VERSION" ] ; then array_start=1 ; else array_start=0 ; fi + if [[ ! -z "$ZSH_VERSION" ]] ; then array_start=1 ; else array_start=0 ; fi echo -e "$summary" | tee -a log/summary.log return ${#errors[*]} } function __rvm_yaml { @@ -636,11 +629,11 @@ for var in ${successes[*]} ; do yaml="$yaml\n - $var" ; done yaml="$yaml\nerrors:" for var in ${errors[*]} ; do yaml="$yaml\n - $var" ; done yaml="$yaml\nrubies:" total=${#rubies[*]} - if [ ! -z "$ZSH_VERSION" ] ; then array_start=1 ; else array_start=0 ; fi + if [[ ! -z "$ZSH_VERSION" ]] ; then array_start=1 ; else array_start=0 ; fi for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do __rvm_log "debug" "${rubies[$index]}: ${statuses[$index]}" yaml="$yaml\n \"${rubies[$index]}\": ${statuses[$index]}" done ; unset index array_start mkdir -p log @@ -655,11 +648,11 @@ json="$json\n \"successful\": [ "$(echo ${successes[*]} | sed 's# #", "#g')" ]," json="$json\n \"errors\": [ "$(echo ${errors[*]} | sed 's# #", "#g')" ]," json="$json\n \"rubies\": {" total=${#rubies[*]} - if [ ! -z "$ZSH_VERSION" ] ; then array_start=1 ; else array_start=0 ; fi + if [[ ! -z "$ZSH_VERSION" ]] ; then array_start=1 ; else array_start=0 ; fi for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do __rvm_log "debug" "${rubies[$index]}: ${statuses[$index]}" json="$json\n {\"${rubies[$index]}\": ${statuses[$index]}}" if (( $index + 1 < $total + $array_start )) ; then json="$json, " ; fi done ; unset index array_start @@ -677,16 +670,16 @@ unset code cat $rvm_ruby_file >> "$rvm_temp_path/$$.rb" echo -e "\n end \nend\n" >> "$rvm_temp_path/$$.rb" rvm_ruby_args="$rvm_temp_path/$$.rb" rvm_action="ruby" - if [ ! -z "$rvm_debug_flag" ] ; then echo -e "$rvm_temp_path/$$.rb:\n$(cat $rvm_temp_path/$$.rb)" ; fi + if [[ ! -z "$rvm_debug_flag" ]] ; then echo -e "$rvm_temp_path/$$.rb:\n$(cat $rvm_temp_path/$$.rb)" ; fi __rvm_do } function __rvm_irbrc { - if [ -d $rvm_ruby_home -a ! -s $rvm_ruby_irbrc ] ; then + if [[ -d "$rvm_ruby_home" ]] && [[ ! -s "$rvm_ruby_irbrc" ]] ; then rvm_ruby_irbrc_file=$(cat <<-Config require "irb/completion" rescue nil @prompt = { @@ -710,20 +703,20 @@ unset rvm_ruby_irbrc_file fi } function __rvm_pushpop { - if [ -z "$1" ] ; then + if [[ -z "$1" ]] ; then popd > /dev/null 2>&1 else pushd "$1" > /dev/null 2>&1 fi } function __rvm_state { - if [ -z "$rvm_state" ] ; then - if [ -z "$(which ruby | awk /$(basename $rvm_path)/)" ] ; then + if [[ -z "$rvm_state" ]] ; then + if [[ -z "$(which ruby | awk /$(basename $rvm_path)/)" ]] ; then rvm_state=system else rvm_state="$(dirname $(which ruby) | xargs dirname | xargs basename)" fi else @@ -736,16 +729,16 @@ function __rvm_inspect { for binary in $rvm_ruby_args ; do actual_file=$(which $binary) __rvm_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 + 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 } # # ruby supporting libraries: @@ -757,11 +750,11 @@ # TODO: Figure out how to list, grab and apply the patches __rvm_log "info" "Retrieving $package-$version.$archive_format" __rvm_fetch "ftp://ftp.gnu.org/gnu/readline/$package-$version.$archive_format" __rvm_run "$package/extract" "tar zxf $rvm_archives_path/$package-$version.$archive_format -C $rvm_src_path" "Extracting $package-$version.$archive_format" cd "$rvm_src_path/$package-$version" - if [ "Darwin" = "$(uname)" ] ; then + if [[ "Darwin" = "$(uname)" ]] ; then #sdk=$(ls -t /Developer/SDKs/ | head -n 1) #CFLAGS="-isysroot /Developer/SDKs/$sdk -arch i386 -arch x86_64" #LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/$sdk -arch i386 -arch x86_64" #export CFLAGS LDFLAGS __rvm_run "$package/configure" "./configure --prefix=$rvm_path/usr --disable-dependency-tracking --disable-static --enable-shared" "Configuring $package" @@ -828,40 +821,39 @@ __rvm_run "$package/make.install" "/usr/bin/make install" "Installing $package to $rvm_path/usr" __rvm_pushpop } __rvm_make_flags() { - PATH=.rvm/usr/bin:$PATH ; export PATH - if [ "Darwin" = "$(uname)" ] ; then + PATH=${rvm_path}/usr/bin:$PATH ; export PATH + if [[ "Darwin" = "$(uname)" ]] ; then sdk="$(/bin/ls -t /Developer/SDKs/ | head -n 1)" - if [ "Darwin" = "$(uname)" ] ; then - if [[ "$(sw_vers -productVersion)" =~ ^10.6 ]] ; then - rvm_archflags="-arch x86_64" + if [[ "Darwin" = "$(uname)" ]] ; then + rvm_archflags="-arch $(uname -m)" + if [[ "-arch x86_64" = "$rvm_archflags" ]] ; then openssl_os="os/compiler darwin64-x86_64-cc" else - rvm_archflags="-arch i386" openssl_os="os/compiler darwin-i386-cc" fi fi CFLAGS="-isysroot /Developer/SDKs/$sdk $rvm_archflags" ; export CFLAGS LDFLAGS="-Wl,-syslibroot /Developer/SDKs/$sdk $rvm_archflags" ; export LDFLAGS ARCHFLAGS="$rvm_archflags" ; export ARCHFLAGS fi } __rvm_monitor() { - if [ -d test/ ] ; then + if [[ -d "test/" ]] ; then : - elif [ -d spec/ ] ; then + elif [[ -d "spec/" ]] ; then : fi } # # Actual Utility functions. # timestamp() { - if [ "Darwin" = "$(uname)" ] ; then + if [[ "Darwin" = "$(uname)" ]] ; then echo $(stat -c "%Y" $1) else echo $(stat -f "%m" $1) fi }