diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-12-18 16:27:04 -0800 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-12-18 16:27:04 -0800 |
commit | 893cca45601d35972a727fa5c71eb481f9df9b3b (patch) | |
tree | 7b4ba0fc88684cf5fb657dbb3666568529f636e6 | |
parent | 5792e5ffc5683493f04dc5f5f13c583b855cffcf (diff) | |
parent | 3862673db6fa8b7b6c0eff2e15bda167b84c7af1 (diff) | |
download | vyatta-op-893cca45601d35972a727fa5c71eb481f9df9b3b.tar.gz vyatta-op-893cca45601d35972a727fa5c71eb481f9df9b3b.zip |
Merge branch 'kenwood' of suva.vyatta.com:/git/vyatta-op into kenwood
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | debian/changelog | 33 | ||||
-rw-r--r-- | debian/control | 1 | ||||
-rwxr-xr-x | scripts/vyatta-boot-image.pl | 302 | ||||
-rw-r--r-- | templates/clear/interfaces/connection/node.def | 1 | ||||
-rw-r--r-- | templates/clear/interfaces/connection/node.tag/node.def | 53 | ||||
-rw-r--r-- | templates/clear/interfaces/node.def | 1 | ||||
-rw-r--r-- | templates/connect/interface/node.def | 2 | ||||
-rw-r--r-- | templates/connect/interface/node.tag/node.def | 28 | ||||
-rw-r--r-- | templates/connect/node.def | 1 | ||||
-rw-r--r-- | templates/disconnect/interface/node.def | 2 | ||||
-rw-r--r-- | templates/disconnect/interface/node.tag/node.def | 34 | ||||
-rw-r--r-- | templates/disconnect/node.def | 2 | ||||
-rw-r--r-- | templates/install-image/node.def | 2 | ||||
-rw-r--r-- | templates/install-image/node.tag/node.def | 3 | ||||
-rw-r--r-- | templates/remove/installed-image/node.def | 2 | ||||
-rw-r--r-- | templates/set/system/boot-image/node.def | 2 | ||||
-rw-r--r-- | templates/set/system/node.def | 1 | ||||
-rw-r--r-- | templates/show/system/installed-images/node.def | 2 |
19 files changed, 473 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index 0660d3a..a9deebe 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,6 +22,7 @@ bin_SCRIPTS += scripts/vyatta-cpu-summary.pl bin_SCRIPTS += scripts/yesno bin_SCRIPTS += scripts/vyatta-gettime.pl bin_SCRIPTS += scripts/show-users.pl +bin_SCRIPTS += scripts/vyatta-boot-image.pl bin_sudo_users_SCRIPTS = scripts/vyatta-identify-interface.pl bin_sudo_users_SCRIPTS += scripts/vyatta-delete-log-file.sh diff --git a/debian/changelog b/debian/changelog index da02296..efac41a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,36 @@ +vyatta-op (0.13.28) unstable; urgency=low + + * Use new cleaner command arguments + + -- Stephen Hemminger <stephen.hemminger@vyatta.com> Wed, 16 Dec 2009 12:06:35 -0800 + +vyatta-op (0.13.27) unstable; urgency=low + + * add op command for image removal + + -- An-Cheng Huang <ancheng@vyatta.com> Wed, 11 Nov 2009 18:19:24 -0800 + +vyatta-op (0.13.26) unstable; urgency=low + + * Prevent problems on upgrade for files moved from vyatta-serial to + this package + + -- Mohit Mehta <mohit.mehta@vyatta.com> Mon, 09 Nov 2009 16:06:49 -0800 + +vyatta-op (0.13.25) unstable; urgency=low + + * move generic interface op commands to vyatta-op + + -- An-Cheng Huang <ancheng@vyatta.com> Mon, 09 Nov 2009 11:51:05 -0800 + +vyatta-op (0.13.24) unstable; urgency=low + + * add .merge-branch-exclude + * add install-image op commands + * add op commands for installed images + + -- An-Cheng Huang <ancheng@vyatta.com> Wed, 04 Nov 2009 15:32:46 -0800 + vyatta-op (0.13.23) unstable; urgency=low * Decolorize show system login users diff --git a/debian/control b/debian/control index a6a8638..ce59bec 100644 --- a/debian/control +++ b/debian/control @@ -24,6 +24,7 @@ Depends: sed (>= 4.1.5), at, net-tools, libtimedate-perl +Replaces: vyatta-serial Suggests: util-linux (>= 2.13-5), ncurses-bin (>= 5.5-5), Description: bash operational command completion diff --git a/scripts/vyatta-boot-image.pl b/scripts/vyatta-boot-image.pl new file mode 100755 index 0000000..7a4a85d --- /dev/null +++ b/scripts/vyatta-boot-image.pl @@ -0,0 +1,302 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Getopt::Long; +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'; + +# this function parses the grub config file and returns a hash reference +# of the parsed data. +sub parseGrubCfg { + my $fd = undef; + return undef if (!open($fd, '<', $UNION_GRUB_CFG)); + + my %ghash = (); + my @entries = (); + my $in_entry = 0; + my $idx = 0; + while (<$fd>) { + if ($in_entry) { + if (/^}/) { + $in_entry = 0; + ++$idx; + } elsif (/^\s+linux /) { + my %ehash = ( + 'idx' => $idx, + 'ver' => undef, + 'term' => undef, + 'reset' => undef + ); + # kernel line + if (/^\s+linux \/boot\/([^\/ ]+)\/.* boot=live /) { + # union install + $ehash{'ver'} = $1; + } else { + # old install + $ehash{'ver'} = $OLD_IMG_VER_STR; + } + if (/console=tty0.*console=ttyS0/) { + $ehash{'term'} = 'serial'; + } else { + $ehash{'term'} = 'kvm'; + } + if (/standalone_root_pw_reset/) { + $ehash{'reset'} = 1; + } else { + $ehash{'reset'} = 0; + } + push @entries, \%ehash; + } + } elsif (/^set default=(\d+)$/) { + $ghash{'default'} = $1; + } elsif (/^menuentry /) { + $in_entry = 1; + } + } + close($fd); + $ghash{'entries'} = \@entries; + return \%ghash; +} + +# this function deletes the entries for the specified version from the grub +# config file. returns undef if successful. otherwise returns error message. +sub deleteGrubEntries { + my ($del_ver) = @_; + + my $rfd = undef; + return 'Cannot delete GRUB entries' if (!open($rfd, '<', $UNION_GRUB_CFG)); + my ($wfd, $tfile) = mkstemp('/tmp/boot-image.XXXXXX'); + + my @entry = (); + my ($in_entry, $ver) = (0, 0); + while (<$rfd>) { + next if (/^$/); # ignore empty lines + if ($in_entry) { + if (/^}/) { + if ($ver ne $del_ver) { + # output entry + print $wfd "\n"; + foreach my $l (@entry) { + print $wfd $l; + } + print $wfd "}\n"; + } + $in_entry = 0; + $ver = 0; + @entry = (); + } else { + if (/^\s+linux \/boot\/([^\/ ]+)\/.* boot=live /) { + # kernel line + $ver = $1; + } + push @entry, $_; + } + } elsif (/^menuentry /) { + $in_entry = 1; + push @entry, $_; + } else { + print $wfd $_; + } + } + close($wfd); + close($rfd); + + my $p = (stat($UNION_GRUB_CFG))[2]; + return 'Failed to modify GRUB configuration' + if (!defined($p) || !chmod(($p & 07777), $tfile)); + system("mv $tfile $UNION_GRUB_CFG"); + return 'Failed to delete GRUB entries' if ($? >> 8); + return undef; +} + +# this function takes the default terminal type and a list of all entries +# and returns the "boot list", i.e., the list for user to select which one +# to boot. +sub getBootList { + my ($dver, $dterm, $entries, $delete) = @_; + my %vhash = (); + 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); + + next if ($_->{'reset'}); # skip password reset entry + next if ($term ne $dterm); # not the default terminal + next if (defined($vhash{$ver})); # version already in list + + $vhash{$ver} = 1; + push @list, $_; + } + return \@list; +} + +sub displayBootList { + my ($didx, $entries) = @_; + for my $i (0 .. $#{$entries}) { + my $di = $i + 1; + my $ver = ${$entries}[$i]->{'ver'}; + my $m = ''; + if ($didx == ${$entries}[$i]->{'idx'}) { + $m = ' (default boot)'; + } + printf " %2d: %s%s\n", $di, $ver, $m; + } +} + +my ($show, $del, $sel) = (undef, undef, undef); +GetOptions( + 'show' => \$show, + 'delete' => \$del, + 'select' => \$sel +); + +my $gref = parseGrubCfg(); +if (!defined($gref)) { + print "Cannot find GRUB configuration file. Exiting...\n"; + exit 1; +} +my $def_idx = $gref->{'default'}; +my $entries = $gref->{'entries'}; +if (!defined($def_idx) || !defined($entries) + || !defined(${$entries}[$def_idx])) { + print "Error parsing GRUB configuration file. Exiting...\n"; + exit 1; +} +my $def_ver = ${$entries}[$def_idx]->{'ver'}; +my $def_term = ${$entries}[$def_idx]->{'term'}; + +my $bentries = getBootList($def_ver, $def_term, $entries, $del); +if ($#{$bentries} < 0) { + print "No images found. Exiting...\n"; + exit 1; +} + +my $msg = 'The system currently has the following image(s) installed:'; +if (defined($del)) { + # doing delete + $msg = 'The following image(s) can be deleted:'; +} +print "$msg\n\n"; +displayBootList($def_idx, $bentries); +print "\n"; + +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) { + # doing delete + $prompt_msg = 'Select the image to delete: '; + $error_msg = 'Invalid selection. Nothing is deleted.'; +} + +print "$prompt_msg"; +my $resp = <STDIN>; +if (defined($resp)) { + chomp($resp); + if (!($resp =~ /^\d+$/) || ($resp < 1) || ($resp > ($#{$bentries} + 1))) { + $resp = undef; + } +} +if (!defined($resp)) { + print "$error_msg Exiting...\n"; + exit 1; +} +print "\n"; + +$resp -= 1; + +if ($sel) { + doSelect($resp); +} elsif ($del) { + doDelete($resp); +} +exit 0; + +sub doSelect { + my ($bdx) = @_; + my $new_idx = ${$bentries}[$resp]->{'idx'}; + my $new_ver = ${$bentries}[$resp]->{'ver'}; + system("sed -i 's/^set default=.*\$/set default=$new_idx/' $UNION_GRUB_CFG"); + if ($? >> 8) { + print "Failed to set the default boot image. Exiting...\n"; + exit 1; + } + print <<EOF; +Default boot image has been set to "$new_ver". +You need to reboot the system to start the new default image. + +EOF + exit 0; +} + +sub curVer { + my ($fd, $ver) = (undef, undef); + open($fd, '<', $VER_FILE) or return undef; + while (<$fd>) { + next if (!(/^Version\s+:\s+(\S+)$/)); + $ver = $1; + last; + } + close($fd); + return $ver; +} + +sub doDelete { + my ($bdx) = @_; + my $del_ver = ${$bentries}[$resp]->{'ver'}; + print "Are you sure you want to delete the\n\"$del_ver\" image? "; + print '(Yes/No) [No]: '; + my $resp = <STDIN>; + if (!defined($resp)) { + $resp = 'no'; + } + chomp($resp); + $resp = lc($resp); + if ($resp ne 'yes') { + print "Image is NOT deleted. Exiting...\n"; + exit 1; + } + + my $cver = curVer(); + if (!defined($cver)) { + print "Cannot verify current version. Exiting...\n"; + exit 1; + } + if ($cver eq $del_ver) { + print <<EOF; +Cannot delete current running image. Reboot into a different version +before deleting. Exiting... +EOF + exit 1; + } + if (! -d "$UNION_BOOT/$del_ver") { + print "Cannot find the target image. Exiting...\n"; + exit 1; + } + + print "Deleting the \"$del_ver\" image..."; + my $err = deleteGrubEntries($del_ver); + if (defined($err)) { + print "$err. Exiting...\n"; + exit 1; + } + system("rm -rf '$UNION_BOOT/$del_ver'"); + if ($? >> 8) { + print "Error deleting the image. Exiting...\n"; + exit 1; + } + + print "Done\n"; + exit 0; +} + diff --git a/templates/clear/interfaces/connection/node.def b/templates/clear/interfaces/connection/node.def new file mode 100644 index 0000000..cf1d414 --- /dev/null +++ b/templates/clear/interfaces/connection/node.def @@ -0,0 +1 @@ +help: Reset datalink layer connection to peer diff --git a/templates/clear/interfaces/connection/node.tag/node.def b/templates/clear/interfaces/connection/node.tag/node.def new file mode 100644 index 0000000..e936cde --- /dev/null +++ b/templates/clear/interfaces/connection/node.tag/node.def @@ -0,0 +1,53 @@ +help: Bring datalink layer connection down and back up + +allowed: local -a array ; + array=( /etc/ppp/peers/pppoe* /etc/ppp/peers/pppoa* /etc/ppp/peers/wan* /etc/ppp/peers/wlm* ) ; + echo -n ${array[@]##*/} + +run: ( + IFNAME=${4} + LOGFILE=/var/log/vyatta/ppp_${IFNAME}.log + if [ ! -e /etc/ppp/peers/$IFNAME ]; then + echo "Invalid interface: $IFNAME" + builtin exit 1 + fi + + # Serial PPP interfaces are started with "pon", which + # lingers around as a watchdog process. Sometimes + # multiple "pon" scripts are running. So we need to kill + # all pon scripts relating to this interface before + # before killing the pppd process. + if [ "${IFNAME::3}" = "wan" ]; then + PON_PIDS=` ps -C pon -f | grep $IFNAME | awk '{print $2}'` + if [ -n "$PON_PIDS" ]; then + echo "Killing pon pids: $PON_PIDS" + for PID in $PON_PIDS ; do + kill -HUP $PID + done + fi + fi + + if [ -d /sys/class/net/${IFNAME} ]; then + # interface is up, lets bring it down... + echo "Bringing interface $IFNAME down..." + echo "`date`: User $USER stopping PPP daemon for $IFNAME by clear command" >> $LOGFILE + sudo /sbin/poff $IFNAME + elif [ ! -z "`ps -C pppd -f | grep $IFNAME `" ]; then + # Connection is in the process of being established + echo "Stopping connection establishment for interface ${IFNAME}..." + echo "`date`: User $USER stopping PPP daemon for $IFNAME by clear command" >> $LOGFILE + sudo /sbin/poff $IFNAME + fi + + # now PPP layer should be down + echo "Bringing interface $IFNAME back up..." + echo "`date`: User $USER starting PPP daemon for $IFNAME by clear command" >> $LOGFILE + if [ "${IFNAME::3}" = "wan" ]; then + # Serial interfaces are started with "pon" + (umask 0; sudo /usr/sbin/pon $IFNAME > \ + /dev/null 2>&1 & ) + else + ( umask 0; sudo /usr/sbin/pppd call $IFNAME > \ + /tmp/${IFNAME}.log 2>&1 & ) + fi +) diff --git a/templates/clear/interfaces/node.def b/templates/clear/interfaces/node.def new file mode 100644 index 0000000..74924aa --- /dev/null +++ b/templates/clear/interfaces/node.def @@ -0,0 +1 @@ +help: Clear interface information diff --git a/templates/connect/interface/node.def b/templates/connect/interface/node.def new file mode 100644 index 0000000..a94a721 --- /dev/null +++ b/templates/connect/interface/node.def @@ -0,0 +1,2 @@ +help: Bring up a connection-oriented network interface + diff --git a/templates/connect/interface/node.tag/node.def b/templates/connect/interface/node.tag/node.def new file mode 100644 index 0000000..dd806e3 --- /dev/null +++ b/templates/connect/interface/node.tag/node.def @@ -0,0 +1,28 @@ +help: Bring up connection-oriented interface + +allowed: local -a array ; + array=( /etc/ppp/peers/pppoe* /etc/ppp/peers/pppoa* /etc/ppp/peers/wan* /etc/ppp/peers/wlm* ) ; + echo -n ${array[@]##*/} + +run: + IFNAME=${3} + LOGFILE=/var/log/vyatta/ppp_${IFNAME}.log + if [ ! -e /etc/ppp/peers/$IFNAME ]; then + echo "Invalid interface: $3" + elif [ -d /sys/class/net/$IFNAME ]; then + echo "Interface $IFNAME is already connected." + elif [ ! -z "`ps -C pppd -f | grep $IFNAME `" ]; then + echo "Interface ${IFNAME}: Connection is being established." + else + echo "Bringing interface $IFNAME up..." + echo "`date`: User $USER starting PPP daemon for $IFNAME by connect command" >> $LOGFILE + if [ "${IFNAME::3}" = "wan" ]; then + # Serial interfaces are started with "pon" + (umask 0; sudo /usr/sbin/pon $IFNAME > \ + /dev/null 2>&1 & ) + else + # PPPOE, PPPOA, WLM interfaces are started directly + ( umask 0; sudo /usr/sbin/pppd call $IFNAME > \ + /tmp/${IFNAME}.log 2>&1 & ) + fi + fi diff --git a/templates/connect/node.def b/templates/connect/node.def new file mode 100644 index 0000000..471f21f --- /dev/null +++ b/templates/connect/node.def @@ -0,0 +1 @@ +help: Establish a connection diff --git a/templates/disconnect/interface/node.def b/templates/disconnect/interface/node.def new file mode 100644 index 0000000..c7d88e8 --- /dev/null +++ b/templates/disconnect/interface/node.def @@ -0,0 +1,2 @@ +help: Take down a connection-oriented network interface + diff --git a/templates/disconnect/interface/node.tag/node.def b/templates/disconnect/interface/node.tag/node.def new file mode 100644 index 0000000..85233ec --- /dev/null +++ b/templates/disconnect/interface/node.tag/node.def @@ -0,0 +1,34 @@ +help: Bring connection-oriented interface down + +allowed: local -a array ; + array=( /etc/ppp/peers/pppoe* /etc/ppp/peers/pppoa* /etc/ppp/peers/wan* /etc/ppp/peers/wlm* ) ; + echo -n ${array[@]##*/} + +run: + IFNAME=${3} + LOGFILE=/var/log/vyatta/ppp_${IFNAME}.log + if [ ! -e /etc/ppp/peers/${IFNAME} ]; then + echo "Invalid interface: $IFNAME" + elif [ -z "`ps -C pppd -f | grep $IFNAME`" ]; then + echo "Interface $IFNAME: Connection is already down" + else + # Serial PPP interfaces are started with "pon", which + # lingers around as a watchdog process. Sometimes + # multiple "pon" scripts are running. So we need to kill + # all pon scripts relating to this interface before + # before killing the pppd process + if [ "${IFNAME::3}" = "wan" ]; then + PON_PIDS=` ps -C pon -f | grep $IFNAME | awk '{print $2}'` + if [ -n "$PON_PIDS" ]; then + echo "killing pon pids: $PON_PIDS" + for PID in $PON_PIDS ; do + kill -HUP $PID + done + fi + fi + + echo "Bringing interface $IFNAME down..." + echo "`date`: User $USER stopping PPP daemon for $IFNAME by disconnect command" >> $LOGFILE + sudo /sbin/poff $IFNAME + fi + diff --git a/templates/disconnect/node.def b/templates/disconnect/node.def new file mode 100644 index 0000000..fce9a97 --- /dev/null +++ b/templates/disconnect/node.def @@ -0,0 +1,2 @@ +help: Take down a connection + diff --git a/templates/install-image/node.def b/templates/install-image/node.def new file mode 100644 index 0000000..e229319 --- /dev/null +++ b/templates/install-image/node.def @@ -0,0 +1,2 @@ +help: Install new system image to hard drive +run: sudo /opt/vyatta/sbin/install-image diff --git a/templates/install-image/node.tag/node.def b/templates/install-image/node.tag/node.def new file mode 100644 index 0000000..af0ecad --- /dev/null +++ b/templates/install-image/node.tag/node.def @@ -0,0 +1,3 @@ +help: The new system image file to be installed +allowed: echo -n '<ISO_image_file>' +run: sudo /opt/vyatta/sbin/install-image "$2" diff --git a/templates/remove/installed-image/node.def b/templates/remove/installed-image/node.def new file mode 100644 index 0000000..1d116e2 --- /dev/null +++ b/templates/remove/installed-image/node.def @@ -0,0 +1,2 @@ +help: Remove an installed image from the system +run: sudo /opt/vyatta/bin/vyatta-boot-image.pl --delete diff --git a/templates/set/system/boot-image/node.def b/templates/set/system/boot-image/node.def new file mode 100644 index 0000000..c5848a4 --- /dev/null +++ b/templates/set/system/boot-image/node.def @@ -0,0 +1,2 @@ +help: Set the system default boot image +run: sudo /opt/vyatta/bin/vyatta-boot-image.pl --select diff --git a/templates/set/system/node.def b/templates/set/system/node.def new file mode 100644 index 0000000..eef577c --- /dev/null +++ b/templates/set/system/node.def @@ -0,0 +1 @@ +help: Set system operational parameters diff --git a/templates/show/system/installed-images/node.def b/templates/show/system/installed-images/node.def new file mode 100644 index 0000000..08caab7 --- /dev/null +++ b/templates/show/system/installed-images/node.def @@ -0,0 +1,2 @@ +help: Show installed Vyatta images +run: /opt/vyatta/bin/vyatta-boot-image.pl --show |