diff options
| -rw-r--r-- | Makefile.am | 2 | ||||
| -rw-r--r-- | debian/changelog | 6 | ||||
| -rw-r--r-- | debian/control | 3 | ||||
| -rwxr-xr-x | scripts/vyatta-show-version | 255 | ||||
| -rw-r--r-- | scripts/vyos-show-version | 106 | ||||
| -rw-r--r-- | templates/show/version/added/node.def | 2 | ||||
| -rw-r--r-- | templates/show/version/all/node.def | 5 | ||||
| -rw-r--r-- | templates/show/version/deleted/node.def | 2 | ||||
| -rw-r--r-- | templates/show/version/downgraded/node.def | 2 | ||||
| -rw-r--r-- | templates/show/version/funny/node.def | 2 | ||||
| -rw-r--r-- | templates/show/version/node.def | 2 | ||||
| -rw-r--r-- | templates/show/version/upgraded/node.def | 2 | 
12 files changed, 121 insertions, 268 deletions
| diff --git a/Makefile.am b/Makefile.am index e736419..8212b02 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,7 @@ interp_DATA += functions/interpreter/vyatta-image-complete  bin_SCRIPTS	 = scripts/vyatta-show-interfaces  bin_SCRIPTS	+= scripts/vyatta-show-interfaces.pl -bin_SCRIPTS	+= scripts/vyatta-show-version +bin_SCRIPTS	+= scripts/vyos-show-version  bin_SCRIPTS     += scripts/vyatta-show-dhclient.pl  bin_SCRIPTS	+= scripts/vyatta-show-dmi  bin_SCRIPTS	+= scripts/vyatta-tshark-interface-port.pl diff --git a/debian/changelog b/debian/changelog index 5a896d3..8744266 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyatta-op (0.14.0+vyos2+current2) unstable; urgency=medium + +  * New implementation of "run show version" + + --  <daniil@baturin.org>  Thu, 03 Mar 2016 09:57:48 -0500 +  vyatta-op (0.14.0+vyos2+current1) unstable; urgency=medium    [ Thomas Jepp ] diff --git a/debian/control b/debian/control index 1046c54..6062453 100644 --- a/debian/control +++ b/debian/control @@ -32,7 +32,8 @@ Depends: sed (>= 4.1.5),   libtimedate-perl,   usbutils,   lsscsi, - hvinfo + hvinfo, + python-pystache  Suggests: util-linux (>= 2.13-5),   ncurses-bin (>= 5.5-5),   dialog diff --git a/scripts/vyatta-show-version b/scripts/vyatta-show-version deleted file mode 100755 index dd4f7bc..0000000 --- a/scripts/vyatta-show-version +++ /dev/null @@ -1,255 +0,0 @@ -#!/usr/bin/perl -w -# -# Module: show_version -# -# **** 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) 2005-2013 Vyatta, Inc. -# All Rights Reserved. -# -# Author: Rick Balocca -# Date: 2007 -# Description: -# -# **** End License **** -# -use strict; -use warnings; - -# -# Global hash of debians in the base install and now. -# -my $rHoH_base_debs; -my $rHoH_now_debs; - -my $base          = '/opt/vyatta/etc'; -my $versionfile   = "$base/version"; -my $buildfile     = "$base/build.txt"; -my $debsfile      = "$base/deb-versions.txt"; - -sub echo_file { -    my ($file) = @_; - -    my @lines = (); -    if (!(-e $file)) { -	return @lines; -    } - -    open(my $FH, '<', $file) or die "Unable to open [$file]\n"; -    @lines=<$FH>; -    close($FH); -    return @lines; -} - -# This follows the chain from /boot/grub/menu.cfg which -# boots /boot/vmlinuz to find the version of kernel running -sub get_image_type { -    my $kernel = readlink('/boot/vmlinuz'); -    my $version; - -    unless (defined($kernel)) { -	warn "Can not read link /boot/vmlinuz: $!\n"; -	return; -    } - -    unless ($kernel =~ /^vmlinuz-.*-([^-]*)-(vyatta|vyos)(.*)$/) { -	warn "Unknown kernel version: $kernel\n"; -	return; -    } - -    # XXX: Maybe just check 'uname -m' ? -    if ($1 eq '586') { -	$version = "x86 32-bit"; -    } elsif ($1 eq "amd64") { -	$version = "x86 64-bit"; -    } else { -	$version = $1; -    } - -    if ($3 eq '-virt') { -	$version .= " Virtual" -    } - -    return $version; -} - -# -# convert the "dpkg -l" output have same format as deb-versions.txt -# -sub get_pkg_version { -    my @lines = @_; - -    my @new_lines = (); -    foreach my $line (@lines) { -	if ($line =~ /^[D\|\+]/) { -	    next;   # skip header -	} -	my ($status, $pkg, $version) = split(/[ \t\n]+/, $line, 4); -	if ($status =~ /^i/) { -	    push(@new_lines, "$pkg $version"); -	} -    } -    return @new_lines; -} - -sub read_pkg_file { -    my @pkgs_list = @_; - -    my %HoH = (); -    my ($name, $version); -    foreach my $line (@pkgs_list) { -	($name, $version) = split(/[ \t\n]+/, $line, 3); -	$HoH{$name}{'version'} = $version; -    } -    return \%HoH; -} - -sub show_added { -    for my $name (sort keys %$rHoH_now_debs) { -	if (!$rHoH_base_debs->{$name}) { -	    printf("Aii %-25s %-25s\n", -		   $name, $rHoH_now_debs->{$name}->{'version'}); -	} -    } -} - -sub show_deleted { -    for my $name (sort keys %$rHoH_base_debs) { -	if (!$rHoH_now_debs->{$name}) { -	    printf("X   %-25s %-25s\n", -		   $name, $rHoH_base_debs->{$name}->{'version'}); -	} -    } -} - -sub show_upgraded_downgraded { -    my ($up_down) = @_; - -    my ($symbol, $op, $ver_base, $ver_now, $cmd); -    if ($up_down eq "upgraded") { -	$symbol = "U"; -	$op = "lt"; -    } else { -	$symbol = "D"; -	$op = "gt"; -    } -    for my $name (sort keys %$rHoH_base_debs) { -	if ($rHoH_now_debs->{$name}) { -	    $ver_base = $rHoH_base_debs->{$name}{'version'}; -	    $ver_now  =  $rHoH_now_debs->{$name}{'version'}; -	    if ($ver_base ne $ver_now) { -		$cmd = "dpkg --compare-versions \"$ver_base\" $op \"$ver_now\""; -		if (!system($cmd)) { -		    printf("%sii %-25s %-20s (baseline: %s)\n", -			   $symbol, $name, $ver_now, $ver_base); -		} -            } -	} -    } -} - -sub show_upgraded { -    show_upgraded_downgraded("upgraded"); -} - -sub show_downgraded { -    show_upgraded_downgraded("downgraded"); -} - -sub show_all { -    show_added(); -    show_deleted(); -    show_upgraded(); -    show_downgraded(); -} - -my %options = ( -    "added"      => \&show_added, -    "deleted",   => \&show_deleted, -    "upgraded"   => \&show_upgraded, -    "downgraded" => \&show_downgraded, -    "all"        => \&show_all, -); - -# -# main -# -my $hv = `hvinfo`; -if (defined($hv) && $hv ne "") { -    $versionfile .= "-virt"; -} -print(&echo_file($versionfile)); -print(&echo_file($buildfile)); - -my $type = get_image_type(); -if ($type) { -    print "System type:  $type\n"; -} - -my $booted = `grep -e '^overlayfs.*/filesystem.squashfs' /proc/mounts`; -if (defined($booted) && $booted ne "") { -    $booted="livecd"; -} else { -    my $image_boot = `grep -e '^overlayfs /' /proc/mounts`; -    if ($image_boot ne "") { -	$booted="image"; -    } else { -	$booted="disk"; -    } -} -print "Boot via:     $booted\n"; - -if (defined($hv) && $hv ne "") { -    chomp $hv; -    print "Hypervisor:   $hv\n"; -} - - -my $plat_model = `sudo /usr/sbin/dmidecode -s system-product-name`; -chomp $plat_model; -my $plat_sn = `sudo /usr/sbin/dmidecode -s system-serial-number`; -chomp $plat_sn; -my $plat_uuid = `sudo /usr/sbin/dmidecode -s system-uuid`; -chomp $plat_uuid; - -if (defined $plat_model && $plat_model ne "" && $plat_model ne " ") { -    print "HW model:     $plat_model\n" -} - -if (defined $plat_sn && $plat_sn ne "" && $plat_sn ne " ") { -    print "HW S/N:       $plat_sn\n" -} - -if (defined $plat_uuid && $plat_uuid ne "" && $plat_uuid ne " ") { -    print "HW UUID:      $plat_uuid\n" -} - -my $uptime = `uptime`; -if (defined $uptime && $uptime ne "") { -    print "Uptime:      $uptime\n"; -} - -if (!(-e $debsfile)) { -    exit 0; -} -print "\n"; -$rHoH_base_debs = read_pkg_file(&echo_file($debsfile)); -$rHoH_now_debs  = read_pkg_file(get_pkg_version(`dpkg -l 2> /dev/null`)); - -if ($#ARGV == 0) { -    if ($options{$ARGV[0]}) { -        $options{$ARGV[0]}->(); -    } else { -	print "Usage: showversion [added|deleted|upgraded|downgraded|all]\n"; -	exit 1; -    } -} diff --git a/scripts/vyos-show-version b/scripts/vyos-show-version new file mode 100644 index 0000000..a701b84 --- /dev/null +++ b/scripts/vyos-show-version @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# +# Copyright (C) 2016 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later 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. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. +# +# File: vyos-show-version +# Purpose: +#    Displays image version and system information. +#    Used by the "run show version" command. + + +import sys +import subprocess +import json + +import pystache + + +def read_file(name): +    with open (name, "r") as f: +        data = f.read() +    return data.strip() + +version_file = '/opt/vyatta/etc/version.json' +version_data = None + +version_output_tmpl = """ +Version:          VyOS {{version}} +Built by:         {{built_by}} +Built on:         {{built_on}} +Build ID:         {{build_id}} + +Architecture:     {{system_arch}} +Boot via:         {{boot_via}} +System type:      {{system_type}} + +Hardware vendor:  {{hardware_vendor}} +Hardware model:   {{hardware_model}} +Hardware S/N:     {{hardware_serial}} +Hardware UUID:    {{hardware_uuid}} + +Copyright:        VyOS maintainers and contributors + +""" + +# Get and display image version data from the built-in version file +# This gives us image version, built on, build by, and build UUID +try: +    with open(version_file, 'r') as f: +        version_data = json.load(f) +except: +    print("Unable to get VyOS version data") +    sys.exit(1) + + +# Get system architecture (well, kernel architecture rather) +version_data['system_arch'] = subprocess.check_output('uname -m', shell=True).strip() + + +# Get hypervisor name, if any +system_type = "physical" +try: +    hypervisor = subprocess.check_output('hvinfo', shell=True).strip() +    system_type = "{0} guest".format(hypervisor) +except CalledProcessError: +    # hvinfo returns 1 if it cannot detect any hypervisor +    pass +version_data['system_type'] = system_type + + +# Get boot type, it can be livecd, installed image, or, possible, a system installed +# via legacy "install system" mechanism +# In installed images, the squashfs image file is named after its image version, +# while on livecd it's just "filesystem.squashfs", that's how we tell a livecd boot +# from an installed image +boot_via = "installed image" +if subprocess.call(""" grep -e '^overlay.*/filesystem.squashfs' /proc/mounts >/dev/null""", shell=True) == 0: +    boot_via = "livecd" +elif subprocess.call(""" grep '^overlay /' /proc/mounts >/dev/null """, shell=True) != 0: +    boot_via = "legacy non-image installation" +version_data['boot_via'] = boot_via +     + +# Get hardware details from DMI +version_data['hardware_vendor'] = read_file('/sys/class/dmi/id/sys_vendor') +version_data['hardware_model']  = read_file('/sys/class/dmi/id/product_name') +# XXX: serial and uuid files are only readable for root, so we cannot just read them +#      when script is ran by a normal user, hence this ugly fixup +version_data['hardware_serial'] = subprocess.check_output('sudo cat /sys/class/dmi/id/subsystem/id/product_serial', shell=True).strip() +version_data['hardware_uuid'] = subprocess.check_output('sudo cat /sys/class/dmi/id/subsystem/id/product_uuid', shell=True).strip() + + +output = pystache.render(version_output_tmpl, version_data).strip() +print(output) + diff --git a/templates/show/version/added/node.def b/templates/show/version/added/node.def deleted file mode 100644 index 2381b74..0000000 --- a/templates/show/version/added/node.def +++ /dev/null @@ -1,2 +0,0 @@ -help: Show VyOS version information plus added packages -run: ${vyatta_bindir}/vyatta-show-version added diff --git a/templates/show/version/all/node.def b/templates/show/version/all/node.def index 5b60609..8344124 100644 --- a/templates/show/version/all/node.def +++ b/templates/show/version/all/node.def @@ -1,2 +1,5 @@  help: Show VyOS version information plus all packages changes -run: ${vyatta_bindir}/vyatta-show-version all +run: ${vyatta_bindir}/vyos-show-version +     echo "" +     echo "Package versions:" +     dpkg -l diff --git a/templates/show/version/deleted/node.def b/templates/show/version/deleted/node.def deleted file mode 100644 index d328cf6..0000000 --- a/templates/show/version/deleted/node.def +++ /dev/null @@ -1,2 +0,0 @@ -help: Show VyOS version information plus deleted packages -run: ${vyatta_bindir}/vyatta-show-version deleted diff --git a/templates/show/version/downgraded/node.def b/templates/show/version/downgraded/node.def deleted file mode 100644 index 250b048..0000000 --- a/templates/show/version/downgraded/node.def +++ /dev/null @@ -1,2 +0,0 @@ -help: Show VyOS version information plus downgraded packages -run: ${vyatta_bindir}/vyatta-show-version downgraded diff --git a/templates/show/version/funny/node.def b/templates/show/version/funny/node.def index cb62c96..e6544f9 100644 --- a/templates/show/version/funny/node.def +++ b/templates/show/version/funny/node.def @@ -1,5 +1,5 @@  help: Show VyOS version information plus a funny poem  run: -    ${vyatta_bindir}/vyatta-show-version +    ${vyatta_bindir}/vyos-show-version      ${vyatta_bindir}/limericks.py diff --git a/templates/show/version/node.def b/templates/show/version/node.def index 4237e5d..e2bfc1f 100644 --- a/templates/show/version/node.def +++ b/templates/show/version/node.def @@ -1,2 +1,2 @@  help: Show VyOS version information -run: ${vyatta_bindir}/vyatta-show-version +run: ${vyatta_bindir}/vyos-show-version diff --git a/templates/show/version/upgraded/node.def b/templates/show/version/upgraded/node.def deleted file mode 100644 index b693c23..0000000 --- a/templates/show/version/upgraded/node.def +++ /dev/null @@ -1,2 +0,0 @@ -help: Show VyOS version information plus upgraded packages -run: ${vyatta_bindir}/vyatta-show-version upgraded | 
