scripts/gems in rvm-0.0.96 vs scripts/gems in rvm-0.0.97

- old
+ new

@@ -1,22 +1,19 @@ #!/usr/bin/env bash -#source $rvm_path/scripts/rvm source $rvm_path/scripts/utility -#source $rvm_path/scripts/selector color_green=$($rvm_scripts_path/color "green") color_red=$($rvm_scripts_path/color "red") color_yellow=$($rvm_scripts_path/color "yellow") color_none=$($rvm_scripts_path/color "none") -if [[ -z "$rvm_ruby_gem_home" ]] ; then rvm_ruby_gem_home="$(gem env home)" ; fi -if [[ "$rvm_trace_flag" -eq 1 ]] ; then set -x ; export rvm_trace_flag ; fi +if [[ ! -z "$rvm_trace_flag" ]] ; then set -x ; export rvm_trace_flag ; fi +if [[ -d "$rvm_ruby_gem_home" ]] && which gem &> /dev/null ; then rvm_ruby_gem_home="$(gem env home)" ; fi -trap "rm -f $rvm_path/tmp/$$* > /dev/null 2>&1 ; exit" 0 1 2 3 15 +trap "if [[ -d $rvm_path/tmp/ ]] && [[ -f $rvm_path/tmp/$$ ]] ; then rm -f $rvm_path/tmp/$$ > /dev/null 2>&1 ; fi ; exit" 0 1 2 3 15 - __rvm_gems_name() { echo "$rvm_gem_set_name" } __rvm_gems_dir() { @@ -115,50 +112,53 @@ echo "Loading $rvm_file_name file..." rvm_ruby_gem_list=$(\ls $rvm_ruby_gem_home/specifications/ 2> /dev/null | sed 's#.gems.*$##' 2> /dev/null) while read -r line do # Keep this on 2nd line :( - # - # Parse the line - # - gem="$(echo $line | awk -F';' '{print $1}')" - gem_prefix="$(echo $line | awk -F';' '{print $2}')" - if $rvm_scripts_path/match "$gem" "\.gem$" ; then - gem_name="$(basename $gem | sed 's#\.gem##' | awk -F'-' '{$NF=NULL;print}')" - gem_version="$(basename $gem | sed 's#\.gem##' | awk -F'-' '{print $NF}' )" - gem_postfix="$(basename $gem | sed "s#.*\.gem##")" - else - gem_name="$(echo $gem | awk '{print $1}')" - if $rvm_scripts_path/match "$gem" "--version" ; then - gem_version="$(echo $gem | sed 's#.*--version[=]*[ ]*##' | awk '{print $1}')" - gem_postfix="$(echo $gem | sed "s#${gem_name/ /}##" | sed "s#--version[=]*[ ]*${gem_version/ /}##")" - elif $rvm_scripts_path/match "$gem" "-v" ; then - gem_version="$(echo $gem | sed 's#.*-v[=]*[ ]*##' | awk '{print $1}')" - gem_postfix="$(echo $gem | sed "s#${gem_name/ /}##" | sed "s#-v[=]*[ ]*${gem_version/ /}##")" - else - unset gem_version # no version - fi - fi - - if [[ -f "$gem" ]] ; then - gem_file_name="$gem" - elif $rvm_scripts_path/match "$gem" ".gem$" ; then - gem_file_name="$gem" - elif [[ -z "${gem_version/ /}" ]] ; then # no v/Users/wayne/projects/db0/rvm/scripts/gems - gem_file_name="${gem_name/ /}*.gem" - else # version - gem_file_name="${gem_name/ /}-${gem_version/ /}.gem" - fi + __rvm_parse_gem_line $line __rvm_gem_install done < <(awk '/^[\.\/a-zA-Z]/{print}' "$rvm_file_name") else $rvm_scripts_path/log "error" "$rvm_file_name does not exist to load from." fi } + +__rvm_parse_gem_line() { + line="$*" + gem="$(echo $line | awk -F';' '{print $1}')" + gem_prefix="$(echo $line | awk -F';' '{print $2}')" + if $rvm_scripts_path/match "$gem" "\.gem$" ; then + gem_name="$(basename $gem | sed 's#\.gem##' | awk -F'-' '{$NF=NULL;print}')" + gem_version="$(basename $gem | sed 's#\.gem##' | awk -F'-' '{print $NF}' )" + gem_postfix="$(basename $gem | sed "s#.*\.gem##")" + else + gem_name="$(echo $gem | awk '{print $1}')" + if $rvm_scripts_path/match "$gem" "--version" ; then + gem_version="$(echo $gem | sed 's#.*--version[=]*[ ]*##' | awk '{print $1}')" + gem_postfix="$(echo $gem | sed "s#${gem_name/ /}##" | sed "s#--version[=]*[ ]*${gem_version/ /}##")" + elif $rvm_scripts_path/match "$gem" "-v" ; then + gem_version="$(echo $gem | sed 's#.*-v[=]*[ ]*##' | awk '{print $1}')" + gem_postfix="$(echo $gem | sed "s#${gem_name/ /}##" | sed "s#-v[=]*[ ]*${gem_version/ /}##")" + else + unset gem_version # no version + fi + fi + + if [[ -f "$gem" ]] ; then + gem_file_name="$gem" + elif $rvm_scripts_path/match "$gem" ".gem$" ; then + gem_file_name="$gem" + elif [[ -z "${gem_version/ /}" ]] ; then # no v/Users/wayne/projects/db0/rvm/scripts/gems + gem_file_name="${gem_name/ /}*.gem" + else # version + gem_file_name="${gem_name/ /}-${gem_version/ /}.gem" + fi +} __rvm_gem_install() { + __rvm_parse_gem_line $* - installed_gem="$(ls ${rvm_ruby_gem_home}/specifications/${gem_file_name}*spec 2>/dev/null | head -n 1)" + installed_gem="$(ls ${rvm_ruby_gem_home}/specifications/${gem_file_name}spec 2>/dev/null | head -n 1)" if [[ -z "$rvm_force_flag" ]] && [[ -f "$installed_gem" ]] ; then unset gem $rvm_scripts_path/log "info" "$color_green$gem_name $gem_version$yellow exists, skipping (--force to re-install)" else if [[ -f "$gem" ]] ; then @@ -202,24 +202,24 @@ # TODO: Set vars if fourth field is non-empty (means that there are conditional statements to execute in the gem install line. if [[ "rvm_make_flags_flag" -eq 1 ]] ; then __rvm_make_flags ; fi $rvm_scripts_path/log "warn" "$gem_name $gem_version is not installed, installing..." if [[ ! -z "$rvm_ruby_gem_home" ]] ; then - command="GEM_HOME='$rvm_ruby_gem_home' GEM_PATH='$rvm_ruby_gem_home' $gem_prefix gem install --no-rdoc --no-ri -q $gem $gem_postfix $vars" + command="GEM_HOME='$rvm_ruby_gem_home' GEM_PATH='$rvm_ruby_gem_home' $gem_prefix $rvm_ruby_home/bin/gem install --no-rdoc --no-ri -q $gem $gem_postfix $vars" else - command="$gem_prefix gem install --no-rdoc --no-ri -q $gem $gem_postfix $vars" + command="$gem_prefix $rvm_ruby_home/bin/gem install --no-rdoc --no-ri -q $gem $gem_postfix $vars" fi - if [[ -f "$gem" ]] ; then command="${command} -l" ; fi - eval $command > /dev/null 2>&1 + + eval $command >> "$rvm_path/log/$rvm_ruby_string/gem.install.log" 2>> "$rvm_path/log/$rvm_ruby_string/gem.install.error.log" result=$? if [[ $result -eq 0 ]] ; then - $rvm_scripts_path/log "info" "$color_green$gem_name $gem_version$color_none installed." + $rvm_scripts_path/log "info" "$color_green$gem_name $gem_version$color_none installed." else - $rvm_scripts_path/log "error" "$color_red$gem_name $gem_version$color_none failed to install." + $rvm_scripts_path/log "error" "$color_red$gem_name $gem_version$color_none failed to install, output logged to $rvm_path/log/$rvm_ruby_string/gem.install.error.log" fi - fi - unset gem gem_prefix gem_name gem_version gem_file_name gem_postfix cache_file gem_file_name gem_string + fi ; unset gem gem_prefix gem_name gem_version gem_file_name gem_postfix cache_file gem_file_name gem_string + return $result } __rvm_gems_gemdir() { if [[ "$rvm_user_flag" -eq 1 ]] ; then @@ -258,11 +258,10 @@ elif [[ "list" = "$action" ]] ; then __rvm_gems_list elif [[ "gemdir" = "$action" ]] ; then __rvm_gems_gemdir elif [[ "install" = "$action" ]] ; then - gem_file_name="$1" - __rvm_gem_install + __rvm_gem_install $* else $rvm_scripts_path/log "error" "gems must be passed an action as the first parameter {load,dump,delete,name,list,gemdir,install}" fi