scripts/rvm-utility in wayneeseguin-rvm-0.0.44 vs scripts/rvm-utility in wayneeseguin-rvm-0.0.45

- old
+ new

@@ -1,10 +1,13 @@ #!/bin/bash function __rvm_info { cat <<Info +system: + uname: "$(uname -a)" + ruby: interpreter: "`ruby -v | awk '{print $1}'`" version: "`ruby -v | awk '{print $2}'`" date: "`ruby -v | sed 's/^.*(\([0-9]\{4\}\(-[0-9][0-9]\)\{2\}\).*$/\1/'`" platform: "`ruby -v | sed 's/^.*\[//' | sed 's/\].*$//'`" @@ -27,38 +30,37 @@ IRBRC: "$IRBRC" Info } function __rvm_debug { + __rvm_log "debug" "\nPATH:\n$(echo $PATH | awk -F":" '{print $1":"$2":"$3":"$4":"$5}')" - __rvm_log "info" "PATH:$(echo $PATH | awk -F":" '{print $1":"$2":"$3":"$4":"$5}')" + for file_name in ~/.bash_profile ~/.bashrc ~/.zshrc ; do + if [ -s $file_name ] ; then + __rvm_log "debug" "\n$file_name:\n$(grep 'rvm' $file_name)" + fi + done - for file in .bash_profile .bashrc .zshrc ; do - if [ -s $file ] ; then - __rvm_log "debug" "~/$file:\n$(grep rvm ~/$file)\n" + 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 + __rvm_log "debug" "$file_name (filtered):\n$(cat $file_name | awk '!/assword|_key/')\n" fi done - if [ -s $rvm_path/default ] ; then - __rvm_log "debug" "$rvm_path/default:\n$($rvm_path/default)\n" + if [ -f $rvm_path/bin/rvm ] ; then + __rvm_log "error" "rvm script in bin! \n$(ls -laht $rvm_path/bin/rvm)" fi - - if [ -e $rvm_path/bin/rvm ] ; then - __rvm_log "debug" "rvm script in bin:\n$(ls -laht $rvm_path/bin/rvm)" - fi - } # Logging functions based on level function __rvm_log { - case "$1" in - 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 ;; + debug) shift ; echo -e "\033[0;35m<debug> \033[0m $* \033[0;35m</debug> \033[0m " ;; + info) shift ; echo -e "\033[0;32m<info> \033[0m $* \033[0;32m</info> \033[0m " ;; + warn) shift ; echo -e "\033[0;33m<warning> \033[0m $* \033[0;33m</warning> \033[0m " ;; + error) shift ; echo -e "\033[0;31m<error> \033[0m $* \033[0;31m</error> \033[0m " ;; + fail) shift ; echo -e "\033[0;31m<fail> \033[0m $* \033[0;31m</fail> \033[0m " ; __rvm_pushpop ; return 1 ;; *) echo -e "$*" esac } function __rvm_clean-path { @@ -84,26 +86,26 @@ 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 eval "nice -n $rvm_niceness /bin/bash -l -c '$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" ; popd 2> /dev/null ; 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 { - 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 +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_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 rvm_json_flag rvm_yaml_flag } # TODO: root user loadng of /etc/rvmrc function __rvm_load-rvmrc { if [ -s ~/.rvmrc ] ; then source ~/.rvmrc ; fi } function __rvm_bin_scripts { # NOTE: This depends on the forthcoming ruby_string select functionality. - rvm_ruby_binaries=`/bin/ls $rvm_path/*/bin/ruby` + rvm_ruby_binaries=`/bin/ls $rvm_path/*/bin/ruby 2> /dev/null` 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_bin_script @@ -129,21 +131,21 @@ chmod +x $rvm_bin_path/$rvm_ruby_package_name } function __rvm_fetch { - pushd $rvm_archives_path > /dev/null + __rvm_pushpop $rvm_archives_path eval $rvm_fetch "$1" 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 + __rvm_pushpop return $result } function __rvm_load-defaults { @@ -257,37 +259,42 @@ fi } # clones from source implementation/version to default +# TODO: Merge this into 'rvm sync' function __rvm_gem-dup { __rvm_log "debug" "$rvm_ruby_interpreter" if [ "$rvm_ruby_interpreter" = "default" ] ; then # TODO: ~/.rvm/default first, then system user - rvm_source_gem_dir="$rvm_system_user_gem_path" + rvm_source_gem_path="$rvm_system_user_gem_path" elif [ "$rvm_ruby_interpreter" = "user" ] ; then - rvm_source_gem_dir="$rvm_system_user_gem_path" + rvm_source_gem_path="$rvm_system_user_gem_path" elif [ "$rvm_ruby_interpreter" = "system" ] ; then - rvm_source_gem_dir="$rvm_system_gem_path" + rvm_source_gem_path="$rvm_system_gem_path" else # TODO: use selector for this? - rvm_source_gem_dir=${rvm_gem_home/$rvm_ruby_interpreter/$rvm_ruby_version} + rvm_source_gem_path=${rvm_gem_home/$rvm_ruby_interpreter/$rvm_ruby_version} fi + __rvm_gem_sync +} - if [ ! -z "$rvm_source_gem_dir" ] ; then - for rvm_gem_name_version in `/bin/ls $rvm_source_gem_dir/gems` ; do +function __rvm_gem_sync { + if [ ! -z "$rvm_source_gem_path" ] ; then + for rvm_gem_name_version in `/bin/ls $rvm_source_gem_path/gems 2> /dev/null` ; 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 echo "$rvm_gem_name_version already installed." else - __rvm_gi $rvm_source_gem_dir/cache/$rvm_gem_name-$rvm_gem_version.gem + __rvm_gi $rvm_source_gem_path/cache/$rvm_gem_name-$rvm_gem_version.gem fi done unset rvm_gem_name_version rvm_gem_name rvm_gem_version else - __rvm_log "fail" "Unknown $rvm_ruby_interpreter version: $rvm_ruby_version" + __rvm_log "fail" "Unknown ruby selected :(" + result=1 fi } function __rvm_db { rvm_hash_file="$rvm_config_path/db" @@ -317,11 +324,11 @@ # Q: TODO: Is this neccessary any longer? function __rvm_symlinks { # TODO: Account for the ruby wrapper script files mkdir -p ${rvm_path}/bin - for release in `/bin/ls $rvm_path | grep 'ruby-'` ; do + for release in `/bin/ls $rvm_path 2> /dev/null | grep 'ruby-'` ; do for binary in irb gem rdoc ri erb ; do if [ -x $rvm_path/$release/bin/$binary ] ; then ln -fs $rvm_path/$release/bin/$binary $rvm_path/bin/$binary-${release#ruby-} fi done @@ -343,11 +350,11 @@ echo "rbx head --jit" echo "ree 20090610" else current=`which ruby | xargs dirname | xargs dirname | xargs basename` echo -e "\nruby:\n" - for version in `/bin/ls -l $rvm_path/ | awk '/ ruby-[1-2].*/ { print $NF }'` ; do + for version in `/bin/ls -l $rvm_path/ 2> /dev/null | awk '/ ruby-[1-2].*/ { print $NF }'` ; do string=`$rvm_bin_path/$version -v` if [ "$current" = "$version" ] ; then echo -e "=> $version : $string" selected="1" else @@ -355,11 +362,11 @@ fi done unset version echo -e "\njruby:\n" - for version in `/bin/ls -l $rvm_path/ | awk '/jruby-.*/ { print $NF }'` ; do + for version in `/bin/ls -l $rvm_path/ 2> /dev/null | awk '/jruby-.*/ { print $NF }'` ; do string=`$rvm_bin_path/$version -v` if [ "$current" = "$version" ] ; then echo -e "=> $version : $string" selected="1" else @@ -367,11 +374,11 @@ fi done unset version echo -e "\nree:\n" - for version in `/bin/ls $rvm_path/ | awk '/ruby-enterprise-.*/ { print $NF }'` ; do + for version in `/bin/ls $rvm_path/ 2> /dev/null | awk '/ruby-enterprise-.*/ { print $NF }'` ; do string=`$rvm_bin_path/$version -v | tr "\n" ' ' ` if [ "$current" = "$version" ] ; then echo -e "=> $version : $string" selected="1" else @@ -392,14 +399,17 @@ fi fi fi echo -e "\nsystem:\n" - if [ "$selected" = "1" ] ; then - echo -e " $($rvm_system_ruby -v)\n" - else - echo -e "=> $($rvm_system_ruby -v)\n" + system_version=`bash -l -c 'rvm system ; ruby -v 2> /dev/null'` + if [ ! -z "$system_version" ] ; then + if [ "$selected" = "1" ] ; then + echo -e " $system_version\n" + else + echo -e "=> $system_version\n" + fi fi unset current version selected fi } @@ -539,27 +549,27 @@ eval "statuses=(${statuses[*]} $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 + 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 { +# TODO: Extract the outer looping mechanism with rvm_install's rubies=() ; successes=() ; errors=() ; statuses=() # TODO: Extract the common functionality out of the if below if [ ! -z "$rvm_ruby_version" ] ; then 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 + if [ ! -z "$(echo $rvm_ruby_selector | awk '/^[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 + unset rvm_ruby_string __rvm_ruby_do done else # all while read bin_line do # Keep this on second line damnit! @@ -567,11 +577,15 @@ 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 + __rvm_summary + return ${#errors[*]} +} +function __rvm_summary { if [ ! -z "$rvm_summary_flag" ] ; then export successes errors statuses 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" @@ -579,47 +593,49 @@ echo -e "statuses: [ $(echo "${statuses[*]}" | sed 's/ /, /g') ]\n" fi if [ ! -z "$rvm_yaml_flag" ] ; then export successes errors statuses - echo -e "\nYAML:" - echo -e " totals:" - echo -e " rubies: ${#rubies[*]}" - echo -e " successes: ${#successes[*]}" - echo -e " errors: ${#errors[*]}" - echo -e " successes:" + yaml="\nYAML:\n totals:\n rubies: ${#rubies[*]}\n successes: ${#successes[*]}\n errors: ${#errors[*]}\n successes:" for var in ${successes[*]} ; do - echo -e " - $var" + yaml="$yaml\n - $var" done - echo -e " errors:" + yaml="$yaml\n errors:" for var in ${errors[*]} ; do - echo -e " - $var" + yaml="$yaml\n - $var" done - echo -e " rubies:" - for var in ${rubies[*]} ; do - echo -e " - $var" - done - echo -e " statuses:" - for var in ${statuses[*]} ; do - echo -e " - $var" - done + yaml="$yaml\n rubies:" + total=${#rubies[*]} + if [ ! -z "$ZSH_VERSION" ] ; then array_start=1 ; else array_start=0 ; fi + for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do + echo "${rubies[$index]}: ${statuses[$index]}" + yaml="$yaml\n \"${rubies[$index]}\": ${statuses[$index]}" + done ; unset index array_start + echo -e "$yaml" fi if [ ! -z "$rvm_json_flag" ] ; then - summary=$(cat <<-Summary - \nSummary: - JSON: - { - "totals": { "rubies": ${#rubies[*]}, "successes": ${#successes[*]}, "errors": ${#errors[*]}}, - "successful": [ "$(echo ${successes[*]} | sed 's/ /", "/g')" ], - "errors": [ "$(echo ${errors[*]} | sed 's/ /", "/g')" ], - "rubies": [ "$(echo ${rubies[*]} | sed 's/ /", "/g')" ], - "statuses": [ $(echo ${statuses[*]} | sed 's/ /, /g') ] - } -Summary -) - echo -e "$summary" + # + # TODO: Merge statuses & rubies: + # rubies: + # "jruby...": 0 + # "1.9.1...": 1 + # + json="JSON:\n{" + json="$json\n \"totals\": { \"rubies\": ${#rubies[*]}, \"successes\": ${#successes[*]}, \"errors\": ${#errors[*]}}," + 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 + for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do + echo "${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 + json="$json\n }\n}" + echo -e "$json" else unset bin_line rvm_summary_flag fi return ${#errors[*]} } @@ -672,38 +688,30 @@ fi return 0 } function __rvm_gemset_dump { - if [ -z "$rvm_gem_set_name" ] ; then - file_name="default" - else - file_name="$rvm_gem_set_name" - fi + file_name=${rvm_gem_set_name:-'default'} 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 + for gem in `gem list | sed 's/[\(|\)]//g' | sed 's/, /,/g' | tr ' ' ';'` ; do name=`echo $gem | awk -F';' '{print $1}'` 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 + done ; unset version versions else echo "$name" >> $file_name.gemset - fi - unset name - done - unset file_name gems versions + fi ; unset name + done ; unset file_name } function __rvm_gemset_load { echo "Loading $rvm_load_file file..." - rvm_ruby_gem_list=`/bin/ls $rvm_gem_home/specifications/ | sed 's/\.gemspec$//' 2> /dev/null` + rvm_ruby_gem_list=`/bin/ls $rvm_gem_home/specifications/ 2> /dev/null | 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}'` @@ -714,11 +722,12 @@ if [ -z "$gem_version" ] ; then # no version gem_file_name="${gem_name}*.gem" else # version gem_file_name="$gem_name-$gem_version.gem" fi - cache_file=`/bin/ls -t $rvm_gem_path/*/*/cache/${gem_file_name}* | head -n1 2> /dev/null` + + cache_file=`/bin/ls -t $rvm_gem_path/*/*/cache/${gem_file_name}* 2> /dev/null | head -n1` if [ -z "$cache_file" ] ; then if [ -z "$gem_version" ] ; then gem="$gem_name" else gem="$gem_name -v $gem_version" @@ -772,19 +781,25 @@ Config ` touch $rvm_ruby_irbrc echo -e "\n$rvm_irbrc_file" > $rvm_ruby_home/.irbrc fi +} +function __rvm_pushpop { + if [ -z "$1" ] ; then + popd > /dev/null 2>&1 + else + pushd $1 > /dev/null 2>&1 + fi } - # # ruby supporting libraries: # function __rvm_readline_install { - pushd $rvm_path/src > /dev/null + __rvm_pushpop $rvm_path/src package=readline version=5.2 # TODO: Figure out how to list, grab and apply the patches __rvm_fetch "ftp://ftp.gnu.org/gnu/readline/$package-$version.tar.gz" __rvm_run "$package.extract" tar zxf $rvm_archives_path/$package-$version.tar.gz -C $rvm_path/src/ @@ -798,22 +813,20 @@ else __rvm_run "$package.configure" ./configure --prefix=$rvm_path/usr --disable-dependency-tracking --disable-static --enable-shared fi __rvm_run "$package.make" make __rvm_run "$package.make.install" make install - popd > /dev/null + __rvm_pushpop } function __rvm_iconv_install { - pushd $rvm_path/src > /dev/null + __rvm_pushpop $rvm_path/src package=libiconv version=1.13.1 __rvm_fetch "http://ftp.gnu.org/pub/gnu/libiconv/$package-$version.tar.gz" __rvm_run "$package.extract" tar zxf $rvm_archives_path/$package-$version.tar.gz -C $rvm_dir/src/ cd $rvm_path/src/$package-$version __rvm_run "$package.configure" ./configure --prefix=$rvm_path/usr --disable-shared __rvm_run "$package.make" make __rvm_run "$package.make.install" make install - - popd > /dev/null + __rvm_pushpop } -