summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2011-06-16 17:55:19 -0400
committerStephen Hemminger <stephen.hemminger@vyatta.com>2011-06-16 17:55:19 -0400
commit9085c5cd7247bd0a4fda63f9841d8b2b37ef7d47 (patch)
tree48154335824d44aef89e88fbeb2e0afd2b758414
parent9960ca2f642872a85dabff5920a8ca62e1b322df (diff)
downloadvyatta-op-9085c5cd7247bd0a4fda63f9841d8b2b37ef7d47.tar.gz
vyatta-op-9085c5cd7247bd0a4fda63f9841d8b2b37ef7d47.zip
Display image type and hypervisor in show version
Bug 6769 Add System type which decodes the type of kernel on the system, and Hypervisor which shows if the system is in virtual environment. Note: the Hypervisor, Uptime should really be part of another command since they aren't a property of the system image but of the system it is being run on but that is splitting hairs. vyatta@napa:~$ show version Version: 999.napa.06160039 Description: 999.napa.06160039 Copyright: 2006-2011 Vyatta, Inc. Built by: autobuild@vyatta.com Built on: Thu Jun 16 07:39:16 UTC 2011 Build ID: 1106160739-bcfda33 System type: Intel 64bit Boot via: disk Hypervisor: VMware Uptime: 21:56:32 up 1:16, 2 users, load average: 0.03, 0.03, 0.05
-rwxr-xr-xscripts/vyatta-show-version73
1 files changed, 57 insertions, 16 deletions
diff --git a/scripts/vyatta-show-version b/scripts/vyatta-show-version
index 03eb83b..c8a315d 100755
--- a/scripts/vyatta-show-version
+++ b/scripts/vyatta-show-version
@@ -1,27 +1,27 @@
#!/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, 2006, 2007 Vyatta, Inc.
# All Rights Reserved.
-#
+#
# Author: Rick Balocca
# Date: 2007
# Description:
-#
+#
# **** End License ****
-#
+#
use strict;
use warnings;
@@ -43,19 +43,50 @@ sub echo_file {
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(.*)$/) {
+ warn "Unknown kernel version: $kernel\n";
+ return;
+ }
+
+ if ($1 eq '586') {
+ $version = "Intel 32bit";
+ } elsif ($1 eq "amd64") {
+ $version = "Intel 64bit";
+ } else {
+ $version = $1;
+ }
+
+ if ($2 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\|\+]/) {
@@ -84,7 +115,7 @@ sub read_pkg_file {
sub show_added {
for my $name (sort keys %$rHoH_now_debs) {
if (!$rHoH_base_debs->{$name}) {
- printf("Aii %-25s %-25s\n",
+ printf("Aii %-25s %-25s\n",
$name, $rHoH_now_debs->{$name}->{'version'});
}
}
@@ -93,7 +124,7 @@ sub show_added {
sub show_deleted {
for my $name (sort keys %$rHoH_base_debs) {
if (!$rHoH_now_debs->{$name}) {
- printf("X %-25s %-25s\n",
+ printf("X %-25s %-25s\n",
$name, $rHoH_base_debs->{$name}->{'version'});
}
}
@@ -101,7 +132,7 @@ sub show_deleted {
sub show_upgraded_downgraded {
my ($up_down) = @_;
-
+
my ($symbol, $op, $ver_base, $ver_now, $cmd);
if ($up_down eq "upgraded") {
$symbol = "U";
@@ -117,11 +148,11 @@ sub show_upgraded_downgraded {
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",
+ printf("%sii %-25s %-20s (baseline: %s)\n",
$symbol, $name, $ver_now, $ver_base);
}
}
- }
+ }
}
}
@@ -154,6 +185,11 @@ my %options = (
print(&echo_file($versionfile));
print(&echo_file($buildfile));
+my $type = get_image_type();
+if ($type) {
+ print "System type: $type\n";
+}
+
my $booted = `grep -e '^unionfs.*/filesystem.squashfs' -e '^aufs.*/filesystem.squashfs' /proc/mounts`;
if (defined($booted) && $booted ne "") {
$booted="livecd";
@@ -166,14 +202,21 @@ if (defined($booted) && $booted ne "") {
}
}
print "Boot via: $booted\n";
+
+my $hv = `/opt/vyatta/sbin/hypervisor_vendor`;
+if (defined($hv) && $hv ne "") {
+ chomp $hv;
+ print "Hypervisor: $hv\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`));
@@ -186,5 +229,3 @@ if ($#ARGV == 0) {
exit 1;
}
}
-
-# end of file