summaryrefslogtreecommitdiff
path: root/scripts/vyatta-boot-image.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/vyatta-boot-image.pl')
-rwxr-xr-xscripts/vyatta-boot-image.pl71
1 files changed, 63 insertions, 8 deletions
diff --git a/scripts/vyatta-boot-image.pl b/scripts/vyatta-boot-image.pl
index d81a738..9431711 100755
--- a/scripts/vyatta-boot-image.pl
+++ b/scripts/vyatta-boot-image.pl
@@ -57,6 +57,8 @@ sub parseGrubCfg {
my @entries = ();
my $in_entry = 0;
my $idx = 0;
+ my $running_boot_cmd=`cat /proc/cmdline`;
+ $running_boot_cmd =~ s/BOOT_IMAGE=//;
while (<$fd>) {
if ($in_entry) {
if (/^}/) {
@@ -87,6 +89,11 @@ sub parseGrubCfg {
} else {
$ehash{'reset'} = 0;
}
+ if (/$running_boot_cmd/) {
+ $ehash{'running_vers'} = 1;
+ } else {
+ $ehash{'running_vers'} = 0;
+ }
push @entries, \%ehash;
}
} elsif (/^set default=(\d+)$/) {
@@ -179,23 +186,70 @@ sub getBootList {
}
+# Get the Vyatta version of a particular image, given its name.
+#
+sub image_vyatta_version {
+ my ($image_name) = @_;
+
+ my $vers;
+ my $dpkg_path = "var/lib/dpkg";
+
+ my $image_path;
+ if ($image_name eq $OLD_IMG_VER_STR) {
+ $image_path = "";
+ } else {
+ $image_path = "/live/image/boot/$image_name/live-rw";
+ }
+
+ $image_path .= "/var/lib/dpkg";
+
+ if ( -e $image_path ) {
+ $vers = `dpkg-query --admindir=$image_path --showformat='\${Version}' --show vyatta-version`;
+ return $vers;
+ } else {
+ if ($image_name eq $OLD_IMG_VER_STR) {
+ return "unknown";
+ }
+
+ my @squash_files = </live/image/boot/$image_name/*.squashfs>;
+ foreach my $squash_file (@squash_files) {
+ if (-e $squash_file) {
+ system("sudo mkdir /tmp/squash_mount");
+ system("sudo mount -o loop,ro -t squashfs $squash_file /tmp/squash_mount");
+ $image_path = "/tmp/squash_mount/var/lib/dpkg";
+ my $vers = `dpkg-query --admindir=$image_path --showformat='\${Version}' --show vyatta-version`;
+ system("sudo umount /tmp/squash_mount");
+ system("sudo rmdir /tmp/squash_mount");
+ return $vers;
+ }
+ }
+ # None found
+ return "unknown2"
+ }
+}
+
# Prints the boot list generated by getBootList(). If the argument
# $brief is set, display the entries for machine instead of human
# consumption: One entry per line showing the the version string only.
#
sub displayBootList {
- my ($didx, $entries, $brief) = @_;
- my $running_ver = curVer();
+ my ($didx, $entries, $brief, $show_version) = @_;
for my $i (0 .. $#{$entries}) {
my $di = $i + 1;
my $ver = $ {$entries}[$i]->{'ver'};
my $m = '';
+
+ if (defined $show_version) {
+ my $vyatta_vers = image_vyatta_version($ver);
+ $m .= " [$vyatta_vers]";
+ }
+
if ($didx == $ {$entries}[$i]->{'idx'}) {
- $m = ' (default boot)';
+ $m .= ' (default boot)';
}
- if ($ver eq $running_ver) {
- $m .= ' (running version)';
+ if ($ {$entries}[$i]->{'running_vers'} == 1) {
+ $m .= ' (running image)';
}
if (defined($brief)) {
@@ -416,13 +470,14 @@ sub doDelete {
# Main section
#
-my ($show, $del, $sel, $list) = (undef, undef, undef, undef);
+my ($show, $del, $sel, $list, $show_vers) = (undef, undef, undef, undef);
GetOptions(
'show' => \$show,
'delete:s' => \$del,
'select:s' => \$sel,
- 'list' => \$list
+ 'list' => \$list,
+ 'show_vers' => \$show_vers,
);
if (-e $UNION_GRUB_CFG) {
@@ -481,7 +536,7 @@ if (defined($del)) {
$msg = 'The following image(s) can be deleted:';
}
print "$msg\n\n";
-displayBootList($def_idx, $bentries);
+displayBootList($def_idx, $bentries, undef, $show_vers);
print "\n";
exit 0 if (defined($show) || (!defined($sel) && !defined($del))); # show-only