diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-01-06 08:20:52 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-01-06 08:20:52 -0800 |
commit | 63598856dc03017d21ffa7f33b2e51ed1b827928 (patch) | |
tree | 61b369d09d12612b3acb5c79c2a4c3252a2a4b6b /scripts | |
parent | a5d04a5c46c1e52d14a228343c8418167f5c801e (diff) | |
parent | c57512e24267209a84ad86054f2fc6f666a44288 (diff) | |
download | vyatta-op-63598856dc03017d21ffa7f33b2e51ed1b827928.tar.gz vyatta-op-63598856dc03017d21ffa7f33b2e51ed1b827928.zip |
Merge branch 'kenwood' of suva.vyatta.com:/git/vyatta-op into kenwood
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/vyatta-boot-image.pl | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/scripts/vyatta-boot-image.pl b/scripts/vyatta-boot-image.pl index c6b2349..8b8a19a 100755 --- a/scripts/vyatta-boot-image.pl +++ b/scripts/vyatta-boot-image.pl @@ -8,7 +8,7 @@ use File::Temp qw/ :mktemp /; my $UNION_BOOT = '/live/image/boot'; my $UNION_GRUB_CFG = "$UNION_BOOT/grub/grub.cfg"; my $VER_FILE = '/opt/vyatta/etc/version'; -my $OLD_IMG_VER_STR = 'Old non-image installation'; +my $OLD_IMG_VER_STR = 'Old-non-image-installation'; my $OLD_GRUB_CFG = '/boot/grub/grub.cfg'; my $DISK_BOOT = '/boot'; my $grub_cfg; @@ -93,11 +93,15 @@ sub deleteGrubEntries { $ver = 0; @entry = (); } else { - if (/^\s+linux \/boot\/([^\/ ]+)\/.* boot=live /) { - # kernel line - $ver = $1; - } - push @entry, $_; + if (/^\s+linux/) { + if (/^\s+linux \/boot\/([^\/ ]+)\/.* boot=live /) { + # kernel line + $ver = $1; + } else { + $ver = $OLD_IMG_VER_STR; + } + } + push @entry, $_; } } elsif (/^menuentry /) { $in_entry = 1; @@ -126,8 +130,6 @@ sub getBootList { my @list = (); foreach (@{$entries}) { my ($ver, $term) = ($_->{'ver'}, $_->{'term'}); - # don't list non-image entry if deleting - next if (defined($delete) && $ver eq $OLD_IMG_VER_STR); # don't list default entry if deleting next if (defined($delete) && $ver eq $dver); @@ -265,6 +267,29 @@ sub curVer { return $ver; } +sub del_non_image_files { + my $logfile="/var/log/vyatta/disk-image-del-"; + $logfile .= `date +%F-%T`; + system("touch $logfile"); + system("echo Deleting disk-based system files at: `date` >> $logfile"); + system("echo Run by: `whoami` >> $logfile"); + + my @entries=</live/image/*>; + my $entry; + foreach $entry (@entries) { + if ($entry eq "/live/image/boot") { + print "Skipping $entry.\n"; + } else { + print "Deleting $entry..."; + system ("echo deleting $entry >> $logfile"); + system ("rm -rf $entry >> $logfile 2>&1"); + print "\n"; + } + } + system ("echo done at: `date` >> $logfile"); +} + + sub doDelete { my ($bdx) = @_; my $del_ver = ${$bentries}[$resp]->{'ver'}; @@ -302,21 +327,26 @@ EOF $boot_dir = $DISK_BOOT; } - if (! -d "$boot_dir/$del_ver") { + if (($del_ver ne $OLD_IMG_VER_STR) && (! -d "$boot_dir/$del_ver")) { print "Cannot find the target image. Exiting...\n"; exit 1; } - print "Deleting the \"$del_ver\" image..."; + print "Deleting the \"$del_ver\" image...\n"; my $err = deleteGrubEntries($del_ver); if (defined($err)) { print "$err. Exiting...\n"; exit 1; } - system("rm -rf '$boot_dir/$del_ver'"); - if ($? >> 8) { - print "Error deleting the image. Exiting...\n"; - exit 1; + + if ($del_ver eq $OLD_IMG_VER_STR) { + del_non_image_files(); + } else { + system("rm -rf '$boot_dir/$del_ver'"); + if ($? >> 8) { + print "Error deleting the image. Exiting...\n"; + exit 1; + } } print "Done\n"; |