scripts/rvm-utility in wayneeseguin-rvm-0.0.40 vs scripts/rvm-utility in wayneeseguin-rvm-0.0.42

- old
+ new

@@ -50,15 +50,15 @@ # Logging functions based on level function __rvm_log { case "$1" in - debug) shift ; echo -e "\n\033[0;35m <d> \033[0m $*" ;; - info) shift ; echo -e "\n\033[0;32m <i> \033[0m $*" ;; - warn) shift ; echo -e "\n\033[0;33m <w> \033[0m $*" ;; - error) shift ; echo -e "\n\033[0;31m <e> \033[0m $*" ;; - fail) shift ; echo -e "\n\033[0;31m <e> \033[0m $*" ; popd 2> /dev/null ; return 1 ;; + debug) shift ; echo -e "\033[0;35m <d> \033[0m $*" ;; + info) shift ; echo -e "\033[0;32m <i> \033[0m $*" ;; + warn) shift ; echo -e "\033[0;33m <w> \033[0m $*" ;; + error) shift ; echo -e "\033[0;31m <e> \033[0m $*" ;; + fail) shift ; echo -e "\033[0;31m <e> \033[0m $*" ; popd 2> /dev/null ; return 1 ;; *) echo -e "$*" esac } function __rvm_clean-path { @@ -76,11 +76,11 @@ function __rvm_run { log_file_name="$1" ; shift command="$*" rvm_ruby_log_path=${rvm_ruby_log_path:-$rvm_path/log} mkdir -p $rvm_ruby_log_path - if [ $rvm_debug ] ; then __rvm_log "debug" "Executing: $command" ; fi + if [ ! -z "$rvm_debug_flag" ] ; then __rvm_log "debug" "Executing: $command" ; fi 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 "$rvm_niceness" = "0" ] ; then eval "$command" >> $rvm_ruby_log_path/$log_file_name.log 2>> $rvm_ruby_log_path/$log_file_name.error.log else @@ -89,11 +89,11 @@ if [ $? -gt 0 ] ; then __rvm_log "error" "Error running '$command', please check $rvm_ruby_log_path/$log_file_name.error.log" ; popd 2> /dev/null ; return 1 ; fi unset log_file command } function __rvm_cleanup-variables { - unset rvm_selected rvm_action rvm_ruby_interpreter rvm_ruby_patch_level rvm_ruby_version rvm_irbrc_file rvm_ruby_irbrc rvm_source_path rvm_path rvm_debug rvm_prefix_path rvm_ruby_package_name rvm_gem_path rvm_command rvm_error_message rvm_ruby_home rvm_ruby_binary rvm_gem_set_name rvm_delete_flag rvm_ruby_tag rvm_ruby_rev rvm_url rvm_ruby_make rvm_ruby_make_install rvm_config_path rvm_bin_path rvm_force rvm_all rvm_re_configure rvm_summary rvm_ruby_string rvm_make_flags rvm_bin_flag + unset rvm_selected rvm_action rvm_ruby_interpreter rvm_ruby_patch_level rvm_ruby_version rvm_irbrc_file rvm_ruby_irbrc rvm_source_path rvm_path rvm_prefix_path rvm_ruby_package_name rvm_gem_path rvm_command rvm_error_message rvm_ruby_home rvm_ruby_binary rvm_gem_set_name rvm_ruby_tag rvm_ruby_rev rvm_url rvm_ruby_make rvm_ruby_configure rvm_ruby_make_install rvm_config_path rvm_ruby_string rvm_bin_path rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_load_flag rvm_dump_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_install_on_use } # TODO: root user loadng of /etc/rvmrc function __rvm_load-rvmrc { if [ -s ~/.rvmrc ] ; then source ~/.rvmrc ; fi @@ -131,20 +131,20 @@ function __rvm_fetch { pushd $rvm_archives_path > /dev/null eval $rvm_fetch "$1" - status=$? - if [ $status -gt 0 ] ; then - if [ $status -eq 78 ] ; then + result=$? + if [ $result -gt 0 ] ; then + if [ $result -eq 78 ] ; then __rvm_log "error" "The requested url does not exist: '$1'" else __rvm_log "error" "There was an error, please check $rvm_ruby_log_path/*.error.log" fi fi popd 2> /dev/null - return $status + return $result } function __rvm_load-defaults { if [ ! -s $rvm_path/system ] ; then @@ -202,11 +202,11 @@ PATH="$rvm_path/bin:$rvm_system_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_select "system" for system_config in system_ps1 system_path system_ruby system_gem_path system_user_gem_path ; do __rvm_db "$system_config" "delete" @@ -324,11 +324,11 @@ } function __rvm_list { - if [ "$rvm_all" ] ; then + if [ "$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 "jruby 1.2.0" echo "jruby 1.3.0" echo "jruby 1.3.1" @@ -405,14 +405,14 @@ if [ $? -ne 0 ] ; then rvm_fetch=`which wget` if [ $? -ne 0 ] ; then __rvm_log "fail" "rvm expects either curl or wget, neither seem to be in your path :(" else - rvm_fetch="wget -q -c " + rvm_fetch="wget -c " # -q for quiet fi else - rvm_fetch="$rvm_fetch -O -L -s --create-dirs -C - " + 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 [ "`whoami`" = "root" ] ; then __rvm_log "fail" "root user support is not yet implemented." @@ -433,33 +433,32 @@ rvm_config_path=${rvm_config_path:-"${rvm_path}/config"} rvm_ruby_repo_url="${rvm_ruby_repo_url:-"http://svn.ruby-lang.org/repos/ruby"}" # Rubinius sha1's will be available after RC1. rvm_rubinius_repo_url="${rvm_rubinius_repo_url:-"git://github.com/evanphx/rubinius.git"}" - #rvm_macruby_repo_url="${rvm_macruby_repo_url:-"http://svn.macosforge.org/repository/ruby/MacRuby"}" - rvm_macruby_repo_url="${rvm_macruby_repo_url:-"git://github.com/masterkain/macruby.git"}" rvm_jruby_repo_url="${rvm_jruby_repo_url:-"git://kenai.com/jruby~main"}" rvm_ruby_load_path="." rvm_ruby_require="" __rvm_clean-path rvm_result=$(echo $PATH | grep 'rvm\/bin:') if [ -z $rvm_result ] ; then PATH=$rvm_bin_path:$PATH ; export PATH fi - mkdir -p $rvm_source_path $rvm_bin_path $rvm_archives_path + mkdir -p $rvm_source_path $rvm_bin_path $rvm_archives_path $rvm_path/tmp } function __rvm_update { - if [ "$rvm_ruby_rev" = "head" -o "$rvm_update_flag" ] ; then + if [ "$rvm_ruby_rev" = "head" -o ! -z "$rvm_self_flag" -o ! -z "$rvm_update_flag" ] ; then __rvm_version __rvm_update_rvm __rvm_version fi __rvm_reload __rvm_select + # 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 } function __rvm_update_rvm { @@ -510,144 +509,104 @@ function __rvm_reload { source $rvm_path/scripts/rvm } +function __rvm_ruby_do { + __rvm_select + __rvm_use + binary=`echo $rvm_action | sed 's/do$//'` + if [ -x $rvm_ruby_home/bin/$binary ] ; then + load_path="$rvm_ruby_home/bin:$rvm_ruby_load_path" + if [ "$binary" = "ruby" ] ; then + rvm_command="$rvm_ruby_home/bin/$binary $rvm_ruby_require -I$load_path -S $rvm_ruby_args" + else + rvm_command="$rvm_ruby_home/bin/$binary $rvm_ruby_args" + fi + echo -e "\n$rvm_ruby_string: $($rvm_ruby_home/bin/$binary -v)" + eval $rvm_command + result=$? + if [ $result -eq 0 ]; then + eval "successes=(${successes[*]} $rvm_ruby_string)" + else + eval "errors=(${errors[*]} $rvm_ruby_string)" + fi + eval "all=(${all[*]} $rvm_ruby_string)" + eval "results=(${results[*]} $result)" + # TODO: keep track of and re-set the previous selected ruby ;) + else + __rvm_log "warn" "'$rvm_ruby_home/bin/$binary' either does not exist or is not executable? :(" + fi + 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_rev rvm_ruby_tag rvm_major_version rvm_minor_version rvm_gem_set_name rvm_gem_home rvm_ruby_binary rvm_ruby_package_name rvm_ruby_home rvm_ruby_log_path rvm_ruby_src_path rvm_ruby_irbrc rvm_selected +} + function __rvm_do { - all=() ; successes=() ; errors=() ; statuses=() + all=() ; successes=() ; errors=() ; results=() # TODO: Extract the common functionality out of the if below if [ ! -z "$rvm_ruby_version" ] ; then - rvm_ruby_selectors=$(echo $rvm_ruby_version | tr ',' ' ') - for rvm_ruby_selector in $rvm_ruby_selectors ; do + for rvm_ruby_selector in `echo $rvm_ruby_version | tr ',' ' '` ; do temp=$(echo $rvm_ruby_selector | awk '{print substr($1, 0, 1)}') if [ ! -z "$(echo $temp | grep '[0-9]')" ] ; then rvm_ruby_interpreter="ruby" rvm_ruby_version="$rvm_ruby_selector" else rvm_ruby_interpreter="$rvm_ruby_selector" unset rvm_ruby_version fi unset temp - __rvm_select - __rvm_use - #__rvm_ - binary=`echo $rvm_action | sed 's/do$//'` - lp="$rvm_ruby_home/bin:$rvm_ruby_load_path" - if [ "$binary" = "ruby" ] ; then - rvm_command="$rvm_ruby_home/bin/$binary $rvm_ruby_require -I$lp -S $rvm_ruby_args" - else - rvm_command="$rvm_ruby_home/bin/$binary $rvm_ruby_args" - fi - echo "$rvm_ruby_string: $($rvm_ruby_home/bin/$binary -v)" - eval $rvm_command - status=$? - if [ $status -eq 0 ]; then - successes[${#successes[*]}]=$rvm_ruby_string - else - errors[${#errors[*]}]=$rvm_ruby_string - fi - all[${#all[*]}]=$rvm_ruby_string - statuses[${#statuses[*]}]=$status - # TODO: keep track of and re-set the previous selected ruby ;) - unset rvm_ruby_interpreter rvm_ruby_patch_level rvm_ruby_version rvm_ruby_package_name rvm_ruby_home rvm_ruby_irbrc rvm_ruby_binary rvm_ruby_string lp + __rvm_ruby_do done else # all - rvm_ruby_binaries=`/bin/ls $rvm_path/*/bin/ruby` - for rvm_ruby_binary in $rvm_ruby_binaries ; do - if [ -x $rvm_ruby_binary ] ; then - rvm_ruby_string=`dirname $rvm_ruby_binary | xargs dirname | xargs basename` - __rvm_select - __rvm_use - rvm_ruby_string="$(dirname $rvm_ruby_home/bin/$binary | xargs dirname | xargs basename)" - lp="$rvm_ruby_home/bin:$rvm_ruby_load_path" - if [ "$binary" = "ruby" ] ; then - rvm_command="$rvm_ruby_binary $rvm_ruby_require -I$lp -S $rvm_ruby_args" - else - rvm_command="$rvm_ruby_binary $rvm_ruby_args" - fi - echo "$(basename $rvm_ruby_binary):" - eval $rvm_command - status=$? - if [ $status -eq 0 ]; then - successes[${#successes[*]}]=$rvm_ruby_string - else - errors[${#errors[*]}]=$rvm_ruby_string - fi - all[${#all[*]}]=$rvm_ruby_string - statuses[${#statuses[*]}]=$status - unset rvm_ruby_interpreter rvm_ruby_patch_level rvm_ruby_version rvm_ruby_package_name rvm_ruby_home rvm_ruby_irbrc rvm_ruby_binary rvm_ruby_string lp + while read bin_line + do # Keep this on second line damnit! + if [ -x $bin_line ] ; then + rvm_ruby_string="`dirname $bin_line | xargs dirname | xargs basename`" + __rvm_ruby_do fi - done + done < <(/bin/ls $rvm_path/*/bin/ruby 2> /dev/null) fi - export successes errors statuses - - if [ ! -z "$rvm_summary" ] ; then - echo -e "\n\033[0;32msuccessful (${#successes[*]}) : [ $(echo "${successes[*]}" | sed 's/ /, /g') ]\033[0m" - echo -e "\n\033[0;31merrors (${#errors[*]}) : [ $(echo "${errors[*]}" | sed 's/ /, /g') ]\033[0m" + if [ ! -z "$rvm_summary_flag" ] ; then + export successes errors results + echo -e "\nSummary:" + echo -e "\033[0;32msuccessful (${#successes[*]}) : [ $(echo "${successes[*]}" | sed 's/ /, /g') ]\033[0m" + echo -e "\033[0;31merrors (${#errors[*]}) : [ $(echo "${errors[*]}" | sed 's/ /, /g') ]\033[0m" echo -e "all (${#all[*]}) : [ $(echo "${all[*]}" | sed 's/ /, /g') ]" - echo -e "exit statuses: [ $(echo "${statuses[*]}" | sed 's/ /, /g') ]\n" - # unset binary successes errors rvm_summary + echo -e "exit results: [ $(echo "${results[*]}" | sed 's/ /, /g') ]\n" else - unset binary successes errors rvm_summary + unset bin_line rvm_summary_flag + # successes errors fi return ${#errors[*]} } -function __rvm_irbrc { - if [ ! -s "$rvm_ruby_irbrc" ] ; then - rvm_irbrc_file=`cat <<-Config -load '$HOME/.irbrc' if File.exists?('$HOME/.irbrc') rescue nil - -require "irb/completion" rescue nil - -@prompt = { - :PROMPT_I => "${rvm_ruby_package_name} > ", # default prompt - :PROMPT_S => "${rvm_ruby_package_name}%l> ", # known continuation - :PROMPT_C => "${rvm_ruby_package_name} > ", - :PROMPT_N => "${rvm_ruby_package_name} ?> ", # unknown continuation - :RETURN => " => %s \n", - :AUTO_INDENT => true -} -@prompt_mode = :DEFAULT -IRB.conf[:PROMPT][@prompt_mode] = @prompt -IRB.conf[:PROMPT_MODE] = @prompt_mode -Config -` - touch $rvm_ruby_home/.irbrc - echo -e "\n$rvm_irbrc_file" > $rvm_ruby_home/.irbrc - fi - -} - function __rvm_ruby_string { if [ "$rvm_ruby_interpreter" = "system" ] ; then - rvm_ruby_string="" + rvm_ruby_string="system" elif [ ! -z "$rvm_ruby_string" ] ; then - echo $rvm_ruby_string | grep "enterprise" > /dev/null - if [ $? -eq 0 ] ; then - rvm_ruby_interpreter="ruby-enterprise" - else - rvm_ruby_interpreter=`echo $rvm_ruby_string | tr '-' ' ' | awk '{print $1}'` - fi - rvm_ruby_vesion=`echo $rvm_ruby_string | awk -F'-' '{print $(NF-1)}'` - revision=`echo $rvm_ruby_string | awk '{print $NF}'` + rvm_ruby_string=`echo "$rvm_ruby_string" | sed 's/ruby-enterprise/ree/g'` # dash-antics :) + rvm_ruby_interpreter=`echo $rvm_ruby_string | tr '-' ' ' | awk '{print $1}'` + rvm_ruby_version=`echo $rvm_ruby_string | awk -F'-' '{print $2}'` + revision=`echo $rvm_ruby_string | awk -F'-' '{print $3}'` + if [ "$revision" = "head" -o "$revision" = "preview" ] ; then rvm_ruby_revision="$revision" else - echo $revision | grep 'p[0-9]\+' > /dev/null + echo $revision | grep '^p[0-9]\+' > /dev/null if [ $? -eq 0 ] ; then rvm_ruby_patch_level=`echo $revision | awk -F'p' '{print $2}'` else - echo $revision | grep '[0-9]\+' > /dev/null + echo $revision | grep '^[0-9]\+' > /dev/null if [ $? -eq 0 ] ; then rvm_ruby_rev="$revision" else unset rvm_ruby_patch_level rvm_ruby_rev fi fi fi + + if [ "rvm_ruby_interpreter" = "ree" ] ; then rvm_ruby_interpreter="ruby-enterprise" ; fi fi return 0 } function __rvm_gemset_dump { @@ -660,11 +619,11 @@ echo "# $rvm_gem_set_name.gemset generated gem dump file. Note that any env variable settings will be missing. Append these after using a ';' field separator" > $rvm_gem_set_name.gemset gems="`gem list | sed 's/[\(|\)]//g' | sed 's/, /,/g' | tr ' ' ';'`" for gem in $gems ; do name=`echo $gem | awk -F';' '{print $1}'` - if [ -z "$rvm_gem_latest" ] ; then + if [ -z "$rvm_latest_flag" ] ; then versions=`echo $gem | awk -F';' '{print $2}' | sed 's/,/ /g'` for version in $versions ; do echo "$name -v$version" >> $file_name.gemset done unset version @@ -676,42 +635,90 @@ unset file_name gems versions } function __rvm_gemset_load { echo "Loading $rvm_load_file file..." - while read line < `cat "$rvm_load_file" | awk '/^[a-zA-Z]/{print}'` ; do + rvm_ruby_gem_list=`/bin/ls $rvm_gem_home/specifications/ | sed 's/\.gemspec$//' 2> /dev/null` + while read line + do # Keep this on 2nd line :( bash fail. # TODO: Switch to a different field separator than ; to allow for evals gem=`echo $line | awk -F';' '{print $1}'` gem_prefix=`echo $line | awk -F';' '{print $2}'` gem_name=`echo $gem | awk '{print $1}'` gem_version=`echo $gem | sed 's/^.*-v[=]*[ ]*//' | awk '{print $1}'` gem_postfix=`echo $gem | sed "s/$gem_name//" | sed "s/-v[=]*[ ]*$gem_version//"` - gem_file="$gem_name-$gem_version.gem" if [ -z "$gem_version" ] ; then # no version - file=`/bin/ls -t $rvm_gem_home/cache/${gem_name}* | head -n 1` + gem_file_name="${gem_name}*.gem" else # version - file=`/bin/ls $rvm_gem_home/cache/$gem_file` + gem_file_name="$gem_name-$gem_version.gem" fi - - if [ -z "$file" ] ; then # not cached - gem="$gem_name-$gem_version" + cache_file=`/bin/ls -t $rvm_gem_path/*/*/cache/${gem_file_name}* | head -n1 2> /dev/null` + if [ -z "$cache_file" ] ; then + if [ -z "$gem_version" ] ; then + gem="$gem_name" + else + gem="$gem_name -v $gem_version" + fi else # cached - gem="$file -l" # install as a named local gem + gem_file_name=`basename $cache_file` + gem_string=`echo "$gem_file_name" | sed 's/\.gem$//'` + if [ ! -z "`echo "$rvm_ruby_gem_list" | awk "/$gem_string/{print}"`" ] ; then + if [ ! -z "$rvm_force_flag" ] ; then + cp $cache_file $rvm_path/tmp/$gem_file_name + gem="$rvm_path/tmp/$gem_file_name" # install as a named local gem + else + unset gem + __rvm_log "info" "$gem_name $gem_version is already installed, skipping. (use --force to force these to install regardless)" + fi + else + gem="$cache_file" + fi fi - # TODO: Set vars if fourth field is non-empty (means that there are conditional statements to execute in the gem install line. - if [ -z "$vars" ] ; then - GEM_HOME="$rvm_gem_home" GEM_PATH="$rvm_gem_home" $gem_prefix $rvm_ruby_home/bin/gem install --no-rdoc --no-ri -q $gem $gem_postfix - else - eval "GEM_HOME='$rvm_gem_home' GEM_PATH='$rvm_gem_home' $gem_prefix $rvm_ruby_home/bin/gem install --no-rdoc --no-ri -q $gem $gem_postfix" + if [ ! -z "$gem" ] ; then + # TODO: Set vars if fourth field is non-empty (means that there are conditional statements to execute in the gem install line. + if [ -z "$vars" ] ; then + GEM_HOME="$rvm_gem_home" GEM_PATH="$rvm_gem_home" $gem_prefix $rvm_ruby_home/bin/gem install --no-rdoc --no-ri -q $gem $gem_postfix + else + eval "GEM_HOME='$rvm_gem_home' GEM_PATH='$rvm_gem_home' $gem_prefix $rvm_ruby_home/bin/gem install --no-rdoc --no-ri -q $gem $gem_postfix" + fi fi - unset gem gem_prefix gem_name gem_version gem_file gem_postfix file - done + unset gem gem_prefix gem_name gem_version gem_file_name gem_postfix cache_file gem_file_name gem_string + done < <(awk '/^[a-zA-Z]/{print}' "$rvm_load_file") } -# -C --with-readline-dir=$rvm_path/usr +function __rvm_irbrc { + if [ -d $rvm_ruby_home -a ! -s $rvm_ruby_irbrc ] ; then + rvm_irbrc_file=`cat <<-Config +load '$HOME/.irbrc' if File.exists?('$HOME/.irbrc') rescue nil + +require "irb/completion" rescue nil + +@prompt = { + :PROMPT_I => "${rvm_ruby_package_name} > ", # default prompt + :PROMPT_S => "${rvm_ruby_package_name}%l> ", # known continuation + :PROMPT_C => "${rvm_ruby_package_name} > ", + :PROMPT_N => "${rvm_ruby_package_name} ?> ", # unknown continuation + :RETURN => " => %s \n", + :AUTO_INDENT => true +} +@prompt_mode = :DEFAULT +IRB.conf[:PROMPT][@prompt_mode] = @prompt +IRB.conf[:PROMPT_MODE] = @prompt_mode +Config +` + touch $rvm_ruby_irbrc + echo -e "\n$rvm_irbrc_file" > $rvm_ruby_home/.irbrc + fi + +} + + +# +# ruby supporting libraries: +# function __rvm_readline_install { pushd $rvm_path/src > /dev/null package=readline version=5.2 # TODO: Figure out how to list, grab and apply the patches @@ -730,11 +737,10 @@ __rvm_run "$package.make" make __rvm_run "$package.make.install" make install popd > /dev/null } -# -C --with-iconv-dir=$rvm_path/usr function __rvm_iconv_install { pushd $rvm_path/src > /dev/null package=libiconv version=1.13.1 __rvm_fetch "http://ftp.gnu.org/pub/gnu/libiconv/$package-$version.tar.gz" @@ -744,5 +750,6 @@ __rvm_run "$package.make" make __rvm_run "$package.make.install" make install popd > /dev/null } +