diff options
author | Bob Gilligan <gilligan@vyatta.com> | 2010-02-11 16:02:57 -0800 |
---|---|---|
committer | Bob Gilligan <gilligan@vyatta.com> | 2010-02-11 16:02:57 -0800 |
commit | 69b5bae09158dbfc8cc5ec045353941a0bdd1979 (patch) | |
tree | f0386d36beb43a1609e426e0b9cd9312da04f898 /scripts/install-system | |
parent | 60cb502944d290a0819a1908eb259901b56a5ce4 (diff) | |
download | vyatta-cfg-quagga-69b5bae09158dbfc8cc5ec045353941a0bdd1979.tar.gz vyatta-cfg-quagga-69b5bae09158dbfc8cc5ec045353941a0bdd1979.zip |
Bugfix 5117: Preserve config files from previous image installation.
The install-image program knows how to preserve the config files from
a previous image or disk-based installation. The install-system
program already knew how to preserve config files from a previous
disk-based installation. This change teaches it how to preserve
config files from a previous image installation.
Diffstat (limited to 'scripts/install-system')
-rwxr-xr-x | scripts/install-system | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/scripts/install-system b/scripts/install-system index bc2277fd..68584445 100755 --- a/scripts/install-system +++ b/scripts/install-system @@ -656,11 +656,65 @@ save_old_keys() { fi } +save_image_config() { + image_name=$1 + + # Cleanup from possible partial last run + rm -fr /mnt/config + mkdir /mnt/config + + output=$(cp -pR /mnt/tmp/boot/$image_name/live-rw/config/* /mnt/config) + + if [ -n "$output" ]; then + echo -e "Warning: error in copying the old config partition.\nSee $INSTALL_LOG for more details." + lecho "Warning: error in copying the old config partition.\ncp -pR /mnt/tmp/* /mnt/config\n$output\n" + fi + rename_old_config +} + +save_image_keys() { + image_name=$1 + + if [ ! -d /mnt/tmp/boot/$image_name/live-rw/etc/ssh ]; then + echo "No SSH keys found on $image_name, so none can be saved." + return; + fi + + echo -n "Would you like to save SSH keys from $image_name too? (Yes/No) [Yes] " + + response=$(get_response "Yes" "Yes No Y N") + if [ "$response" != "yes" ] && [ "$response" != "y" ]; then + echo "OK. SSH keys not saved." + return + fi + + mkdir -p /mnt/ssh + output=$(cp -p /mnt/tmp/boot/$image_name/live-rw/etc/ssh/ssh_host_* /mnt/ssh) + + if [ -n "$output" ]; then + echo -e "Warning: error in copying the old ssh keys." + echo -e "See $INSTALL_LOG for more details." + echo "Warning: error in copying the old ssh keys." >> $INSTALL_LOG + echo "cp -pR /mnt/tmp/etc/ssh/ssh_host_* /mnt/ssh" >> $INSTALL_LOG + echo "$output\n">> $INSTALL_LOG + return + fi + + # reset modes on keys (should already be set) + chmod 600 /mnt/ssh/*_key 2>&1 + chmod 644 /mnt/ssh/*.pub 2>&1 + + echo "SSH keys have been saved." +} + + + ## check_config_partition # look to see if this partition contains a config file # and back it up check_config_partition() { lpart=$1 + copied=0 # Cleanup from possible partial last run rm -fr /mnt/config @@ -678,13 +732,65 @@ check_config_partition() { if [ -f /mnt/tmp/opt/vyatta/etc/config/.vyatta_config ] || [ -f /mnt/tmp/.vyatta_config ]; then save_old_config + copied=1 fi # Look to see if there are SSH host keys if [ -d /mnt/tmp/etc/ssh ]; then save_old_keys + copied=1 fi + if [ $copied -eq 0 ]; then + # Check for images + images=() + image_dirs=/mnt/tmp/boot/* + + for dir in $image_dirs; do + if [ -f $dir/live-rw/config/.vyatta_config ]; then + item=${dir##/mnt/tmp/boot/} + images=($item ${images[@]}) + fi + done + + num_images=${#images[@]} + + if [ $num_images -gt 0 ]; then + echo "I found the following installed system image(s) with config files on $part:" + for (( i = 0; i < $num_images; i++ )); do + echo " $((i + 1)): ${images[$i]}" + done + + if [ $num_images -eq 1 ]; then + echo -n "Would you like to save config information from it? (Yes/No) [Yes] " + else + echo -n "Would you like to save config information from one? (Yes/No) [Yes] " + fi + + response=$(get_response "Yes" "Yes No Y N") + if [ "$response" != "yes" ] && [ "$response" != "y" ]; then + echo "OK. Config information not saved." + return + fi + + if [ $num_images -gt 1 ]; then + image_index=-1 + while [ $image_index -lt 0 -o $image_index -ge $num_images ]; do + echo -n "Which image would you like to use? (1 .. $num_images): " + read num + image_index=$((num - 1)) + done + else + image_index=0 + fi + + image_name=${images[$image_index]} + echo "Saving config information from image $image_name." + save_image_config $image_name + echo "Done." + save_image_keys $image_name + fi + fi umount /mnt/tmp } |