scripts/snapshot in rvm-1.0.7 vs scripts/snapshot in rvm-1.0.8

- old
+ new

@@ -15,31 +15,46 @@ } snapshot_save() { if [[ -z "$1" ]]; then - echo "Usage: rvm snapshot save name" >&2 - echo "Saves a snapshot to <name>.tar.gz in the current directory." >&2 + + printf " + + Usage: + + rvm snapshot save name + + Description: + + Saves a snapshot describing the rvm installation + to <name>.tar.gz in the current working directory.\ + + " >&2 + return 1 + fi # Create the temporary directory. - local snapshot_temp_path="$rvm_tmp_path/$$-snapshot" - \rm -rf "$snapshot_temp_path" - \mkdir -p "$snapshot_temp_path" + local snapshot_temp_path="${rvm_tmp_path:-"$rvm_path/tmp"}/$$-snapshot" + rm -rf "$snapshot_temp_path" + + mkdir -p "$snapshot_temp_path" + "$rvm_path/scripts/log" "info" "Backing up a list of aliases" - \cp "$rvm_config_path/alias" "$snapshot_temp_path/" + cp "$rvm_path/config/alias" "$snapshot_temp_path/" "$rvm_path/scripts/log" "info" "Backing up your user preferences" - \cp "$rvm_config_path/user" "$snapshot_temp_path/" + cp "$rvm_path/config/user" "$snapshot_temp_path/" "$rvm_path/scripts/log" "info" "Backing up your installed packages" - sed -e 's/-//' -e 's/^lib//' < "$rvm_config_path/packages" | awk -F= '{print $1}' | sort | uniq > "$snapshot_temp_path/packages" + sed -e 's/-//' -e 's/^lib//' < "$rvm_path/config/packages" | awk -F= '{print $1}' | sort | uniq > "$snapshot_temp_path/packages" "$rvm_path/scripts/log" "info" "Backing up all of your gemsets" - \mkdir -p "$snapshot_temp_path/gems" + mkdir -p "$snapshot_temp_path/gems" ( builtin cd "$snapshot_temp_path/gems" for snapshot_gemset in $("$rvm_path/scripts/list" gemsets strings) ; do @@ -50,57 +65,78 @@ "$rvm_path/scripts/gemsets" export "${snapshot_gemset}.gems" >/dev/null ; result="$?" __error_on_result "$result" "Error exporting gemset contents for $snapshot_gemset" && return "$result" - \mkdir -p "./$snapshot_gemset/" + mkdir -p "./$snapshot_gemset/" [[ -d "$GEM_HOME/cache/" ]] && \cp -R "$GEM_HOME/cache/" "./$snapshot_gemset/" done ) "$rvm_path/scripts/log" "info" "Backing up all of your installed rubies" + echo '#!/usr/bin/env bash -e' > "$snapshot_temp_path/install-rubies.sh" + echo "source \"\$rvm_path/scripts/rvm\" || true" >> "$snapshot_temp_path/install-rubies.sh" - local snapshot_ruby_name_file="$rvm_tmp_path/$$-rubies" - local snapshot_alias_name_file="$rvm_tmp_path/$$-aliases" - local snapshot_installable_file="$rvm_tmp_path/$$-installable" + local snapshot_ruby_name_file="${rvm_tmp_path:-"$rvm_path/tmp"}/$$-rubies" + + local snapshot_alias_name_file="${rvm_tmp_path:-"$rvm_path/tmp"}/$$-aliases" + + local snapshot_installable_file="${rvm_tmp_path:-"$rvm_path/tmp"}/$$-installable" + "$rvm_path/scripts/alias" list | awk -F ' => ' '{print $1}' | sort | uniq 2>/dev/null > "$snapshot_alias_name_file" + "$rvm_path/scripts/list" strings | \tr ' ' '\n' | sort | uniq > "$snapshot_ruby_name_file" + comm -2 -3 "$snapshot_ruby_name_file" "$snapshot_alias_name_file" > "$snapshot_installable_file" - \rm -rf "$snapshot_ruby_name_file" "$snapshot_alias_name_file" + rm -rf "$snapshot_ruby_name_file" "$snapshot_alias_name_file" + local snapshot_primary_ruby="$(\grep '^\(ree\|ruby-1.8.7\)' < "$snapshot_installable_file" | \grep -v '-head$' | sort -r | head -n1)" + local snapshot_ruby_order="$snapshot_primary_ruby $(\grep -v "$snapshot_primary_ruby" < "$snapshot_installable_file")" + for snapshot_ruby_name in $snapshot_ruby_order ; do + snapshot_install_command="$(__rvm_recorded_install_command "$snapshot_ruby_name")" + if [[ -n "$snapshot_install_command" ]]; then + echo "rvm install $snapshot_install_command" | sed "s#$rvm_path#'\\\"\$rvm_path\\\"'#" >> "$snapshot_temp_path/install-rubies.sh" + else + __rvm_become "$snapshot_ruby_name" + ruby "$rvm_path/lib/rvm/install_command_dumper.rb" >> "$snapshot_temp_path/install-rubies.sh" + fi + unset snapshot_install_command + done; unset snapshot_ruby_name snapshot_primary_ruby - \rm -rf "$snapshot_installable_file" + rm -rf "$snapshot_installable_file" "$rvm_path/scripts/log" "info" "Compressing snapshotting" + local destination_path="$PWD" ( builtin cd "$snapshot_temp_path" - \rm -rf "$destination_path/$1.tar.gz" + rm -rf "$destination_path/$1.tar.gz" tar czf "$destination_path/$1.tar.gz" . result="$?" __error_on_result "$result" "Error creating archive $destination_path/$1.tar.gz" && return "$result" ) "$rvm_path/scripts/log" "info" "Cleaning up" - \rm -rf "$snapshot_temp_path" + rm -rf "$snapshot_temp_path" + "$rvm_path/scripts/log" "info" "Snapshot complete" } snapshot_load() { if [[ -z "$1" ]]; then @@ -114,11 +150,11 @@ if ! [[ -s "$snapshot_archive" ]]; then echo "The provides snapshot '$(basename "$snapshot_archive")' doesn't exist." >&2 return 1 fi - local snapshot_temp_path="$rvm_tmp_path/$$-snapshot" + local snapshot_temp_path="${rvm_tmp_path:-"$rvm_path/tmp"}/$$-snapshot" \rm -rf "$snapshot_temp_path" \mkdir -p "$snapshot_temp_path" "$rvm_path/scripts/log" "info" "Extracting snapshot" @@ -128,10 +164,10 @@ result="$?" __error_on_result "$result" "Error extracting the archive '$snapshot_archive'" && return "$result" ) "$rvm_path/scripts/log" "info" "Restoring user settings" - \cp -f "$snapshot_temp_path/user" "$rvm_config_path/user" + \cp -f "$snapshot_temp_path/user" "$rvm_path/config/user" "$rvm_path/scripts/log" "info" "Installing rvm-managed packages" for snapshot_package in $(cat "$snapshot_temp_path/packages"); do "$rvm_path/scripts/package" install "$snapshot_package" result="$?"