scripts/manage in rvm-1.0.5 vs scripts/manage in rvm-1.0.6

- old
+ new

@@ -13,50 +13,72 @@ fi } # Checks for bison, returns zero iff it is found __rvm_check_for_bison() { + local result + if [[ ${rvm_head_flag:-0} -gt 0 ]]; then - if ! command -v bison >/dev/null ; then - "$rvm_scripts_path/log" "fail" "\nbison is not available in your path. \nPlease ensure bison is installed before compiling from head.\n" - return 1 + command -v bison > /dev/null + result=$? + if [[ $? -gt 0 ]] ; then + "$rvm_scripts_path/log" "fail" \ + "\nbison is not available in your path. \nPlease ensure bison is installed before compiling from head.\n" fi fi + + return $result } # Emits a number of patches to STDOUT, each on a new name # Expands patchsets etc. __rvm_current_patch_names() { # TODO: Lookup default patches on rvm_ruby_string heirarchy. - local separator="%" - local patches="${rvm_patch_names:-""} default" + local separator patches level name + separator="%" + patches="${rvm_patch_names:-""} default" + for patch_name in $(echo ${patches//,/ }); do - local level=1 - local name="$patch_name" + + level=1 + name="$patch_name" + if echo "$name" | grep -q "$separator"; then level="${name/*${separator}/}" name="${name//${separator}*/}" fi + local expanded_name="$(__rvm_expand_patch_name "$name")" + echo "${expanded_name}${separator}${level}" + done + + return 0 } __rvm_apply_patches() { - local patch_result=0 - local patch_level_separator="%" - local patch_fuzziness="25" - local patch_level=1 - local source_directory="${1:-"$rvm_ruby_src_path"}" + + local patches patch_name result patch_level_separator patch_fuzziness patch_level source_directory full_patch_path + + result=0 + patch_level_separator="%" + patch_fuzziness="25" + patch_level=1 + source_directory="${1:-"$rvm_ruby_src_path"}" + ( builtin cd "$source_directory" - patches="$(__rvm_current_patch_names | __rvm_strip)" - for patch_name in $(echo $patches); do + patches=($(__rvm_current_patch_names)) + + for patch_name in "${patches[@]}" ; do + # If set, extract the patch level from the patch name. patch_level=1 + if echo "$patch_name" | \grep -q "$patch_level_separator"; then patch_level=${patch_name//*${patch_level_separator}/} patch_name="${patch_name//${patch_level_separator}*/}" fi @@ -64,140 +86,201 @@ # Expand paths, and for those we found we then apply the patches. if [[ -n "${full_patch_path:-""}" ]]; then if [[ -f "$full_patch_path" ]] ; then + __rvm_run "patch.apply.${patch_name/*\/}" "patch -F$patch_fuzziness -p$patch_level -f <\"$full_patch_path\"" "Applying patch '$patch_name' (located at $full_patch_path)" - # Detect failed patches - [[ $? -gt 0 ]] && patch_result=1 + + [[ $? -gt 0 ]] && result=1 # Detect failed patches fi + else - "$rvm_scripts_path/log" "warn" "Patch '$patch_name' not found." - patch_result=1 + "$rvm_scripts_path/log" "warn" \ + "Patch '$patch_name' not found." + result=1 fi done ) - unset patch_name full_patch_path patch_level - return $patch_result + + return $result } __rvm_install_source() { + + local directory configure_parameters db_configure_flags + [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] && __rvm_select - if [[ "${rvm_ruby_string:-""}" =~ "-head" ]] ; then - # Ensure we have a base ruby. - __rvm_ensure_has_18_compat_ruby || return 1 - fi + case ${rvm_ruby_string:-""} in + *-head) __rvm_ensure_has_18_compat_ruby || return 1 ;; + esac "$rvm_scripts_path/log" "info" "\nInstalling Ruby from source to: $rvm_ruby_home, this may take a while depending on your cpu(s)...\n" builtin cd "$rvm_src_path" if [[ ${rvm_force_flag:-0} -eq 1 ]] ; then + for directory in "$rvm_ruby_home" "$rvm_ruby_src_path" ; do - [[ -d "$directory" ]] && rm -rf "$directory" + + if [[ -d "$directory" ]] ; then + rm -rf "$directory" + fi + done fi result=0 + __rvm_fetch_ruby - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error fetching the ruby interpreter. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error fetching the ruby interpreter. Aborting the installation." + return $result fi builtin cd "$rvm_ruby_src_path" result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error, source directory is missing. Did the download or extraction fail? Aborting the installation." ; return $result + "$rvm_scripts_path/log" "error" \ + "Source directory is missing. Did the download or extraction fail? Aborting the installation." + return $result fi if [[ -d "${rvm_path}/usr" ]] ; then export PATH="${rvm_path}/usr/bin:${PATH}" + builtin hash -r fi __rvm_apply_patches result="$?" + if [[ "$result" -gt 0 ]]; then - "$rvm_scripts_path/log" "fail" "There has been an error applying the specified patches. Aborting the installation." + "$rvm_scripts_path/log" "fail" \ + "There has been an error applying the specified patches. Aborting the installation." return $result fi - if [[ -z "${rvm_ruby_configure:-""}" ]] && [[ ! -s "$rvm_ruby_src_path/configure" ]] ; then + if [[ -z "${rvm_ruby_configure:-""}" && ! -s "$rvm_ruby_src_path/configure" ]] ; then + if command -v autoconf > /dev/null ; then + __rvm_run "autoconf" "autoconf" "Running autoconf" + else - result=$? ; "$rvm_scripts_path/log" "fail" "rvm requires autoconf to install the selected ruby interpreter however autoconf was not found in the PATH." ; return $result + "$rvm_scripts_path/log" "fail" \ + "rvm requires autoconf to install the selected ruby interpreter however autoconf was not found in the PATH." + return 1 fi fi if [[ -n "${rvm_ruby_configure:-""}" ]] ; then + __rvm_run "configure" "$rvm_ruby_configure" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while configuring. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while configuring. Aborting the installation." + return $result fi + elif [[ -s ./configure ]] ; then + # REE stores configure flags differently for head vs. the distributed release. - if [[ "ree" != "$rvm_ruby_interpreter" ]]; then + if [[ "ree" != "${rvm_ruby_interpreter:-""}" ]]; then __rvm_db "${rvm_ruby_interpreter}_configure_flags" "db_configure_flags" fi # On 1.9.2, we manually set the --with-baseruby option # to point to an expanded path. if [[ "${rvm_ruby_string:-""}" = "ruby-1.9.2-head" ]] ; then + local compatible_baseruby="$rvm_wrappers_path/$(__rvm_18_compat_ruby)/ruby" + if [[ -x "$compatible_baseruby" ]] ; then configure_parameters="--with-baseruby=$compatible_baseruby" fi fi - local configure_command="./configure --prefix=$rvm_ruby_home ${db_configure_flags:-""} ${rvm_ruby_configure_flags:-""} ${configure_parameters:-""}" + local configure_command="./configure --prefix=$rvm_ruby_home ${db_configure_flags:-""} ${rvm_configure_flags:-""} ${configure_parameters:-""}" + __rvm_run "configure" "$configure_command" "#configuring $rvm_ruby_string" - unset configure_parameters db_configure_flags - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while running configure. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while running configure. Aborting the installation." + return $result fi + else - "$rvm_scripts_path/log" "error" "Skipping configure step, 'configure' does not exist, did autoconf not run successfully?" + "$rvm_scripts_path/log" "error" \ + "Skipping configure step, 'configure' does not exist, did autoconf not run successfully?" fi rvm_ruby_make=${rvm_ruby_make:-"make"} + __rvm_run "make" "$rvm_ruby_make ${rvm_make_flags:-""}" "#compiling $rvm_ruby_string" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while running make. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while running make. Aborting the installation." + return $result fi - if [[ -d .ext/rdoc ]] ; then \rm -rf .ext/rdoc ; fi + if [[ -d .ext/rdoc ]] ; then + rm -rf .ext/rdoc + fi rvm_ruby_make_install=${rvm_ruby_make_install:-"make install"} + __rvm_run "install" "$rvm_ruby_make_install" "#installing $rvm_ruby_string" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while running make install. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while running make install. Aborting the installation." + return $result fi export GEM_HOME="$rvm_ruby_gem_home" export GEM_PATH="$rvm_ruby_gem_path" export BUNDLE_PATH="$rvm_ruby_gem_home" __rvm_rubygems_setup + __rvm_bin_script + __rvm_run "chmod.bin" "chmod +x $rvm_ruby_home/bin/*" + __rvm_post_install - "$rvm_scripts_path/log" "info" "#complete install of $rvm_ruby_string" + "$rvm_scripts_path/log" "info" \ + "#complete install of $rvm_ruby_string" + + return 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 # Check for clang if the flag is set __rvm_check_for_clang - local result="$?" + result="$?" + [[ $result -gt 0 ]] && return $result case "$rvm_ruby_interpreter" in macruby) if [[ "Darwin" = "$(uname)" ]] ; then @@ -211,41 +294,69 @@ macruby_path="/usr/local/bin" # TODO: configure & make variables should be set here. rvm_ruby_configure=" true " rvm_ruby_make="rake" rvm_ruby_make_install="sudo rake install" + __rvm_db "${rvm_ruby_interpreter}_repo_url" "rvm_ruby_url" + rvm_ruby_repo_url=$rvm_ruby_url + __rvm_install_source $* - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to install from source. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to install from source. Aborting the installation." + return $result fi elif [[ "nightly" = "$rvm_ruby_version" ]] ; then macruby_path="/Library/Frameworks/MacRuby.framework/Versions/0.6/usr/bin" # TODO: Separated nightly from head. + "$rvm_scripts_path/log" "info" "Retrieving the latest nightly macruby build..." + "$rvm_scripts_path/fetch" "$rvm_ruby_url" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to fetch the source. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to fetch the source. Aborting the installation." + return $result fi + mv "$rvm_archives_path/macruby_nightly-latest.pkg" "$rvm_archives_path/macruby_nightly.pkg" + __rvm_run "macruby/extract" "sudo /usr/sbin/installer -pkg '$rvm_archives_path/macruby_nightly.pkg' -target '/'" + mkdir -p "$rvm_ruby_home/bin" else macruby_path="/Library/Frameworks/MacRuby.framework/Versions/${rvm_ruby_version}/usr/bin" + # TODO: Separated nightly from head. "$rvm_scripts_path/log" "info" "Retrieving MacRuby ${rvm_ruby_version} ..." + "$rvm_scripts_path/fetch" "$rvm_ruby_url" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to fetch the source. Aborting the installation." ; return $result + + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to fetch the source. Aborting the installation." + return $result fi + mkdir -p $rvm_ruby_src_path + unzip -o -j "$rvm_archives_path/$rvm_ruby_package_file" "MacRuby ${rvm_ruby_version}/MacRuby ${rvm_ruby_version}.pkg" -d "$rvm_ruby_src_path" + mv "$rvm_ruby_src_path/MacRuby ${rvm_ruby_version}.pkg" "$rvm_ruby_src_path/$rvm_ruby_string.pkg" + __rvm_run "macruby/extract" "sudo /usr/sbin/installer -pkg '$rvm_ruby_src_path/$rvm_ruby_string.pkg' -target '/'" + mkdir -p "$rvm_ruby_home/bin" fi binaries=(erb gem irb rake rdoc ri ruby testrb) for binary_name in ${binaries[@]}; do @@ -261,21 +372,29 @@ exec "$macruby_path/mac$binary_name" "$prefix" "\$@" RubyWrapper ) file_name="$rvm_ruby_home/bin/$binary_name" - rm -f "$file_name" + + if [[ -f "$file_name" ]] ; then + rm -f "$file_name" + fi + echo "$ruby_wrapper" > "$file_name" - if [[ -f "$file_name" ]] ; then chmod +x $file_name ; fi + + if [[ -f "$file_name" ]] ; then + chmod +x $file_name + fi + if [[ "$binary_name" = "ruby" ]] ; then echo "$ruby_wrapper" > "$rvm_bin_path/$rvm_ruby_string" fi - unset file_name ruby_wrapper binary_name files prefix done __rvm_irbrc else - "$rvm_scripts_path/log" "fail" "MacRuby can only be installed on a Darwin OS." + "$rvm_scripts_path/log" "fail" \ + "MacRuby can only be installed on a Darwin OS." fi ;; ree) if [[ -n "$(echo "$rvm_ruby_version" | awk '/^1\.8/')" ]] && [[ $rvm_head_flag -eq 0 ]] ; then @@ -283,193 +402,287 @@ rvm_ruby_url="$(__rvm_db "ree_${rvm_ruby_version}_url")/$rvm_ruby_package_file.tar.gz" "$rvm_scripts_path/log" "info" "Installing Ruby Enterprise Edition from source to: $rvm_ruby_home" builtin cd "$rvm_src_path" + if [[ ${rvm_force_flag:-0} -eq 0 && -d "$rvm_ruby_src_path" && ! -x "$rvm_ruby_src_path/installer" ]] ; then - "$rvm_scripts_path/log" "It appears that the archive has already been extracted. Skipping extract (use --force to force re-download and extract)." + "$rvm_scripts_path/log" \ + "It appears that the archive has already been extracted. Skipping extract (use --force to force re-download and extract)." + else "$rvm_scripts_path/log" "#fetching $rvm_ruby_package_file" "$rvm_scripts_path/fetch" "$rvm_ruby_url" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to fetch the source. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to fetch the source. Aborting the installation." + return $result fi rm -rf "$rvm_ruby_src_path" + __rvm_run "extract" "gunzip < \"$rvm_archives_path/$rvm_ruby_package_file.$rvm_archive_extension\" | tar xf - -C $rvm_src_path" "#extracting $rvm_ruby_package_file to $rvm_ruby_src_path" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to extract the source. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to extract the source. Aborting the installation." + return $result fi mv "$rvm_src_path/$rvm_ruby_package_file" "$rvm_ruby_src_path" fi builtin cd "$rvm_ruby_src_path" + # wait, what? v v v TODO: Investigate line smell. mkdir -p "${rvm_ruby_home}/lib/ruby/gems/1.8/gems" - if [[ -n "$rvm_ruby_configure_flags" ]] ; then - rvm_ruby_configure_flags="${rvm_ruby_configure_flags//--/-c --}" + + if [[ -n "$rvm_configure_flags" ]] ; then + rvm_configure_flags="${rvm_configure_flags//--/-c --}" fi - if [[ "Darwin" = "$(uname)" ]] && [[ "1.8.6" = "$rvm_ruby_version" ]] && [[ -z "$rvm_ree_options" ]] ; then + if [[ "Darwin" = "$(uname)" && "1.8.6" = "$rvm_ruby_version" && -z "$rvm_ree_options" ]] ; then rvm_ree_options="${rvm_ree_options} --no-tcmalloc" fi __rvm_db "${rvm_ruby_interpreter}_configure_flags" "db_configure_flags" __rvm_apply_patches "$rvm_ruby_src_path/source" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to apply patches to ree. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to apply patches to ree. Aborting the installation." + return $result fi - __rvm_run "install" "./installer -a $rvm_rubies_path/$rvm_ruby_string $rvm_ree_options $db_configure_flags $rvm_ruby_configure_flags" "#installing $rvm_ruby_string" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to run the ree installer. Aborting the installation." ; return $result + __rvm_run "install" "./installer -a $rvm_rubies_path/$rvm_ruby_string $rvm_ree_options $db_configure_flags $rvm_configure_flags" "#installing $rvm_ruby_string" + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to run the ree installer. Aborting the installation." + return $result fi chmod +x "$rvm_ruby_home"/bin/* __rvm_rubygems_setup __rvm_irbrc __rvm_bin_script __rvm_post_install else + __rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_version}_repo_url" "rvm_ruby_url" + if [[ -z "$rvm_ruby_url" ]] ; then "$rvm_scripts_path/log" "fail" "rvm does not know the rvm repo url for '${rvm_ruby_interpreter}_${rvm_ruby_version}'" result=1 + else rvm_ruby_repo_url="$rvm_ruby_url" if [[ ${rvm_make_flags_flag:-0} -eq 1 ]] ; then __rvm_make_flags ; fi __rvm_install_source $* fi fi ;; rbx|rubinius) + "$rvm_scripts_path/log" "info" "#dependency installation" # Ensure we have a 1.8.7 compatible ruby installed. __rvm_ensure_has_18_compat_ruby || return 1 + # TODO: use 'rvm gems load' here: unset CFLAGS LDFLAGS ARCHFLAGS # Important. unset BUNDLE_PATH GEM_HOME GEM_PATH MY_RUBY_HOME IRBRC + __rvm_remove_rvm_from_path + __rvm_conditionally_add_bin_path ; export PATH + builtin hash -r if [[ -n "$(echo $rvm_ruby_version | awk '/^1\.0/')" ]] && [[ $rvm_head_flag -eq 0 ]] ; then + "$rvm_scripts_path/log" "info" "#downloading $rvm_ruby_package_file, this may take a while depending on your connection..." + "$rvm_scripts_path/fetch" "$rvm_ruby_url" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to fetch the source. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to fetch the source. Aborting the installation." + return $result fi - __rvm_run "extract" "gunzip < \"$rvm_archives_path/$(basename $rvm_ruby_package_file)\" | tar xf - -C $rvm_src_path" "Extracting $rvm_ruby_package_file ..." + __rvm_run "extract" \ + "gunzip < \"$rvm_archives_path/$(basename $rvm_ruby_package_file)\" | tar xf - -C $rvm_src_path" "Extracting $rvm_ruby_package_file ..." + result=$? - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to extract the source. Aborting the installation." ; return $result + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to extract the source. Aborting the installation." + return $result fi # Remove the left over folder first. rm -rf "$rvm_ruby_src_path" + mv "$rvm_src_path/rubinius-${rvm_ruby_version}" "$rvm_ruby_src_path" else __rvm_db "rubinius_repo_url" "rvm_ruby_repo_url" #rvm_ruby_home="$rvm_rubies_path/$rvm_ruby_interpreter-$rvm_ruby_version" __rvm_fetch_from_github "rbx" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while fetching the rbx git repo. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while fetching the rbx git repo. Aborting the installation." + return $result fi fi - builtin cd "$rvm_ruby_src_path" ; chmod +x ./configure + builtin cd "$rvm_ruby_src_path" + chmod +x ./configure + __rvm_apply_patches - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to apply patches to rubinius. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to apply patches to rubinius. Aborting the installation." + return $result fi __rvm_db "${rvm_ruby_interpreter}_configure_flags" "db_configure_flags" export ruby="$(__rvm_18_compat_ruby)" - rvm_ruby_configure_flags="${rvm_ruby_configure_flags:-"--skip-system"}" - rvm_ruby_configure="$rvm_bin_path/$ruby configure --prefix=$rvm_ruby_home $db_configure_flags $rvm_ruby_configure_flags" ; message="Configuring rbx" + rvm_configure_flags="${rvm_configure_flags:-"--skip-system"}" + + rvm_ruby_configure="$rvm_bin_path/$ruby configure --prefix=$rvm_ruby_home $db_configure_flags $rvm_configure_flags" ; message="Configuring rbx" + if [[ "$rvm_llvm_flag" = "0" ]] ; then rvm_ruby_configure="$rvm_ruby_configure --disable-llvm" + else if [[ "$rvm_ruby_patch_level" = "rc1" ]] ; then rvm_ruby_configure="$rvm_ruby_configure --enable-llvm" fi fi + __rvm_run "configure" "$rvm_ruby_configure" "$message" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while running '$rvm_ruby_configure'. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while running '$rvm_ruby_configure'. Aborting the installation." + return $result fi if [[ "$rvm_trace_flag" -eq 1 ]] ; then rvm_ruby_make="$rvm_wrappers_path/$ruby/rake install --trace" ; message="Compiling rbx (with --trace)" else rvm_ruby_make="$rvm_wrappers_path/$ruby/rake install" ; message="Compiling rbx" fi + __rvm_run "rake" "$rvm_ruby_make" "$message" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while running '$rvm_ruby_configure'. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while running '$rvm_ruby_configure'. Aborting the installation." + return $result fi ; unset ruby # Symlink rubinius wrappers ln -fs "$rvm_ruby_home/bin/rbx" "$rvm_ruby_home/bin/ruby" # Install IRB Wrapper on Rubinius. file_name="$rvm_ruby_home/bin/irb" + rm -f "$file_name" + printf '#!/usr/bin/env bash\n' > "$file_name" + printf "exec '$rvm_ruby_home/bin/rbx' 'irb' \"\$@\"\n" >> "$file_name" + [[ -f "$file_name" ]] && chmod +x "$file_name" # Install Gem Wrapper on Rubinius. file_name="$rvm_ruby_home/bin/gem" + cp -f "$rvm_ruby_home/lib/bin/gem.rb" "$file_name" + __rvm_inject_ruby_shebang "$file_name" - [[ -f "$file_name" ]] && chmod +x "$file_name" + + if [[ -f "$file_name" ]] ; then + chmod +x "$file_name" + fi + unset file_name - binaries="erb ri rdoc" + binaries=(erb ri rdoc) + __rvm_post_install + __rvm_irbrc + __rvm_bin_script ;; jruby) + if ! command -v java > /dev/null; then printf "java must be installed and in your path in order to install JRuby." ; return 1 fi builtin cd "$rvm_src_path" __rvm_fetch_ruby - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to fetch the source. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to fetch the source. Aborting the installation." + return $result fi builtin cd "$rvm_ruby_src_path" - if [[ $rvm_head_flag -eq 1 ]] ; then __rvm_run "ant.dist" "ant dist" "#ant dist" ; fi - mkdir -p "$rvm_ruby_home/bin/" - if "$rvm_scripts_path/match" "$rvm_ruby_version" "1\.3" || "$rvm_scripts_path/match" "$rvm_ruby_version" "1\.2" ; then - __rvm_run "nailgun" "builtin cd \"$rvm_ruby_src_path/tool/nailgun\" && make $rvm_make_flags" "Building Nailgun" - else - __rvm_run "nailgun" "builtin cd \"$rvm_ruby_src_path/tool/nailgun\" && ./configure --prefix=$rvm_ruby_home && make $rvm_make_flags" "Building Nailgun" + if [[ ${rvm_head_flag:-0} -eq 1 ]] ; then + __rvm_run "ant.dist" "ant dist" "#ant dist" fi - if [[ -z "${rvm_ruby_home:-""}" || "$rvm_ruby_home" = "/" ]] ; then echo "WTH?!?! rvm_ruby_home == / ??? not removing." ; return 1000000 ; fi + mkdir -p "$rvm_ruby_home/bin/" + case "$rvm_ruby_version" in + 1.3|1.2) + __rvm_run "nailgun" \ + "builtin cd \"$rvm_ruby_src_path/tool/nailgun\" && make $rvm_make_flags" "Building Nailgun" + ;; + *) + __rvm_run "nailgun" \ + "builtin cd \"$rvm_ruby_src_path/tool/nailgun\" && ./configure --prefix=$rvm_ruby_home && make $rvm_make_flags" "Building Nailgun" + ;; + esac + + if [[ -z "${rvm_ruby_home:-""}" || "$rvm_ruby_home" = "/" ]] ; then + echo "WTH?!?! rvm_ruby_home == / ??? not removing." ; return 1000000 + fi + rm -rf "$rvm_ruby_home" + __rvm_run "install" "/bin/cp -Rf $rvm_ruby_src_path $rvm_ruby_home" "#installing JRuby to $rvm_ruby_home" ( builtin cd "$rvm_ruby_home/bin/" for binary in jirb jruby jgem ; do @@ -480,91 +693,126 @@ # -server is "a lot slower for short-lived scripts like rake tasks, and takes longer to load" #sed -e 's#^JAVA_VM=-client#JAVA_VM=-server#' $rvm_ruby_home/bin/jruby > $rvm_ruby_home/bin/jruby.new && # mv $rvm_ruby_home/bin/jruby.new $rvm_ruby_home/bin/jruby chmod +x "$rvm_ruby_home/bin/jruby" - for binary in jrubyc jirb_swing jirb jgem rdoc ri spec autospec testrb ast generate_yaml_index.rb ; do + binaries=(jrubyc jirb_swing jirb jgem rdoc ri spec autospec testrb ast generate_yaml_index.rb) + for binary in "${binaries[@]}" ; do __rvm_inject_gem_env "$rvm_ruby_home/bin/$binary" - done ; unset binary + done __rvm_inject_ruby_shebang "$rvm_ruby_home/bin/rake" __rvm_rubygems_setup + __rvm_irbrc + __rvm_bin_script + __rvm_use __rvm_post_install # jruby ships with some built in gems, copy them in to place. if [[ -d "$rvm_ruby_home/lib/ruby/gems/1.8" ]]; then + "$rvm_scripts_path/log" "info" "Copying across included gems" + cp -R "$rvm_ruby_home/lib/ruby/gems/1.8/" "$GEM_HOME/" fi ;; maglev) __rvm_ensure_has_18_compat_ruby "$rvm_scripts_path/log" "info" "Running MagLev prereqs checking script." + "$rvm_scripts_path/maglev" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "Prerequisite checks have failed. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "Prerequisite checks have failed. Aborting the installation." + return $result fi builtin cd "$rvm_src_path" if [[ ! -d "$rvm_src_path/$rvm_ruby_string" || ${rvm_force_flag:-0} -eq 1 ]] ; then + rm -rf "$rvm_src_path/$rvm_ruby_string/" "$rvm_src_path/$rvm_ruby_string/" + __rvm_fetch_ruby - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to fetch the source. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to fetch the source. Aborting the installation." + return $result fi fi - if [[ $rvm_head_flag -eq 1 ]] ; then + if [[ ${rvm_head_flag:-0} -eq 1 ]] ; then + builtin cd "$rvm_ruby_src_path" + rvm_gemstone_package_file="GemStone-$(\grep ^GEMSTONE version.txt | cut -f2 -d-).$(uname -sm | \tr ' ' '-')" + rvm_gemstone_url="${rvm_gemstone_url:-"$maglev_url/${rvm_gemstone_package_file}.${rvm_archive_extension}"}" fi "$rvm_scripts_path/log" "info" "Downloading the GemStone package, this may take a while depending on your connection..." "$rvm_scripts_path/fetch" "$rvm_gemstone_url" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to fetch the GemStone package. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to fetch the GemStone package. Aborting the installation." + return $result fi builtin cd "$rvm_src_path" + if [[ -s "$rvm_ruby_package_file" ]] ; then mv "$rvm_ruby_package_file" "$rvm_ruby_src_path" fi builtin cd "$rvm_ruby_src_path" __rvm_run "gemstone.extract" "gunzip < \"$rvm_archives_path/${rvm_gemstone_package_file}.${rvm_archive_extension}\" | tar xf - -C $rvm_ruby_src_path" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to extract the GemStone package. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to extract the GemStone package. Aborting the installation." + return $result fi - chmod -R 777 "$rvm_gemstone_package_file" # for now. + chmod -R 777 "$rvm_gemstone_package_file" # for now. # WTF?! Crack.smoke!(:huff) + ln -nfs "$rvm_gemstone_package_file" "gemstone" - if [[ -z "$rvm_ruby_home" ]] || [[ "$rvm_ruby_home" = "/" ]] ; then echo "WTH?!?! rvm_ruby_home == / ??? not removing." ; return 1000000 ; fi - rm -rf $rvm_ruby_home + if [[ -z "${rvm_ruby_home:-""}" || "$rvm_ruby_home" = "/" ]] ; then + echo "WTH?!?! rvm_ruby_home == / ??? not removing." ; return 1000000 + else + rm -rf $rvm_ruby_home + fi + __rvm_run "install" "/bin/cp -Rf $rvm_ruby_src_path $rvm_ruby_home" "Installing maglev to $rvm_ruby_home" ( builtin cd "$rvm_ruby_home/bin/" for binary in maglev-irb maglev-ruby maglev-gem ; do ln -nfs "$binary" "${binary#maglev-}" done ; unset binary ) - for binary in maglev-ruby maglev-irb maglev-gem ; do + binaries=(maglev-ruby maglev-irb maglev-gem) + for binary in "${binaries[@]}" ; do __rvm_inject_gem_env "$rvm_ruby_home/bin/$binary" - done ; unset binary + done builtin cd "$rvm_ruby_home" if [[ $rvm_head_flag -eq 1 ]] ; then git submodule update --init "$rvm_ruby_home/bin/maglev" force-reload @@ -589,25 +837,32 @@ unset compatible_ruby # TODO: Figure out if anything needs to be done with rubygems. #__rvm_rubygems_setup __rvm_irbrc + __rvm_bin_script + __rvm_use ;; ironruby|ir) if ! command -v mono > /dev/null ; then printf "mono must be installed and in your path in order to install IronRuby." ; return 1 fi if [[ $rvm_head_flag -eq 1 ]] ; then + mono_version="$(mono -V | head -n 1 | cut -d ' ' -f5)" + if "$rvm_scripts_path/match" "$mono_version" "([0-9]+)\.([0-9]+)\.?([0-9]+)?" ; then + mono_major_ver="$(echo "$mono_version" | cut -d '.' -f1)" + mono_minor_ver="$(echo "$mono_version" | cut -d '.' -f2)" - if [[ $mono_major_ver -lt 2 ]] || ( [[ $mono_major_ver -eq 2 ]] && [[ $mono_minor_ver -lt 6 ]] ) ; then + + if [[ $mono_major_ver -lt 2 ]] || ( [[ $mono_major_ver -eq 2 && $mono_minor_ver -lt 6 ]] ) ; then printf "Mono 2.6 (or greater) must be installed and in your path in order to build IronRuby from the repository." printf "Version detected: ${mono_version}" return 1 fi else @@ -616,11 +871,13 @@ fi __rvm_ensure_has_18_compat_ruby __rvm_fetch_ruby + if [[ $? -gt 0 ]] ; then result=$? ; return $result ; fi + builtin cd "$rvm_ruby_src_path" compatible_ruby="$(__rvm_18_compat_ruby)" "$rvm_wrappers_path/$compatible_ruby/gem" install pathname2 --no-rdoc --no-ri @@ -656,11 +913,11 @@ cp -Rf "$rvm_src_path/$rvm_ruby_string/$dir" "$rvm_ruby_home/$dir" done fi binaries=(gem irb rdoc rake ri ruby) - for binary_name in ${binaries[@]} ; do + for binary_name in "${binaries[@]}" ; do if [[ -s "$rvm_ruby_home/bin/$binary_name" ]] ; then tr -d '\r' < "$rvm_ruby_home/bin/$binary_name" > "$rvm_ruby_home/bin/$binary_name.new" #sed -e '1,1s=.*=#!'"/usr/bin/env ir=" "$rvm_ruby_home/bin/$binary_name" > "$rvm_ruby_home/bin/$binary_name.new" mv -f "$rvm_ruby_home/bin/$binary_name.new" "$rvm_ruby_home/bin/$binary_name" chmod +x "$rvm_ruby_home/bin/$binary_name" @@ -674,86 +931,126 @@ builtin hash -r __rvm_run "gems.install" "PATH=$rvm_ruby_gem_home/bin:$rvm_ruby_global_gems_path/bin:$rvm_ruby_home/bin:$PATH GEM_HOME=$rvm_ruby_gem_home GEM_PATH=$rvm_ruby_gem_home $rvm_ruby_home/bin/gem install --no-rdoc --no-ri rake $rvm_gem_options" "Installing $rvm_gem_name to $dir" ;; mput|shyouhei) + if [[ ${rvm_make_flags_flag:-0} -eq 1 ]] ; then __rvm_make_flags ; fi + unset BUNDLE_PATH GEM_HOME GEM_PATH MY_RUBY_HOME IRBRC + __rvm_remove_rvm_from_path + __rvm_conditionally_add_bin_path ; export PATH + builtin hash -r rvm_ruby_home="$rvm_rubies_path/$rvm_ruby_interpreter-$rvm_ruby_version" __rvm_fetch_from_github "mput" "trunk" __rvm_apply_patches - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to apply patches to mput. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to apply patches to mput. Aborting the installation." + return $result fi if [[ ! -s "$rvm_ruby_src_path/configure" ]] ; then + if command -v autoconf &> /dev/null ; then + __rvm_run "autoconf" "autoconf" "Running autoconf" + else - result=$?; "$rvm_scripts_path/log" "fail" "rvm expects autoconf to install this ruby interpreter, autoconf was not found in PATH. Aborting installation." ; return $result + "$rvm_scripts_path/log" "fail" \ + "rvm expects autoconf to install this ruby interpreter, autoconf was not found in PATH. Aborting installation." + return $result fi fi if [[ -s ./Makefile ]] && [[ -z "$rvm_reconfigure_flag" ]] ; then - if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then - "$rvm_scripts_path/log" "debug" "Skipping configure step, Makefile exists so configure must have already been run." - fi + + if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then + "$rvm_scripts_path/log" "debug" "Skipping configure step, Makefile exists so configure must have already been run." + fi + elif [[ -n "$rvm_ruby_configure" ]] ; then + __rvm_run "configure" "$rvm_ruby_configure" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to configure the source. Aborting the installation." ; return $result - fi + result=$? + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to configure the source. Aborting the installation." + return $result + fi + elif [[ -s ./configure ]] ; then - local configure_command="./configure --prefix=$rvm_ruby_home $rvm_ruby_configure_flags" - __rvm_run "configure" "" "Configuring $rvm_ruby_string using $rvm_ruby_configure_flags, this may take a while depending on your cpu(s)..." - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to configure the source. Aborting the installation." ; return $result - fi - else - "$rvm_scripts_path/log" "error" "Skipping configure step, 'configure' script does not exist, did autoconf not run successfully?" + local configure_command="./configure --prefix=$rvm_ruby_home $rvm_configure_flags" + + __rvm_run "configure" "" "Configuring $rvm_ruby_string using $rvm_configure_flags, this may take a while depending on your cpu(s)..." + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to configure the source. Aborting the installation." + return $result fi + else + "$rvm_scripts_path/log" "error" \ + "Skipping configure step, 'configure' script does not exist, did autoconf not run successfully?" + fi + rvm_ruby_make=${rvm_ruby_make:-"make"} + __rvm_run "make" "$rvm_ruby_make $rvm_make_flags" "Compiling $rvm_ruby_string, this may take a while depending on your cpu(s)..." - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to run make. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to run make. Aborting the installation." + return $result fi rvm_ruby_make_install=${rvm_ruby_make_install:-"make install"} + __rvm_run "install" "$rvm_ruby_make_install" "Installing $rvm_ruby_string" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to run make install. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to run make install. Aborting the installation." + return $result fi "$rvm_scripts_path/log" "info" "Installation of $rvm_ruby_string is complete." export GEM_HOME="$rvm_ruby_gem_home" export GEM_PATH="$rvm_ruby_gem_path" export BUNDLE_PATH="$rvm_ruby_gem_home" __rvm_rubygems_setup + __rvm_bin_script + __rvm_run "chmod.bin" "chmod +x $rvm_ruby_home/bin/*" + __rvm_post_install ;; ruby) + __rvm_check_for_bison # && Run like hell... - result=$? ; if [[ "$result" -gt 0 ]] ; then return $result ; fi + if [[ $? -gt 0 ]] ; then return $result ; fi + if [[ ${rvm_make_flags_flag:-0} -eq 1 ]] ; then __rvm_make_flags ; fi - ( - __rvm_install_source $* - ) - + ( __rvm_install_source $* ) result=$? ;; default) "$rvm_scripts_path/log" "fail" "must specify a ruby interpreter to install." @@ -763,89 +1060,140 @@ esac rvm_hook="after_install" ; source "$rvm_scripts_path/hook" - if [[ -n "$ruby_options" ]] ; then RUBYOPT="$ruby_options" ; export RUBYOPT ; fi + if [[ -n "$ruby_options" ]] ; then + RUBYOPT="$ruby_options" + export RUBYOPT + fi return $result } __rvm_fetch_from_github() { rm -rf "$rvm_ruby_src_path" + if [[ ! -d "$rvm_ruby_repo_path/.git" ]] ; then + rm -rf "$rvm_ruby_repo_path" + builtin cd "$rvm_home" + __rvm_run "$1.repo" "git clone --depth 1 $rvm_ruby_repo_url $rvm_ruby_repo_path" "Cloning $rvm_ruby_repo_url" - result=$? ; if [[ "$result" -gt 0 ]] ; then + result=$? + + if [[ "$result" -gt 0 ]] ; then rvm_ruby_repo_http_url="${rvm_ruby_repo_url//git:/http:}" + "$rvm_scripts_path/log" "info" "Could not fetch $rvm_ruby_repo_url - trying $rvm_ruby_repo_http_url" + __rvm_run "$1.repo" "git clone --depth 1 $rvm_ruby_repo_http_url $rvm_ruby_repo_path" "Cloning $rvm_ruby_repo_http_url" fi else local branch="${2:-"master"}" + builtin cd "$rvm_ruby_repo_path" + __rvm_run "$1.repo" "git pull origin $branch" "Pulling from origin $branch" fi + __rvm_run "$1.copy" "\\cp -R \"$rvm_ruby_repo_path\" \"$rvm_ruby_src_path\"" "Copying from repo to source..." + builtin cd "$rvm_ruby_src_path" } __rvm_fetch_ruby() { - [[ -z "$rvm_ruby_selected_flag" ]] && __rvm_select + [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] && __rvm_select + "$rvm_scripts_path/log" "info" "#fetching ${rvm_ruby_string}" if [[ ${rvm_head_flag:-0} -eq 0 && -z "${rvm_ruby_tag:-""}" && -z "${rvm_ruby_revision:-""}" ]] ; then + rvm_ruby_package_name="${rvm_ruby_package_name:-"$rvm_ruby_string"}" + rvm_ruby_package_file="${rvm_ruby_package_file:-"$rvm_ruby_package_name"}" + if [[ "ruby" = "$rvm_ruby_interpreter" ]]; then rvm_archive_extension="${rvm_archive_extension:-tar.bz2}" else rvm_archive_extension="${rvm_archive_extension:-tar.gz}" fi if [[ ! -s "$rvm_archives_path/$rvm_ruby_package_file.$rvm_archive_extension" ]] ; then - if [[ "ruby" = "$rvm_ruby_interpreter" ]] ; then - rvm_ruby_url="$(__rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_release_version}.${rvm_ruby_major_version}_url")/$rvm_ruby_package_file.$rvm_archive_extension" - elif [[ "ree" = "$rvm_ruby_interpreter" ]] ; then - rvm_ruby_url="$(__rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_version}_url")/${rvm_ruby_package_file}.${rvm_archive_extension}" - elif [[ "jruby" = "$rvm_ruby_interpreter" ]] ; then - rvm_ruby_url="$(__rvm_db "${rvm_ruby_interpreter}_url")/${rvm_ruby_version}/${rvm_ruby_package_file}.${rvm_archive_extension}" - elif [[ "maglev" = "$rvm_ruby_interpreter" ]] ; then - : # Should already be set from selector - else - rvm_ruby_url="$(__rvm_db "${rvm_ruby_interpreter}_url")/${rvm_ruby_package_file}.${rvm_archive_extension}" - fi - "$rvm_scripts_path/log" "info" "Downloading ${rvm_ruby_package_file}, this may take a while depending on your connection..." + + case "$rvm_ruby_interpreter" in + ruby) + rvm_ruby_url="$(__rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_release_version}.${rvm_ruby_major_version}_url")/$rvm_ruby_package_file.$rvm_archive_extension" + ;; + ree) + rvm_ruby_url="$(__rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_version}_url")/${rvm_ruby_package_file}.${rvm_archive_extension}" + ;; + jruby) + rvm_ruby_url="$(__rvm_db "${rvm_ruby_interpreter}_url")/${rvm_ruby_version}/${rvm_ruby_package_file}.${rvm_archive_extension}" + ;; + maglev) + : # Should already be set from selector + ;; + *) + rvm_ruby_url="$(__rvm_db "${rvm_ruby_interpreter}_url")/${rvm_ruby_package_file}.${rvm_archive_extension}" + ;; + esac + + "$rvm_scripts_path/log" "info" "#downloading ${rvm_ruby_package_file}, this may take a while depending on your connection..." + "$rvm_scripts_path/fetch" "${rvm_ruby_url}" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to fetch the source. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to fetch the source. Aborting the installation." + return $result fi fi if [[ ! -d "$rvm_ruby_src_path" || ${rvm_force_flag:-0} -eq 1 ]] ; then - rm -rf "$rvm_ruby_src_path" # Especially when forced, we want to ensure the destination is missing. + if [[ -d "$rvm_ruby_src_path" ]] ; then + rm -rf "$rvm_ruby_src_path" # Especially when forced, we want to ensure the destination is missing. + fi + mkdir -p "/tmp/rvm_src_$$" - if [[ "tar.gz" = "$rvm_archive_extension" ]] || [[ "tgz" = "$rvm_archive_extension" ]] ; then - __rvm_run "extract" "gunzip < \"$rvm_archives_path/$rvm_ruby_package_file.$rvm_archive_extension\" | tar xf - -C /tmp/rvm_src_$$" "#extracting $rvm_ruby_package_file to $rvm_ruby_src_path" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to extract the source. Aborting the installation." ; return $result - fi - elif [[ "zip" = "$rvm_archive_extension" ]] ; then - __rvm_run "extract" "unzip -q -o $rvm_archives_path/$rvm_ruby_package_file -d /tmp/rvm_src_$$" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to extract $rvm_ruby_package_file. Aborting the installation." ; return $result - fi - elif [[ "tar.bz2" = "$rvm_archive_extension" ]] ; then - __rvm_run "extract" "bunzip2 < \"$rvm_archives_path/$rvm_ruby_package_file.$rvm_archive_extension\" | tar xf - -C /tmp/rvm_src_$$" "#extracting $rvm_ruby_package_file to $rvm_ruby_src_path" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to extract the source. Aborting the installation." ; return $result - fi - fi + case "$rvm_archive_extension" in + tar.gz|tgz) + __rvm_run "extract" "gunzip < \"$rvm_archives_path/$rvm_ruby_package_file.$rvm_archive_extension\" | tar xf - -C /tmp/rvm_src_$$" "#extracting $rvm_ruby_package_file to $rvm_ruby_src_path" + result=$? + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" "There has been an error while trying to extract the source. Aborting the installation." ; return $result + fi + ;; + zip) + __rvm_run "extract" "unzip -q -o $rvm_archives_path/$rvm_ruby_package_file -d /tmp/rvm_src_$$" + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" "There has been an error while trying to extract $rvm_ruby_package_file. Aborting the installation." + return $result + fi + ;; + tar.bz2) + __rvm_run "extract" "bunzip2 < \"$rvm_archives_path/$rvm_ruby_package_file.$rvm_archive_extension\" | tar xf - -C /tmp/rvm_src_$$" "#extracting $rvm_ruby_package_file to $rvm_ruby_src_path" + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" "There has been an error while trying to extract the source. Aborting the installation." + return $result + fi + ;; + *) + "$rvm_scripts_path/log" "error" "Unknown archive format extension '$rvm_archive_extension'. Aborting the installation." + return 1 + ;; + esac + mv "/tmp/rvm_src_$$/$(builtin cd /tmp/rvm_src_$$ ; ls)" "$rvm_ruby_src_path" ; rm -rf "/tmp/rvm_src_$$" if [[ -n "${rvm_ruby_name:-""}" && -d "$rvm_src_path/$(echo $rvm_ruby_string | sed -e 's/-n.*//')" ]] ; then mv "$rvm_src_path/$(echo "$rvm_ruby_string" | sed -e 's/-n.*//')" "$rvm_ruby_src_path" fi @@ -855,108 +1203,164 @@ fi else mkdir -p "$rvm_repo_path" + if [[ -n "$(echo "$rvm_ruby_url" | awk '/^git/')" ]] ; then + if [[ -d "$rvm_ruby_repo_path/.git" ]] ; then + builtin cd "$rvm_ruby_repo_path" + if [[ -z "$rvm_ruby_revision" ]] ; then + "$rvm_scripts_path/log" "info" "Pulling from $rvm_ruby_repo_url, this may take a while depending on your connection..." + git pull origin master --force - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to update the source from the remote repository. Aborting the installation." ; return $result + + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to update the source from the remote repository. Aborting the installation." + return $result fi + else - if [[ -z "$rvm_ruby_sha" ]] ; then + if [[ -z "${rvm_ruby_sha:-""}" ]] ; then git checkout HEAD else git checkout $(echo "$rvm_ruby_sha" | sed 's#^s##') fi - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to checkout the source branch. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to checkout the source branch. Aborting the installation." + return $result fi fi + else rm -rf "$rvm_ruby_repo_path" + rvm_ruby_repo_http_url="${rvm_ruby_repo_url//git:/http:/}" + "$rvm_scripts_path/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_ruby_repo_path" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "info" "cloning from $rvm_ruby_repo_url failed, now attempting to clone from $rvm_ruby_repo_http_url, this may take a while depending on your connection..." + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "info" \ + "cloning from $rvm_ruby_repo_url failed, now attempting to clone from $rvm_ruby_repo_http_url, this may take a while depending on your connection..." + git clone "$rvm_ruby_repo_http_url" "$rvm_ruby_repo_path" - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to fetch the repository. Aborting the installation." ; return $result + result=$? + + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to fetch the repository. Aborting the installation." + return $result fi fi fi + else - if [[ -n "$rvm_ruby_tag" ]] ; then + if [[ -n "${rvm_ruby_tag:-""}" ]] ; then # TODO: Check if tag v is valid rvm_ruby_url="${rvm_ruby_url:-"$rvm_ruby_repo_url/tags/$(echo "$rvm_ruby_tag" | sed 's/^t//')"}" - elif [[ -z "$rvm_ruby_version" && $rvm_head_flag -eq 1 ]] ; then + + elif [[ -z "${rvm_ruby_version:-""}" && ${rvm_head_flag:-0} -eq 1 ]] ; then rvm_ruby_url="${rvm_ruby_url:-"$rvm_ruby_repo_url/trunk"}" - elif [[ "$rvm_ruby_major_version" = "9" ]] ; then - if [[ -z "$rvm_ruby_minor_version" || "$rvm_ruby_minor_version" = 3 ]] ; then + + elif [[ "${rvm_ruby_major_version:-""}" = "9" ]] ; then + + if [[ -z "${rvm_ruby_minor_version:-""}" || "${rvm_ruby_minor_version:-""}" = 3 ]] ; then rvm_ruby_url="${rvm_ruby_url:-"$rvm_ruby_repo_url/trunk"}" + else rvm_ruby_url="${rvm_ruby_url:-"$rvm_ruby_repo_url/branches/ruby_${rvm_ruby_release_version}_${rvm_ruby_major_version}_${rvm_ruby_minor_version}"}" fi - elif [[ -z "$rvm_ruby_minor_version" ]] || [[ "$rvm_ruby_major_version.$rvm_ruby_minor_version" = "8.8" ]] ; then + + elif [[ -z "${rvm_ruby_minor_version:-""}" || "${rvm_ruby_major_version:-""}.${rvm_ruby_minor_version:-""}" = "8.8" ]] ; then rvm_ruby_url="${rvm_ruby_url:-"$rvm_ruby_repo_url/branches/ruby_${rvm_ruby_release_version}_${rvm_ruby_major_version}"}" + else rvm_ruby_url="${rvm_ruby_url:-"$rvm_ruby_repo_url/branches/ruby_${rvm_ruby_release_version}_${rvm_ruby_major_version}_${rvm_ruby_minor_version}"}" fi + rvm_rev="" - if [ -n "$rvm_ruby_revision" ] ; then + + if [[ -n "${rvm_ruby_revision:-""}" ]] ; then rvm_rev="-$rvm_ruby_revision" fi if [[ -d "$rvm_ruby_repo_path/.svn" ]] ; then + builtin cd "$rvm_ruby_repo_path" + "$rvm_scripts_path/log" "info" "Updating ruby from $rvm_ruby_url" + __rvm_run "svn.switch" "svn switch $rvm_ruby_url" + __rvm_run "svn.update" "svn update" - if [[ -n "$rvm_rev" ]] ; then + + if [[ -n "${rvm_rev:-""}" ]] ; then "$rvm_scripts_path/log" "info" "Checking out revision ${rvm_rev/-r/-r } from $rvm_ruby_url" + __rvm_run "svn.checkout" "svn update -q ${rvm_rev/-r/-r }" fi else rm -rf "$rvm_ruby_repo_path" + __rvm_run "svn.checkout" "svn checkout -q ${rvm_rev/-r/-r } $rvm_ruby_url $rvm_ruby_repo_path" "Downloading source from ${rvm_ruby_url}." fi - result=$? ; if [[ "$result" -gt 0 ]] ; then - "$rvm_scripts_path/log" "error" "There has been an error while trying to fetch / update the source. Aborting the installation." ; return $result - fi + result=$? + if [[ "$result" -gt 0 ]] ; then + "$rvm_scripts_path/log" "error" \ + "There has been an error while trying to fetch / update the source. Aborting the installation." + return $result + fi fi + "$rvm_scripts_path/log" "info" "Copying from repo to src path..." + rm -rf "$rvm_ruby_src_path" + cp -R "$rvm_ruby_repo_path" "$rvm_ruby_src_path" fi } __rvm_check_default() { - 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 + + local default_ruby_interpreter="$(rvm alias show default 2>/dev/null | awk -F"${rvm_gemset_separator:-"@"}" '{print $1}')" + + local 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 - unset default_ruby_interpreter current_ruby_interpreter } __rvm_uninstall_ruby() { - if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select ; fi - if [[ -n "$rvm_ruby_string" ]] ; then + if [[ ${rvm_ruby_selected_flag} -eq 0 ]] ; then __rvm_select ; fi + + if [[ -n "${rvm_ruby_string:-""}" ]] ; then + for dir in "$rvm_rubies_path" ; do if [[ -d "$dir/$rvm_ruby_string" ]] ; then "$rvm_scripts_path/log" "info" "Removing $dir/$rvm_ruby_string..." + rm -rf $dir/$rvm_ruby_string else "$rvm_scripts_path/log" "info" "$dir/$rvm_ruby_string has already been removed." fi + if [[ -e "$rvm_bin_path/$rvm_ruby_string" ]] ; then rm -f "$rvm_bin_path/$rvm_ruby_string" fi done ; unset dir @@ -966,11 +1370,15 @@ __rvm_check_default else "$rvm_scripts_path/log" "fail" "Cannot uninstall unknown package '$rvm_ruby_string'" - fi ; unset rvm_uninstall_flag + fi + + unset rvm_uninstall_flag + + return 0 } __rvm_remove_ruby() { if [[ ${rvm_ruby_selected_flag:-0} -eq 0 ]] ; then __rvm_select ; fi @@ -1008,11 +1416,11 @@ __rvm_remove_gemsets() { if [[ ${rvm_gems_flag:-0} -eq 1 ]] ; then "$rvm_scripts_path/log" "info" "Removing $rvm_ruby_string gemsets..." - gemsets="$rvm_gems_path/$rvm_ruby_string $(ls -d "${rvm_gems_path}"/* | awk '/'$rvm_ruby_string'@/')" + gemsets="$rvm_gems_path/$rvm_ruby_string $(builtin cd "${rvm_gems_path}"/ ; find * -type d -maxdepth 0 | awk '/'$rvm_ruby_string'@/')" for gemset in $gemsets ; do if [[ -d "$gemset" ]] ; then rm -rf "$gemset" fi @@ -1023,11 +1431,11 @@ __rvm_remove_wrappers() { "$rvm_scripts_path/log" "info" "Removing $rvm_ruby_string wrappers..." local wrappers wrapper - wrappers="$rvm_wrappers_path/$rvm_ruby_string $(ls -d "$rvm_wrappers_path"/* 2>/dev/null | awk '/'$rvm_ruby_string'@/')" + wrappers="$rvm_wrappers_path/$rvm_ruby_string $(builtin cd "$rvm_wrappers_path"/ ; find * -type f -maxdepth 0 2>/dev/null | awk '/'$rvm_ruby_string'@/')" for wrapper in $wrappers ; do rm -rf "$wrapper" done @@ -1037,11 +1445,11 @@ __rvm_remove_environments() { "$rvm_scripts_path/log" "info" "Removing $rvm_ruby_string environments..." local environments environment - environments="$rvm_environments_path/$rvm_ruby_string $(ls -d "$rvm_environments_path"/* | awk '/'$rvm_ruby_string'@/')" + environments="$rvm_environments_path/$rvm_ruby_string $(builtin cd "$rvm_environments_path"/ ; find * -type f -maxdepth 0 | awk '/'$rvm_ruby_string'@/')" for environment in $environments ; do rm -rf "$environment" done @@ -1071,11 +1479,12 @@ __rvm_remove_binaries() { "$rvm_scripts_path/log" "info" "Removing $rvm_ruby_string binaries..." # Iterate over all binaries and check for symlinked wrappers etc. local binary_name - for binary_name in $(ls "$rvm_bin_path"); do + + for binary_name in $(builtin cd "$rvm_bin_path" ; find * -type f -maxdepth 0); do full_binary_path="$rvm_bin_path/$binary_name" if [[ -L "$full_binary_path" ]] && "$rvm_scripts_path/match" "$(readlink "$full_binary_path")" "$rvm_ruby_string"; then rm -f "$full_binary_path" fi @@ -1083,21 +1492,28 @@ done } __rvm_post_install() { if [[ "$rvm_ruby_interpreter" != "jruby" ]] ; then - binaries="${binaries:-"gem irb erb ri rdoc testrb rake"}" + binaries=(${binaries:-"gem irb erb ri rdoc testrb rake"}) + "$rvm_scripts_path/log" "info" "#shebangs adjustment for $rvm_ruby_string ($binaries)." - for binary in $(echo $binaries) ; do + + for binary in "${binaries[@]}" ; do + if [[ -e "$rvm_ruby_home/bin/$binary" ]] || [[ -e "$rvm_ruby_src_path/bin/$binary" ]] ; then + if [[ "$rvm_ruby_src_path" != "$rvm_ruby_home" ]] && [[ -f "$rvm_ruby_src_path/bin/$binary" ]] ; then cp -f "$rvm_ruby_src_path/bin/$binary" "$rvm_ruby_home/bin/$binary" elif [[ -f "$rvm_ruby_gem_home/bin/$binary" ]] ; then cp -f "$rvm_ruby_gem_home/bin/$binary" "$rvm_ruby_home/bin/$binary" fi + __rvm_inject_gem_env "$rvm_ruby_home/bin/$binary" + __rvm_inject_ruby_shebang "$rvm_ruby_home/bin/$binary" + chmod +x "$rvm_ruby_home/bin/$binary" fi done ; unset binary binaries fi @@ -1136,44 +1552,55 @@ __rvm_use if [[ "$install" -eq 0 ]] ; then # 1.9.X has it's own built-in gem command __rvm_inject_ruby_shebang "$rvm_ruby_src_path/bin/gem" + __rvm_inject_gem_env "$rvm_ruby_home/bin/gem" cp "$rvm_ruby_src_path/bin/gem" "$rvm_ruby_home/bin/gem" home="$GEM_HOME" ; path="$GEM_PATH" # Save + for dir in $rvm_ruby_global_gems_path $rvm_ruby_gem_home ; do export GEM_HOME="$dir" ; export GEM_PATH="$dir" ; export BUNDLE_PATH="$dir" __rvm_run "rubygems.update" "$rvm_ruby_home/bin/gem update --system" "#rubygems update for $dir" done ; unset home path dir + GEM_HOME="$home" ; GEM_PATH="$path" ; BUNDLE_PATH="$home" export GEM_HOME GEM_PATH BUNDLE_PATH __rvm_inject_ruby_shebang "$rvm_ruby_home/bin/gem" + __rvm_inject_gem_env "$rvm_ruby_home/bin/gem" directory_name="$rvm_ruby_home/lib/ruby/gems" + version_number="${rvm_ruby_release_version}.${rvm_ruby_major_version}" + if [[ "$version_number" == "." ]]; then - version_number="$(\ls "$directory_name" | \grep '^[[:digit:]].[[:digit:]]\(.[[:digit:]]\)\?' | head -n1)" + version_number="$(builtin cd "$directory_name" ; find * -type f -maxdepth 0 | \grep '^[[:digit:]].[[:digit:]]\(.[[:digit:]]\)\?' | head -n1)" + if [[ -n "$version_number" ]]; then ruby_lib_gem_path="${directory_name}/${version_number}" else ruby_lib_gem_path="" fi + else ruby_lib_gem_path="${directory_name}/${version_number}" fi + unset directory_name version_number 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_scripts_path/log" "debug" "Skipping rubygems update for $rvm_ruby_version" fi + ruby_lib_gem_path="$rvm_ruby_home/lib/ruby/gems/jruby" else "$rvm_scripts_path/log" "info" "#rubygems installing to $rvm_ruby_string" rvm_rubygems_version="$(__rvm_db "${rvm_ruby_interpreter}_rubygems_version")" @@ -1214,13 +1641,19 @@ fi fi if [[ -n "$ruby_lib_gem_path" ]]; then # Add ruby's gem path to ruby's lib direcotry. - mkdir -p $(dirname "$ruby_lib_gem_path") - if [[ -d "$ruby_lib_gem_path" ]] ; then \rm -rf "$ruby_lib_gem_path" ; fi + + if [[ -d "$ruby_lib_gem_path" ]] ; then + \rm -rf "$ruby_lib_gem_path" + fi + + mkdir -p ${ruby_lib_gem_path%\/*} + ln -nfs "$rvm_ruby_gem_home" "$ruby_lib_gem_path" + fi; unset ruby_lib_gem_path if [[ -s "$rvm_ruby_src_path/bin/rdoc" ]] ; then __rvm_inject_ruby_shebang "$rvm_ruby_src_path/bin/rdoc" fi @@ -1264,48 +1697,70 @@ actual_file="$1" fi } __rvm_manage_rubies() { - unset rvm_gemset_name rvm_ruby_selected_flag + local manage_result=0 + local bin_line="" - rvm_ruby_gem_home=$(echo "${rvm_ruby_gem_home:-""}" | awk -F${rvm_gemset_separator} '{print $1}') - rvm_ruby_string=$(echo "${rvm_ruby_string:-""}" | awk -F${rvm_gemset_separator} '{print $1}') + rvm_gemset_name="" + rvm_ruby_selected_flag=0 - local manage_result=0 + rvm_ruby_gem_home="${rvm_ruby_gem_home:-""//${rvm_gemset_separator}*}" + rvm_ruby_string="${rvm_ruby_string:-""//${rvm_gemset_separator}*}" - if [[ -n "$rubies_string" ]] ;then - for rvm_ruby_string in $(echo "$rubies_string" | \tr ',' ' ') ; do + # Given list of ruby strings. + if [[ -n "${rubies_string:-""}" ]] ;then + + for rvm_ruby_string in "${rubies_string//,/ }" ; do current_manage_ruby_string="$rvm_ruby_string" + eval "__rvm_${action}_ruby" result="$?" + if [[ "$result" -gt 0 && "$manage_result" = 0 ]]; then manage_result="$result" fi - [[ "$result" = 0 && "$action" = "install" ]] && __rvm_record_install "$current_manage_ruby_string" + + if [[ "$result" = 0 && "$action" = "install" ]] ; then + __rvm_record_install "$current_manage_ruby_string" + fi + unset current_manage_ruby_string + __rvm_unset_ruby_variables done + else # all + if [[ "$action" != "install" && "$action" != "remove" && "$action" != "uninstall" ]] ; then - while read -r bin_line + + local ruby_string + while read -r ruby_string do # Keep this on second line damnit! - if [[ -x "$bin_line" ]] ; then - current_manage_ruby_string="$(dirname "$bin_line" | xargs dirname | xargs basename)" - rvm_ruby_string="$current_manage_ruby_string" + + if [[ -x "$ruby_string" ]] ; then + rvm_ruby_string="$ruby_string" + eval "__rvm_${action}_ruby" result="$?" + if [[ "$result" -gt 0 && "$manage_result" = 0 ]]; then manage_result="$result" fi + # record as current_manage_string to prevent it being overridden. - [[ "$result" = 0 && "$action" = "install" ]] && __rvm_record_install "$current_manage_ruby_string" - unset current_manage_ruby_string + if [[ "$result" = 0 && "$action" = "install" ]] ; then + __rvm_record_install "$ruby_string" + fi + __rvm_unset_ruby_variables fi - done < <(ls "$rvm_rubies_path"/*/bin/ruby 2> /dev/null) + done < <(builtin cd "$rvm_rubies_path" ; find * -type d -maxdepth 0 2> /dev/null) + else - "$rvm_scripts_path/log" "warn" 'Really? '"$action"' all? See "rvm list known" and limit the selection to something more sane please :)' + "$rvm_scripts_path/log" "warn" \ + 'Really? '"$action"' all? See "rvm list known" and limit the selection to something more sane please :)' fi fi # TODO: This should return the exit status of the command that got called. return $manage_result