summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorBob Gilligan <gilligan@vyatta.com>2010-01-11 17:05:26 -0800
committerBob Gilligan <gilligan@vyatta.com>2010-01-11 17:05:26 -0800
commitff11c68efa6fac9a20ae62f0d7049b6e60ed9c4f (patch)
treed2fd80d878454580f5f103f2d8a7b9e5644d9bca /scripts
parent094d5a5f9dcc47d3197da46ebe4b67ebe7ce2eb0 (diff)
downloadvyatta-op-ff11c68efa6fac9a20ae62f0d7049b6e60ed9c4f.tar.gz
vyatta-op-ff11c68efa6fac9a20ae62f0d7049b6e60ed9c4f.zip
Add image name completion for two system image commands.
The two commands are: "set system image default-boot" and "delete system image".
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/vyatta-boot-image.pl79
1 files changed, 61 insertions, 18 deletions
diff --git a/scripts/vyatta-boot-image.pl b/scripts/vyatta-boot-image.pl
index 304f35c..c3040b4 100755
--- a/scripts/vyatta-boot-image.pl
+++ b/scripts/vyatta-boot-image.pl
@@ -178,10 +178,13 @@ sub getBootList {
return \@list;
}
-# Prints the boot list generated by getBootList().
+
+# 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) = @_;
+ my ($didx, $entries, $brief) = @_;
my $running_ver = curVer();
for my $i (0 .. $#{$entries}) {
my $di = $i + 1;
@@ -195,7 +198,11 @@ sub displayBootList {
$m .= ' (running version)';
}
- printf " %2d: %s%s\n", $di, $ver, $m;
+ if (defined($brief)) {
+ print "$ver\n";
+ } else {
+ printf " %2d: %s%s\n", $di, $ver, $m;
+ }
}
}
@@ -203,9 +210,19 @@ sub displayBootList {
# number passed in.
#
sub doSelect {
- my ($resp, $def_ver, $bentries) = @_;
- my $new_idx = $ {$bentries}[$resp]->{'idx'};
- my $new_ver = $ {$bentries}[$resp]->{'ver'};
+ my ($resp, $def_ver, $bentries, $new_ver) = @_;
+ my $new_idx;
+ if (defined($new_ver)) {
+ for my $i (0 .. $#{$bentries}) {
+ if ($ {$bentries}[$i]->{'ver'} eq $new_ver) {
+ $new_idx = $ {$bentries}[$i]->{'idx'};
+ last;
+ }
+ }
+ } else {
+ $new_idx = $ {$bentries}[$resp]->{'idx'};
+ $new_ver = $ {$bentries}[$resp]->{'ver'};
+ }
if ($new_ver eq $def_ver) {
print "The default boot image has not been changed.\n";
exit 0;
@@ -311,15 +328,18 @@ sub del_non_image_files {
system ("echo done at: `date` >> $logfile");
}
-
-# Takes the boot list entry number selected by the user and deletes
-# the corresponding image. Deletes all of the grub config file entries
-# associated with that image and deletes the files associated
-# with that entry.
+# Deletes all of the grub config file entries associated with that
+# image and deletes the files associated with that entry. If caller
+# provides the version string of the image to be deleted ($del_ver),
+# that version is targetted. Otherwise, the caller must provide the
+# index into the boot entries list ($resp) to identify the image to be
+# deleted.
#
sub doDelete {
- my ($resp, $orig_def_ver, $def_ter, $bentries) = @_;
- my $del_ver = $ {$bentries}[$resp]->{'ver'};
+ my ($resp, $orig_def_ver, $def_ter, $bentries, $del_ver) = @_;
+ if (!defined($del_ver)) {
+ $del_ver = $ {$bentries}[$resp]->{'ver'};
+ }
my $boot_dir;
my $cver = curVer();
@@ -394,12 +414,13 @@ sub doDelete {
# Main section
#
-my ($show, $del, $sel) = (undef, undef, undef);
+my ($show, $del, $sel, $list) = (undef, undef, undef, undef);
GetOptions(
'show' => \$show,
- 'delete' => \$del,
- 'select' => \$sel
+ 'delete:s' => \$del,
+ 'select:s' => \$sel,
+ 'list' => \$list
);
if (-e $UNION_GRUB_CFG) {
@@ -433,6 +454,25 @@ if ($#{$bentries} < 0) {
exit 1;
}
+if (defined($list)) {
+ displayBootList($def_idx, $bentries, 1);
+ exit 0;
+}
+
+if (defined($sel) && ($sel ne "")) {
+ # User has specified entry to select
+ doSelect(0, $def_ver, $bentries, $sel);
+ print "Done.\n";
+ exit 0;
+}
+
+if (defined($del) && ($del ne "")) {
+ # User has specified entry to delete
+ doDelete(0, $def_ver, $def_term, $bentries, $del);
+ print "Done.\n";
+ exit 0;
+}
+
my $msg = 'The system currently has the following image(s) installed:';
if (defined($del)) {
# doing delete
@@ -469,10 +509,13 @@ print "\n";
$resp -= 1;
-if ($sel) {
+if (defined($sel)) {
doSelect($resp, $def_ver, $bentries);
-} elsif ($del) {
+} elsif (defined($del)) {
doDelete($resp, $def_ver, $def_term, $bentries);
+} else {
+ print "Unknown command.\n";
+ exit 1;
}
exit 0;