From 8c7c6648dafdcf3e12af5ad904a78c784468b439 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 29 Mar 2010 16:15:02 -0700 Subject: Use new interface_description function Show interfaces doesn't have to be in configure mode. --- debian/control | 1 + scripts/vyatta-show-interfaces.pl | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/debian/control b/debian/control index 2052a68..724c211 100644 --- a/debian/control +++ b/debian/control @@ -13,6 +13,7 @@ Depends: sed (>= 4.1.5), ntpdate, procps (>= 1:3.2.7-3), pciutils, + vyatta-cfg (>= 0.16.26), vyatta-quagga (>= 0.99.15-26), lsof, coreutils (>= 5.97-5.3), diff --git a/scripts/vyatta-show-interfaces.pl b/scripts/vyatta-show-interfaces.pl index 1b662c8..6e071e2 100755 --- a/scripts/vyatta-show-interfaces.pl +++ b/scripts/vyatta-show-interfaces.pl @@ -57,10 +57,8 @@ my @tx_stat_vars = sub get_intf_description { my $name = shift; - my $intf = new Vyatta::Interface($name); - return "" unless $intf; + my $description = interface_description($name); - my $description = $intf->description(); return "" unless $description; return $description; } -- cgit v1.2.3 From a01bc047936b541d84e78d892bdb8ba63843c84c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Mon, 29 Mar 2010 16:15:45 -0700 Subject: 0.13.58 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 00bfea3..3da3d78 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-op (0.13.58) unstable; urgency=low + + * Use new interface_description function + + -- Stephen Hemminger Mon, 29 Mar 2010 16:15:45 -0700 + vyatta-op (0.13.57) unstable; urgency=low * Remove old vtysh alias -- cgit v1.2.3 From a6bd76a42085fda394b74b8d975790a3b05cac6c Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 15 Apr 2010 13:51:46 -0700 Subject: Add Input Functional Block device support --- templates/show/interfaces/input/detail/node.def | 2 ++ templates/show/interfaces/input/node.def | 2 ++ templates/show/interfaces/input/node.tag/brief/node.def | 2 ++ templates/show/interfaces/input/node.tag/node.def | 3 +++ 4 files changed, 9 insertions(+) create mode 100644 templates/show/interfaces/input/detail/node.def create mode 100644 templates/show/interfaces/input/node.def create mode 100644 templates/show/interfaces/input/node.tag/brief/node.def create mode 100644 templates/show/interfaces/input/node.tag/node.def diff --git a/templates/show/interfaces/input/detail/node.def b/templates/show/interfaces/input/detail/node.def new file mode 100644 index 0000000..9cb235b --- /dev/null +++ b/templates/show/interfaces/input/detail/node.def @@ -0,0 +1,2 @@ +help: Show detailed input functional block interface information +run: ${vyatta_bindir}/vyatta-show-interfaces.pl --intf-type=input --action=show diff --git a/templates/show/interfaces/input/node.def b/templates/show/interfaces/input/node.def new file mode 100644 index 0000000..9114561 --- /dev/null +++ b/templates/show/interfaces/input/node.def @@ -0,0 +1,2 @@ +help: Show input functional block interface information +run: ${vyatta_bindir}/vyatta-show-interfaces.pl --intf-type=input --action=show-brief diff --git a/templates/show/interfaces/input/node.tag/brief/node.def b/templates/show/interfaces/input/node.tag/brief/node.def new file mode 100644 index 0000000..ec7d295 --- /dev/null +++ b/templates/show/interfaces/input/node.tag/brief/node.def @@ -0,0 +1,2 @@ +help: Show summary of the specified input functional block interface information +run: ${vyatta_bindir}/vyatta-show-interfaces.pl --intf="$4" --action=show-brief diff --git a/templates/show/interfaces/input/node.tag/node.def b/templates/show/interfaces/input/node.tag/node.def new file mode 100644 index 0000000..ab21b37 --- /dev/null +++ b/templates/show/interfaces/input/node.tag/node.def @@ -0,0 +1,3 @@ +help: Show specified input functional block interface information +allowed: ${vyatta_sbindir}/vyatta-interfaces.pl --show input +run: ${vyatta_bindir}/vyatta-show-interfaces.pl --intf="$4" -- cgit v1.2.3 From 33f1dc8636595650172ca738b0b81ea5d77725bf Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 15 Apr 2010 13:53:22 -0700 Subject: 0.13.59 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 3da3d78..8035be3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-op (0.13.59) unstable; urgency=low + + * Add Input Functional Block device support + + -- Stephen Hemminger Thu, 15 Apr 2010 13:53:22 -0700 + vyatta-op (0.13.58) unstable; urgency=low * Use new interface_description function -- cgit v1.2.3 From ed1cf8a595bbcf46c515d1ee14095ba47e661d36 Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Mon, 26 Apr 2010 12:25:39 -0700 Subject: Bugfix 5549: Use proper prompt string when deleting image. --- scripts/vyatta-boot-image.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/vyatta-boot-image.pl b/scripts/vyatta-boot-image.pl index 276d704..d81a738 100755 --- a/scripts/vyatta-boot-image.pl +++ b/scripts/vyatta-boot-image.pl @@ -489,7 +489,7 @@ exit 0 if (defined($show) || (!defined($sel) && !defined($del))); # show-only # for doing select my $prompt_msg = 'Select the default boot image: '; my $error_msg = 'Invalid selection. Default is not changed.'; -if ($del) { +if (defined ($del)) { # doing delete $prompt_msg = 'Select the image to delete: '; $error_msg = 'Invalid selection. Nothing is deleted.'; -- cgit v1.2.3 From e3759a21689e941a536b9d7f82c54cd7a537d3ac Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Mon, 26 Apr 2010 12:26:53 -0700 Subject: 0.13.60 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 8035be3..eee1bdc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-op (0.13.60) unstable; urgency=low + + * Bugfix 5549: Use proper prompt string when deleting image. + + -- Bob Gilligan Mon, 26 Apr 2010 12:26:53 -0700 + vyatta-op (0.13.59) unstable; urgency=low * Add Input Functional Block device support -- cgit v1.2.3 From 1e912c8e385c94baff8e54b76532763ee161d575 Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Fri, 30 Apr 2010 15:51:31 -0700 Subject: Added an op-mode command to rename a system image. Also added an op-mode command to display the Vyatta version strings along with the names of the installed images. This is useful if you rename an image from its default name, which is its version string. --- Makefile.am | 1 + scripts/rename-image.pl | 97 ++++++++++++++++++++++ scripts/vyatta-boot-image.pl | 71 ++++++++++++++-- templates/rename/node.def | 1 + templates/rename/system/image/node.def | 1 + templates/rename/system/image/node.tag/node.def | 6 ++ .../rename/system/image/node.tag/node.tag/node.def | 7 ++ templates/rename/system/node.def | 1 + templates/show/system/image/version/node.def | 2 + 9 files changed, 179 insertions(+), 8 deletions(-) create mode 100644 scripts/rename-image.pl create mode 100644 templates/rename/node.def create mode 100644 templates/rename/system/image/node.def create mode 100644 templates/rename/system/image/node.tag/node.def create mode 100644 templates/rename/system/image/node.tag/node.tag/node.def create mode 100644 templates/rename/system/node.def create mode 100644 templates/show/system/image/version/node.def diff --git a/Makefile.am b/Makefile.am index 7174493..0fda3f8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,6 +23,7 @@ bin_SCRIPTS += scripts/show-dhcp-leases.pl bin_SCRIPTS += scripts/vyatta-boot-image.pl bin_SCRIPTS += scripts/vyatta-sudo bin_SCRIPTS += scripts/vyatta-show-snmp.pl +bin_SCRIPTS += scripts/rename-image.pl bin_sudo_users_SCRIPTS = scripts/vyatta-identify-interface.pl bin_sudo_users_SCRIPTS += scripts/vyatta-delete-log-file.sh diff --git a/scripts/rename-image.pl b/scripts/rename-image.pl new file mode 100644 index 0000000..d9fbd78 --- /dev/null +++ b/scripts/rename-image.pl @@ -0,0 +1,97 @@ +#!/usr/bin/perl + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2010 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Bob Gilligan +# Date: April 30, 2010 +# Description: Script to re-name a system image. +# +# **** End License **** + +use strict; +use warnings; +use Getopt::Long; +use File::Temp qw/ tempfile tempdir /; + +my $old_name; +my $new_name; + +GetOptions( + 'old_name:s' => \$old_name, + 'new_name:s' => \$new_name, + ); + +if (!defined($old_name) || !defined($new_name)) { + printf("Must specify both old ane new name.\n"); + exit 1; +} + +my $image_path = "/live/image/boot"; + +if (! -e "$image_path") { + # must be running on old non-image installed system + $image_path = ""; +} + +if (! -e "$image_path/$old_name") { + printf("Old name $old_name does not exist.\n"); + exit 1; +} + +if (("$new_name" eq "Old-non-image-installation") || + ("$new_name" eq "grub") || + ("$new_name" =~ /^initrd/) || + ("$new_name" =~ /^vmlinuz/) || + ("$new_name" =~ /^System\.map/) || + ("$new_name" =~ /^config-/)) { + printf("Can't use reserved image name.\n"); + exit 1; +} + +if (-e "$image_path/$new_name") { + printf("New name $new_name already exists.\n"); + exit 1; +} + +printf("Renaming image $old_name to $new_name.\n"); + +my $tmpfh; +my $tmpfilename; +($tmpfh, $tmpfilename) = tempfile(); + +if (!open (GRUBFH, "<${image_path}/grub/grub.cfg")) { + printf("Can't open grub file.\n"); + exit 1; +} + +# This is sensitive to the format of menu entries and boot paths +# in the grub config file. +# +my $line; +while ($line = ) { + $line =~ s/\/boot\/$old_name/\/boot\/$new_name/g; + $line =~ s/Vyatta $old_name/Vyatta $new_name/; + $line =~ s/Lost password change $old_name/Lost password change $new_name/; + printf($tmpfh $line); +} + +close($tmpfh); +close(GRUBFH); + +system("mv $image_path/$old_name $image_path/$new_name"); +system("cp $tmpfilename $image_path/grub/grub.cfg"); + +printf("Done.\n"); + 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 = ; + 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 diff --git a/templates/rename/node.def b/templates/rename/node.def new file mode 100644 index 0000000..b2270fd --- /dev/null +++ b/templates/rename/node.def @@ -0,0 +1 @@ +help: Re-name something. diff --git a/templates/rename/system/image/node.def b/templates/rename/system/image/node.def new file mode 100644 index 0000000..00e9c81 --- /dev/null +++ b/templates/rename/system/image/node.def @@ -0,0 +1 @@ +help: Re-name a system image. diff --git a/templates/rename/system/image/node.tag/node.def b/templates/rename/system/image/node.tag/node.def new file mode 100644 index 0000000..eb25def --- /dev/null +++ b/templates/rename/system/image/node.tag/node.def @@ -0,0 +1,6 @@ +help: System image to rename. + +allowed: + local -a images ; + images=`/opt/vyatta/bin/vyatta-boot-image.pl --list` + echo -n $images diff --git a/templates/rename/system/image/node.tag/node.tag/node.def b/templates/rename/system/image/node.tag/node.tag/node.def new file mode 100644 index 0000000..1f94c57 --- /dev/null +++ b/templates/rename/system/image/node.tag/node.tag/node.def @@ -0,0 +1,7 @@ +help: New name for system image. + +run: + old=$4 + new=$5 + sudo /opt/vyatta/bin/rename-image.pl --old_name $old --new_name $new + diff --git a/templates/rename/system/node.def b/templates/rename/system/node.def new file mode 100644 index 0000000..1d86fc2 --- /dev/null +++ b/templates/rename/system/node.def @@ -0,0 +1 @@ +help: Re-name a system object. diff --git a/templates/show/system/image/version/node.def b/templates/show/system/image/version/node.def new file mode 100644 index 0000000..b488a12 --- /dev/null +++ b/templates/show/system/image/version/node.def @@ -0,0 +1,2 @@ +help: Show installed Vyatta images with Vyatta version number +run: /opt/vyatta/bin/vyatta-boot-image.pl --show --show_vers -- cgit v1.2.3 From 72b54ee266b56b918c2c06e680db4e204428e6d5 Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Fri, 30 Apr 2010 15:54:38 -0700 Subject: 0.13.61 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index eee1bdc..f9bd795 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-op (0.13.61) unstable; urgency=low + + * Added an op-mode command to rename a system image. + + -- Bob Gilligan Fri, 30 Apr 2010 15:54:37 -0700 + vyatta-op (0.13.60) unstable; urgency=low * Bugfix 5549: Use proper prompt string when deleting image. -- cgit v1.2.3 From f78be567aa747f501ad55f0037ef843801d3dd93 Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Fri, 30 Apr 2010 17:49:31 -0700 Subject: Add "show system image storage" op mode command. As the name indicates, it tells you how much disk space each image occupies. --- Makefile.am | 1 + scripts/show-image-storage.pl | 66 ++++++++++++++++++++++++++++ templates/show/system/image/storage/node.def | 3 ++ 3 files changed, 70 insertions(+) create mode 100644 scripts/show-image-storage.pl create mode 100644 templates/show/system/image/storage/node.def diff --git a/Makefile.am b/Makefile.am index 0fda3f8..25e343c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,6 +24,7 @@ bin_SCRIPTS += scripts/vyatta-boot-image.pl bin_SCRIPTS += scripts/vyatta-sudo bin_SCRIPTS += scripts/vyatta-show-snmp.pl bin_SCRIPTS += scripts/rename-image.pl +bin_SCRIPTS += scripts/show-image-storage.pl bin_sudo_users_SCRIPTS = scripts/vyatta-identify-interface.pl bin_sudo_users_SCRIPTS += scripts/vyatta-delete-log-file.sh diff --git a/scripts/show-image-storage.pl b/scripts/show-image-storage.pl new file mode 100644 index 0000000..00a5112 --- /dev/null +++ b/scripts/show-image-storage.pl @@ -0,0 +1,66 @@ +#!/usr/bin/perl + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2010 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Bob Gilligan +# Date: April 30, 2010 +# Description: Script to display disk storage used by images +# +# **** End License **** + +use strict; +use warnings; +use Getopt::Long; + + +# +# Main section +# + +# Figure out where the images live... +my $imagedir = "/live/image/boot"; +if (! -e $imagedir) { + # Must be running on Old non-image system. + $imagedir = "/boot"; + if (! -e $imagedir) { + printf("Can't locate system image directory!\n"); + exit 1; + } +} + +my $bootlist=`/opt/vyatta/bin/vyatta-boot-image.pl --list`; + +my @bootlist_arr = split(/\n/, $bootlist); + +printf("Image name Read-Only Read-Write Total\n"); +printf("------------------------------ ------------ ------------ ------------\n"); + +foreach my $image (@bootlist_arr) { + my $total; + my $read_only; + my $read_write; + my $string; + my $garbage; + + if ( -e "$imagedir/$image") { + $string = `du -s $imagedir/$image`; + ($total, $garbage) = split(' ', $string); + $string = `du -s $imagedir/$image/*.squashfs`; + ($read_only, $garbage) = split(' ', $string); + $read_write = $total - $read_only; + printf("%-30s %12d %12d %12d\n", $image, $read_only, $read_write, + $total); + } +} diff --git a/templates/show/system/image/storage/node.def b/templates/show/system/image/storage/node.def new file mode 100644 index 0000000..0592adc --- /dev/null +++ b/templates/show/system/image/storage/node.def @@ -0,0 +1,3 @@ +help: Show disk space utilization of system images + +run: /opt/vyatta/bin/show-image-storage.pl -- cgit v1.2.3 From e4900050785cbf3a4d3e7b2ea2f09c2dc16cc068 Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Fri, 30 Apr 2010 17:50:25 -0700 Subject: 0.13.62 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index f9bd795..1ea1340 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-op (0.13.62) unstable; urgency=low + + * Add "show system image storage" op mode command. + + -- Bob Gilligan Fri, 30 Apr 2010 17:50:24 -0700 + vyatta-op (0.13.61) unstable; urgency=low * Added an op-mode command to rename a system image. -- cgit v1.2.3 From cb95ae399390b7415ac8926c928e70e8a5469aa8 Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Fri, 30 Apr 2010 17:51:27 -0700 Subject: 0.13.63 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 1ea1340..9022f5b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-op (0.13.63) unstable; urgency=low + + * UNRELEASED + + -- Bob Gilligan Fri, 30 Apr 2010 17:51:27 -0700 + vyatta-op (0.13.62) unstable; urgency=low * Add "show system image storage" op mode command. -- cgit v1.2.3 From 6f57b95df6e3aa1b5b7c163b65059f9067f71eee Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Tue, 4 May 2010 10:59:49 -0700 Subject: Don't allow the currently running image to be renamed. Allowing the running image to be renamed introduced several issues. It is simpler just to dis-allow it. If the user needs to re-name the running image, they can reboot on another image, re-name the first image, then boot back into it. --- scripts/rename-image.pl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/rename-image.pl b/scripts/rename-image.pl index d9fbd78..e2e9745 100644 --- a/scripts/rename-image.pl +++ b/scripts/rename-image.pl @@ -60,6 +60,17 @@ if (("$new_name" eq "Old-non-image-installation") || exit 1; } +my $cmdline=`cat /proc/cmdline`; +my $cur_name; +($cur_name, undef) = split(' ', $cmdline); +$cur_name =~ s/BOOT_IMAGE=\/boot\///; +$cur_name =~ s/\/vmlinuz.*//; + +if ($old_name eq $cur_name) { + printf("Can't re-name the running image.\n"); + exit 1; +} + if (-e "$image_path/$new_name") { printf("New name $new_name already exists.\n"); exit 1; -- cgit v1.2.3 From 2fbeac33be69e6adc9c9a9082f43d8c29faded8e Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Thu, 20 May 2010 10:47:15 -0700 Subject: 0.13.64 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 9022f5b..24881e6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-op (0.13.64) unstable; urgency=low + + * Don't allow the currently running image to be renamed. + + -- Bob Gilligan Thu, 20 May 2010 10:47:05 -0700 + vyatta-op (0.13.63) unstable; urgency=low * UNRELEASED -- cgit v1.2.3 From 0d76417d76a6cc297fc7944b1f620ef4a83ef1f4 Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Wed, 26 May 2010 16:34:44 -0700 Subject: Move DHCPv6 client op-mode commands to this package. --- Makefile.am | 2 + scripts/dhcpv6-client-show-leases.pl | 211 +++++++++++++++++++++ templates/release/dhcpv6/interface/node.def | 2 + .../release/dhcpv6/interface/node.tag/node.def | 10 + templates/release/dhcpv6/node.def | 1 + templates/renew/dhcpv6/interface/node.def | 1 + templates/renew/dhcpv6/interface/node.tag/node.def | 10 + templates/renew/dhcpv6/node.def | 1 + templates/show/dhcpv6/client/leases/node.def | 3 + templates/show/dhcpv6/client/node.def | 1 + 10 files changed, 242 insertions(+) create mode 100644 scripts/dhcpv6-client-show-leases.pl create mode 100644 templates/release/dhcpv6/interface/node.def create mode 100644 templates/release/dhcpv6/interface/node.tag/node.def create mode 100644 templates/release/dhcpv6/node.def create mode 100644 templates/renew/dhcpv6/interface/node.def create mode 100644 templates/renew/dhcpv6/interface/node.tag/node.def create mode 100644 templates/renew/dhcpv6/node.def create mode 100644 templates/show/dhcpv6/client/leases/node.def create mode 100644 templates/show/dhcpv6/client/node.def diff --git a/Makefile.am b/Makefile.am index 25e343c..67ae860 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,6 +26,8 @@ bin_SCRIPTS += scripts/vyatta-show-snmp.pl bin_SCRIPTS += scripts/rename-image.pl bin_SCRIPTS += scripts/show-image-storage.pl +sbin_SCRIPTS = scripts/dhcpv6-client-show-leases.pl + bin_sudo_users_SCRIPTS = scripts/vyatta-identify-interface.pl bin_sudo_users_SCRIPTS += scripts/vyatta-delete-log-file.sh bin_sudo_users_SCRIPTS += scripts/vyatta-reboot.pl diff --git a/scripts/dhcpv6-client-show-leases.pl b/scripts/dhcpv6-client-show-leases.pl new file mode 100644 index 0000000..546668c --- /dev/null +++ b/scripts/dhcpv6-client-show-leases.pl @@ -0,0 +1,211 @@ +#!/usr/bin/perl + +# Module: dhcpv6-client-show-leases.pl +# +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# A copy of the GNU General Public License is available as +# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution +# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'. +# You can also obtain it by writing to the Free Software Foundation, +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +# MA 02110-1301, USA. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2010 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Bob Gilligan +# Date: April 2010 +# Description: Script to display DHCPv6 client leases in a user-friendly form +# +# **** End License **** + +use strict; +use lib "/opt/vyatta/share/perl5/"; + +use Getopt::Long; +use Vyatta::Config; + + +# Globals +my $debug_flag = 0; + +GetOptions( + "debug" => \$debug_flag, + ); + + +sub log_msg { + my $message = shift; + + print "DEBUG: $message" if $debug_flag; +} + + +# +# Main section. +# + +opendir (my $dir, "/var/lib/dhcp3"); +my @lease_files; +while (my $f = readdir $dir) { + if ($f =~ /^dhclient_v6_(\w+).leases$/) { + push (@lease_files, $f); + } +} +closedir $dir; + +if ($debug_flag) { + print "lease files:", join(' ',@lease_files), "\n"; +} + +# Holds the most recent (last) entry for each interface +my %ghash = (); + +foreach my $lease_filename (@lease_files) { + my @lines=(); + + if (!open(LEASE_FILE, "; + close(LEASE_FILE); + chomp @lines; + + my $level = 0; + my $s1; + my $s2; + my $ia_na; + my $iaaddr; + my $ends_day; + my $ends_time; + my $ifname; + my $starts; + my $pref_life; + my $max_life; + my $binding_state; + + # Parse the leases file into a hash keyed by IPv6 addr. + foreach my $line (@lines) { + log_msg("Line: $line\n"); + if ($line =~ /^lease6 \{/) { + if ($level != 0) { + printf("Found lease6 at level $level\n"); + exit 1; + } + $level++; + } elsif ($line =~ /^.*ia-na .*\{/) { + if ($level != 1) { + printf("Found ia-na at level $level\n"); + exit 1; + } + log_msg("setting ia_na\n"); + ($s1, $ia_na, $s2) = split(' ', $line); + $level++; + } elsif ($line =~ /^.*interface /) { + if ($level != 1) { + printf("Found interface at level $level\n"); + exit 1; + } + ($s1, $ifname) = split(' ', $line); + $ifname =~ s/;//; + $ifname =~ s/\"//g; + log_msg("Setting ifname to $ifname\n"); + } elsif ($line =~ /^.*iaaddr .*\{/) { + if ($level != 2) { + printf("Found iaaddr at level $level\n"); + exit 1; + } + ($s1, $iaaddr, $s2) = split(' ', $line); + log_msg("Setting iaaddr to $iaaddr.\n"); + log_msg("s1 $s1 s2 $s2\n"); + $level++; + } elsif ($line =~ /^.*starts /) { + ($s1, $starts) = split(' ', $line); + $starts =~ s/;//; + } elsif ($line =~ /^.*preferred-life /) { + ($s1, $pref_life) = split(' ', $line); + $pref_life =~ s/;//; + } elsif ($line =~ /^.*max-life /) { + ($s1, $max_life) = split(' ', $line); + $max_life =~ s/;//; + } elsif ($line =~ /^.*ends /) { + if ($level != 2) { + printf("Found ends at level $level\n"); + exit 1; + } + log_msg("Setting ends_day ends_time\n"); + ($s1, $s2, $ends_day, $ends_time) = split(' ', $line); + $ends_time =~ s/;//; + } elsif ($line =~ /^.*binding state /) { + if ($level != 2) { + printf("Found binding state at level $level\n"); + exit 1; + } + log_msg("Setting binding state\n"); + ($s1, $s2, $binding_state) = split(' ', $line); + $binding_state =~ s/;//; + } elsif ($line =~ /^.*\{/) { + log_msg("Unknown clause: $line\n"); + $level++; + } elsif ($line =~ /\}$/) { + $level--; + if ($level == 0) { + if (!defined($ia_na)) { + printf("ia_na not defined\n"); + exit 1; + } + + if (!defined($iaaddr)) { + printf("iaaddr not defined\n"); + exit 1; + } + } + } else { + log_msg("Unknown parameter: $line\n"); + } + } + + my @array = ($ia_na, $iaaddr, $starts, $max_life, $pref_life); + $ghash{$ifname} = \@array; +} + +# Display the leases... + +my $num_entries = scalar(keys %ghash); +if ($num_entries == 0) { + printf("There are no DHCPv6 leases.\n"); + exit 0; +} else { + printf("DHCPv6 client leases:\n"); +} + +printf("\n"); +printf("Interface IPv6 Address Expires\n"); +printf("--------- --------------------------------------- ------------------------\n"); +foreach my $key (keys %ghash) { + my $entry = $ghash{$key}; + my ($ia_na, $iaaddr, $starts, $max_life, $pref_life) = @$entry; + my $ts; + if (defined ($starts) && defined ($max_life)) { + my $exp_time = $starts + $max_life; + $ts = localtime($exp_time); + } else { + $ts = "Unknown"; + } + printf ("%-9s %-39s %s\n", $key, $iaaddr, $ts); +} + + + diff --git a/templates/release/dhcpv6/interface/node.def b/templates/release/dhcpv6/interface/node.def new file mode 100644 index 0000000..847df8e --- /dev/null +++ b/templates/release/dhcpv6/interface/node.def @@ -0,0 +1,2 @@ +help: Release a DHCPv6 lease on an interface + diff --git a/templates/release/dhcpv6/interface/node.tag/node.def b/templates/release/dhcpv6/interface/node.tag/node.def new file mode 100644 index 0000000..05f45c8 --- /dev/null +++ b/templates/release/dhcpv6/interface/node.tag/node.def @@ -0,0 +1,10 @@ +help: Release DHCPv6 lease for interface + +allowed: + local -a array + array=( /var/lib/dhcp3/dhclient_v6_*.conf ) + tail=${array[@]#/var/lib/dhcp3/dhclient_v6_} + ifnames=${tail[@]%.conf} + echo -n ${ifnames[@]} + +run: sudo /opt/vyatta/sbin/vyatta-dhcpv6-client.pl --release --ifname "$4" diff --git a/templates/release/dhcpv6/node.def b/templates/release/dhcpv6/node.def new file mode 100644 index 0000000..ed4b8c2 --- /dev/null +++ b/templates/release/dhcpv6/node.def @@ -0,0 +1 @@ +help: Release a DHCPv6 lease \ No newline at end of file diff --git a/templates/renew/dhcpv6/interface/node.def b/templates/renew/dhcpv6/interface/node.def new file mode 100644 index 0000000..eb69706 --- /dev/null +++ b/templates/renew/dhcpv6/interface/node.def @@ -0,0 +1 @@ +help: Renew DHCPv6 lease for an interface \ No newline at end of file diff --git a/templates/renew/dhcpv6/interface/node.tag/node.def b/templates/renew/dhcpv6/interface/node.tag/node.def new file mode 100644 index 0000000..b6c5813 --- /dev/null +++ b/templates/renew/dhcpv6/interface/node.tag/node.def @@ -0,0 +1,10 @@ +help: Renew a DHCPv6 lease on an interface + +allowed: + local -a array + array=( /var/lib/dhcp3/dhclient_v6_*.conf ) + tail=${array[@]#/var/lib/dhcp3/dhclient_v6_} + ifnames=${tail[@]%.conf} + echo -n ${ifnames[@]} + +run: sudo /opt/vyatta/sbin/vyatta-dhcpv6-client.pl --renew --ifname "$4" \ No newline at end of file diff --git a/templates/renew/dhcpv6/node.def b/templates/renew/dhcpv6/node.def new file mode 100644 index 0000000..cbfb1bb --- /dev/null +++ b/templates/renew/dhcpv6/node.def @@ -0,0 +1 @@ +help: Renew a DHCPv6 lease diff --git a/templates/show/dhcpv6/client/leases/node.def b/templates/show/dhcpv6/client/leases/node.def new file mode 100644 index 0000000..8eb6954 --- /dev/null +++ b/templates/show/dhcpv6/client/leases/node.def @@ -0,0 +1,3 @@ +help: Display DHCPv6 client leases + +run: sudo /opt/vyatta/sbin/dhcpv6-client-show-leases.pl diff --git a/templates/show/dhcpv6/client/node.def b/templates/show/dhcpv6/client/node.def new file mode 100644 index 0000000..7c5b0c3 --- /dev/null +++ b/templates/show/dhcpv6/client/node.def @@ -0,0 +1 @@ +help: Display DHCPv6 client information -- cgit v1.2.3 From ce660cba1408ac05795b19bc5adaf605b470c34f Mon Sep 17 00:00:00 2001 From: Bob Gilligan Date: Wed, 26 May 2010 16:35:33 -0700 Subject: 0.13.65 --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 24881e6..e8b9ea0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-op (0.13.65) unstable; urgency=low + + * Move DHCPv6 client op-mode commands to this package. + + -- Bob Gilligan Wed, 26 May 2010 16:35:33 -0700 + vyatta-op (0.13.64) unstable; urgency=low * Don't allow the currently running image to be renamed. -- cgit v1.2.3