scripts/manage in rvm-1.0.8 vs scripts/manage in rvm-1.0.9

- old
+ new

@@ -13,22 +13,20 @@ fi } # Checks for bison, returns zero iff it is found __rvm_check_for_bison() { - local result - if [[ ${rvm_head_flag:-0} -gt 0 ]]; then command -v bison > /dev/null result=$? if [[ $? -gt 0 ]] ; then "$rvm_path/scripts/log" "fail" \ "\nbison is not available in your path. \nPlease ensure bison is installed before compiling from head.\n" fi fi - return $result + return ${result:-0} } # Emits a number of patches to STDOUT, each on a new name # Expands patchsets etc. __rvm_current_patch_names() { @@ -57,11 +55,11 @@ return 0 } __rvm_apply_patches() { - local result patches patch_name patch_level_separator patch_fuzziness patch_level source_directory full_patch_path + local patches patch_name patch_level_separator patch_fuzziness patch_level source_directory full_patch_path result=0 patch_level_separator="%" patch_fuzziness="25" patch_level=1 @@ -105,16 +103,16 @@ result=1 fi done ) - return $result + return ${result:-0} } __rvm_install_source() { - local result directory configure_parameters db_configure_flags + local directory configure_parameters db_configure_flags [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] && __rvm_select case ${rvm_ruby_string:-""} in *-head) __rvm_ensure_has_18_compat_ruby || return 1 ;; @@ -257,27 +255,27 @@ export GEM_HOME="$rvm_ruby_gem_home" export GEM_PATH="$rvm_ruby_gem_path" export BUNDLE_PATH="$rvm_ruby_gem_home" __rvm_rubygems_setup + result=$? __rvm_bin_script __rvm_run "chmod.bin" "chmod +x $rvm_ruby_home/bin/*" __rvm_post_install + result=$? "$rvm_path/scripts/log" "info" \ "Install of $rvm_ruby_string - #complete " - return 0 + return ${result:-0} } __rvm_install_ruby() { - local result - if [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] ; then __rvm_select ; fi if [[ -n "${RUBYOPT:-""}" ]] ; then ruby_options="$RUBYOPT" ; fi unset RUBYOPT @@ -724,11 +722,11 @@ # jruby ships with some built in gems, copy them in to place. if [[ -d "$rvm_ruby_home/lib/ruby/gems/1.8" ]]; then "$rvm_path/scripts/log" "info" "Copying across included gems" - cp -R "$rvm_ruby_home/lib/ruby/gems/1.8/" "$GEM_HOME/" + cp -R "$rvm_ruby_home/lib/ruby/gems/1.8/" "$rvm_ruby_gem_home/" fi ;; maglev) __rvm_ensure_has_18_compat_ruby @@ -1119,16 +1117,14 @@ if [[ -n "$ruby_options" ]] ; then RUBYOPT="$ruby_options" export RUBYOPT fi - return $result + return ${result:-0} } __rvm_fetch_from_github() { - local result - rm -rf "${rvm_src_path:-"$rvm_path/src"}/$rvm_ruby_string" if [[ ! -d "${rvm_repos_path:-"$rvm_path/repos"}/$rvm_ruby_string/.git" ]] ; then rm -rf "${rvm_repos_path:-"$rvm_path/repos"}/$rvm_ruby_string" @@ -1155,15 +1151,14 @@ __rvm_run "$1.copy" "\\cp -R \"${rvm_repos_path:-"$rvm_path/repos"}/$rvm_ruby_string\" \"${rvm_src_path:-"$rvm_path/src"}/$rvm_ruby_string\"" "Copying from repo to source..." builtin cd "${rvm_src_path:-"$rvm_path/src"}/$rvm_ruby_string" - return $? + return ${result:-0} } __rvm_fetch_ruby() { - local result [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] && __rvm_select "$rvm_path/scripts/log" "info" "$rvm_ruby_string - #fetching " @@ -1240,11 +1235,11 @@ "There has been an error while trying to extract $rvm_ruby_package_file. Halting the installation." return $result fi ;; tar.bz2) - __rvm_run "extract" "bunzip2 < \"${rvm_archives_path:-"$rvm_path/archives"}/$rvm_ruby_package_file.$rvm_archive_extension\" | tar xf - -C /tmp/rvm_src_$$" "$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path:-"$rvm_path/src"}/$rvm_ruby_string" + __rvm_run "extract" "bunzip2 < '${rvm_archives_path:-"$rvm_path/archives"}/$rvm_ruby_package_file.$rvm_archive_extension' | tar xf - -C /tmp/rvm_src_$$" "$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path:-"$rvm_path/src"}/$rvm_ruby_string" result=$? if [[ "$result" -gt 0 ]] ; then "$rvm_path/scripts/log" "error" \ "There has been an error while trying to extract the source. Halting the installation." @@ -1316,11 +1311,12 @@ else rm -rf "${rvm_repos_path:-"$rvm_path/repos"}/$rvm_ruby_string" rvm_ruby_repo_http_url="${rvm_ruby_repo_url//git:/http:/}" - "$rvm_path/scripts/log" "info" "Cloning from $rvm_ruby_repo_url, this may take a while depending on your connection..." + "$rvm_path/scripts/log" "info" \ + "Cloning from $rvm_ruby_repo_url, this may take a while depending on your connection..." git clone --depth 1 "$rvm_ruby_repo_url" "${rvm_repos_path:-"$rvm_path/repos"}/$rvm_ruby_string" result=$? if [[ "$result" -gt 0 ]] ; then @@ -1384,11 +1380,13 @@ __rvm_run "svn.checkout" "svn update -q ${rvm_rev/-r/-r }" fi else rm -rf "${rvm_repos_path:-"$rvm_path/repos"}/$rvm_ruby_string" - __rvm_run "svn.checkout" "svn checkout -q ${rvm_rev/-r/-r } $rvm_ruby_url ${rvm_repos_path:-"$rvm_path/repos"}/$rvm_ruby_string" "Downloading source from ${rvm_ruby_url}." + __rvm_run "svn.checkout" \ + "svn checkout -q ${rvm_rev/-r/-r } $rvm_ruby_url ${rvm_repos_path:-"$rvm_path/repos"}/$rvm_ruby_string" \ + "Downloading source from ${rvm_ruby_url}." fi result=$? if [[ "$result" -gt 0 ]] ; then "$rvm_path/scripts/log" "error" \ @@ -1401,93 +1399,132 @@ rm -rf "${rvm_src_path:-"$rvm_path/src"}/$rvm_ruby_string" cp -R "${rvm_repos_path:-"$rvm_path/repos"}/$rvm_ruby_string" "${rvm_src_path:-"$rvm_path/src"}/$rvm_ruby_string" fi + + return ${result:-0} } __rvm_check_default() { - local default_ruby_interpreter="$(rvm alias show default 2>/dev/null | awk -F"${rvm_gemset_separator:-"@"}" '{print $1}')" + local default_ruby_interpreter current_ruby_interpreter - local current_ruby_interpreter="$(echo "$rvm_ruby_string" | awk -F"${rvm_gemset_separator:-"@"}" '{print $1}')" + default_ruby_interpreter="$(rvm alias show default 2>/dev/null | awk -F"${rvm_gemset_separator:-"@"}" '{print $1}')" + current_ruby_interpreter="$(echo "$rvm_ruby_string" | awk -F"${rvm_gemset_separator:-"@"}" '{print $1}')" + if [[ -n "$current_ruby_interpreter" && "$current_ruby_interpreter" = "$default_ruby_interpreter" ]]; then + __rvm_run_with_env 'default.restore' 'system' 'rvm use system --default' 'Removing default ruby interpreter' + fi + + return $? } __rvm_uninstall_ruby() { + local dir + if [[ ${rvm_ruby_selected_flag} -eq 0 ]] ; then __rvm_select ; fi if [[ -n "${rvm_ruby_string:-""}" ]] ; then for dir in "$rvm_path/rubies" ; do + if [[ -d "$dir/$rvm_ruby_string" ]] ; then + "$rvm_path/scripts/log" "info" "Removing $dir/$rvm_ruby_string..." rm -rf $dir/$rvm_ruby_string + else + "$rvm_path/scripts/log" "info" \ "$dir/$rvm_ruby_string has already been removed." + fi if [[ -e "${rvm_bin_path:-"$rvm_path/bin"}/$rvm_ruby_string" ]] ; then + rm -f "${rvm_bin_path:-"$rvm_path/bin"}/$rvm_ruby_string" + fi - done ; unset dir + done + __rvm_remove_install_record "$rvm_ruby_string" __rvm_remove_gemsets __rvm_check_default else + "$rvm_path/scripts/log" "fail" \ "Cannot uninstall unknown package '$rvm_ruby_string'" + fi unset rvm_uninstall_flag return 0 } __rvm_remove_ruby() { + + local dir + if [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] ; then __rvm_select ; fi if [[ -n "${rvm_ruby_string:-""}" ]] ; then for dir in ${rvm_src_path:-"$rvm_path/src"} $rvm_path/rubies ; do if [[ -d $dir/$rvm_ruby_string ]] ; then + "$rvm_path/scripts/log" "info" "Removing $dir/$rvm_ruby_string..." - rm -rf $dir/$rvm_ruby_string + rm -rf "$dir/$rvm_ruby_string" + else + "$rvm_path/scripts/log" "info" "it seems that $dir/$rvm_ruby_string is already non existent." + fi if [[ -e "${rvm_bin_path:-"$rvm_path/bin"}/$rvm_ruby_string" ]] ; then + rm -f "${rvm_bin_path:-"$rvm_path/bin"}/$rvm_ruby_string" + fi __rvm_check_default - done ; unset dir + done __rvm_remove_install_record "$rvm_ruby_string" __rvm_remove_gemsets __rvm_remove_archives __rvm_remove_aliases __rvm_remove_wrappers __rvm_remove_environments __rvm_remove_binaries + else - "$rvm_path/scripts/log" "fail" "Cannot remove unknown package '$rvm_ruby_string'" - fi ; unset rvm_remove_flag + + "$rvm_path/scripts/log" "fail" \ + "Cannot remove unknown package '$rvm_ruby_string'" + + return 1 + + fi + + unset rvm_remove_flag + + return 0 } __rvm_remove_gemsets() { if [[ ${rvm_gems_flag:-0} -eq 1 ]] ; then "$rvm_path/scripts/log" "info" "Removing $rvm_ruby_string gemsets..." @@ -1583,11 +1620,11 @@ if [[ ${#binaries[@]} -lt 1 ]] ; then binaries=(gem irb erb ri rdoc testrb rake) fi "$rvm_path/scripts/log" "info" \ - "$rvm_ruby_string adjusting #shebangs for ($binaries)." + "$rvm_ruby_string - adjusting #shebangs for ($binaries)." for binary in "${binaries[@]}" ; do if [[ -e "$rvm_ruby_home/bin/$binary" || -e "${rvm_src_path:-"$rvm_path/src"}/$rvm_ruby_string/bin/$binary" ]] ; then @@ -1610,11 +1647,13 @@ binaries=(gem irb erb ri rdoc testrb rake) fi # Import the initial gemsets. - __rvm_run_with_env "gemsets.initial" "$rvm_ruby_string" "'$rvm_path/scripts/gemsets' initial" "$rvm_ruby_string - #importing default gemsets ($rvm_path/gemsets/)" + __rvm_run_with_env "gemsets.initial" "$rvm_ruby_string" \ + "'$rvm_path/scripts/gemsets' initial" \ + "$rvm_ruby_string - #importing default gemsets ($rvm_path/gemsets/)" __rvm_irbrc __rvm_generate_default_docs @@ -1642,13 +1681,13 @@ fi } __rvm_rubygems_setup() { - local result home path dir directory_name version_number ruby_lib_gem_path + local home path dir directory_name version_number ruby_lib_gem_path - if [[ -n "$(echo "$rvm_ruby_version" | awk '/^1\.9/')" ]] || [[ -n "$(echo "$rvm_ruby_interpreter" | awk '/^mput/')" ]] ; then + if [[ -n "$(echo "$rvm_ruby_version" | awk '/^1\.9/')" || -n "$(echo "$rvm_ruby_interpreter" | awk '/^mput/')" ]] ; then install=0 elif [[ "$rvm_ruby_string" = "ruby-head" ]] ; then install=0 @@ -1706,18 +1745,21 @@ elif [[ -n "$(echo "$rvm_ruby_interpreter" | awk '/^rbx|jruby/')" ]] ; then # Hands off rubygems for rbx & jruby if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then - "$rvm_path/scripts/log" "debug" "Skipping rubygems update for $rvm_ruby_version" + "$rvm_path/scripts/log" "debug" \ + "Skipping rubygems update for $rvm_ruby_version" fi ruby_lib_gem_path="$rvm_ruby_home/lib/ruby/gems/jruby" else - "$rvm_path/scripts/log" "info" "$rvm_ruby_string - #rubygems installing to $rvm_ruby_string" + "$rvm_path/scripts/log" "info" \ + "$rvm_ruby_string - #rubygems installing to $rvm_ruby_string" + rvm_rubygems_version="$(__rvm_db "${rvm_ruby_interpreter}_rubygems_version")" rvm_rubygems_version="${rvm_rubygems_version:-"$(__rvm_db "rubygems_version")"}" rvm_rubygems_url=$(__rvm_db "rubygems_${rvm_rubygems_version}_url") rvm_gem_package_name="rubygems-$rvm_rubygems_version" rvm_gem_url="$rvm_rubygems_url/$rvm_gem_package_name.tgz" @@ -1749,12 +1791,13 @@ fi builtin cd "${rvm_src_path:-"$rvm_path/src"}/$rvm_gem_package_name" __rvm_run "rubygems.install" \ - "GEM_PATH="$rvm_ruby_gem_path:$rvm_ruby_global_gems_path" GEM_HOME=$rvm_ruby_gem_home BUNDLE_PATH=$rvm_ruby_gem_home $rvm_ruby_home/bin/ruby ${rvm_src_path:-"$rvm_path/src"}/$rvm_gem_package_name/setup.rb" + "GEM_PATH='$rvm_ruby_gem_path:$rvm_ruby_global_gems_path' GEM_HOME='$rvm_ruby_gem_home' BUNDLE_PATH='$rvm_ruby_gem_home' $rvm_ruby_home/bin/ruby ${rvm_src_path:-"$rvm_path/src"}/$rvm_gem_package_name/setup.rb" result=$? + if [[ $result -gt 0 ]] ; then "$rvm_path/scripts/log" "warning" \ "$rvm_ruby_string - #warning Installation of rubygems $rvm_ruby_package_name did not complete successfully." fi @@ -1786,11 +1829,11 @@ if [[ -s "${rvm_src_path:-"$rvm_path/src"}/$rvm_ruby_string/bin/rake" ]] ; then __rvm_inject_ruby_shebang "${rvm_src_path:-"$rvm_path/src"}/$rvm_ruby_string/bin/rake" fi - return $result + return ${result:-0} } __rvm_inject_ruby_shebang() { local actual_file @@ -1808,17 +1851,17 @@ local actual_file string __rvm_actual_file $1 - if [[ -f "$actual_file" ]] ; then + if [[ -s "$actual_file" ]] ; then - if [[ -n "$(head -n 1 $actual_file | awk '/[j]*ruby/')" ]] ; then + if [[ -n "$(head -n 1 "$actual_file" | awk '/[j]*ruby/')" ]] ; then string="ENV['GEM_HOME']=ENV['GEM_HOME'] || '$rvm_ruby_gem_home'\nENV['GEM_PATH']=ENV['GEM_PATH'] || '$rvm_ruby_gem_path'\nENV['PATH']='$rvm_ruby_gem_home/bin:$rvm_ruby_global_gems_path/bin:$rvm_ruby_home/bin:' + ENV['PATH']\nENV['BUNDLE_PATH']=ENV['BUNDLE_PATH'] || '$rvm_ruby_gem_home'\n" - elif [[ -n "$(head -n 1 $actual_file | awk '/bash/')" ]] ; then + elif [[ -n "$(head -n 1 "$actual_file" | awk '/bash/')" ]] ; then string="GEM_HOME=\${GEM_HOME:-'$rvm_ruby_gem_home'}\nGEM_PATH=\${GEM_PATH:-'$rvm_ruby_gem_home:$rvm_ruby_global_gems_path'}\nPATH=$rvm_ruby_gem_home/bin:$rvm_ruby_global_gems_path/bin:$rvm_ruby_home/bin:\$PATH\nBUNDLE_PATH=\${BUNDLE_PATH:-'$rvm_ruby_gem_home'}\n" fi @@ -1828,23 +1871,26 @@ mv $actual_file.new $actual_file ; chmod +x "$actual_file" fi fi + + return 0 } __rvm_actual_file() { - if [[ -L $1 ]] ; then # If the file is a symlink, + if [[ -L "$1" ]] ; then # If the file is a symlink, actual_file="$(readlink $1)" # read the link target so we can preserve it. else actual_file="$1" fi + return 0 } __rvm_manage_rubies() { local manage_result bin_line