[kernel] r17170 - in dists/trunk/linux-base: bin lib man

Ben Hutchings benh at alioth.debian.org
Fri Apr 1 02:14:20 UTC 2011


Author: benh
Date: Fri Apr  1 02:14:19 2011
New Revision: 17170

Log:
Add list_versions() subroutine and linux-version list sub-command

Modified:
   dists/trunk/linux-base/bin/linux-version
   dists/trunk/linux-base/lib/DebianLinux.pm
   dists/trunk/linux-base/man/linux-version.1

Modified: dists/trunk/linux-base/bin/linux-version
==============================================================================
--- dists/trunk/linux-base/bin/linux-version	Fri Apr  1 01:52:49 2011	(r17169)
+++ dists/trunk/linux-base/bin/linux-version	Fri Apr  1 02:14:19 2011	(r17170)
@@ -19,13 +19,14 @@
 use strict;
 use warnings;
 
-use DebianLinux qw(version_cmp);
+use DebianLinux qw(version_cmp image_list);
 
 sub usage {
     my $fh = shift;
     print $fh (<< 'EOT');
 Usage: $0 compare VERSION1 OP VERSION2
        $0 sort [--reverse] VERSION1 VERSION2 ...
+       $0 list [--paths]
 
 The version arguments should be kernel version strings as shown by
 'uname -r' and used in filenames.
@@ -69,6 +70,26 @@
     exit 0;
 }
 
+sub list_versions {
+    my $show_paths;
+
+    if (@_ == 1 and $_[0] eq '--paths') {
+	$show_paths = 1;
+    } elsif (@_ != 0) {
+	usage_error();
+    }
+
+    for (image_list()) {
+	my ($version, $path) = @$_;
+	if ($show_paths) {
+	    print "$version $path\n";
+	} else {
+	    print "$version\n";
+	}
+    }
+    exit 0;
+}
+
 if (@ARGV == 0) {
     usage_error();
 }
@@ -81,5 +102,7 @@
     compare_versions(@ARGV);
 } elsif ($command eq 'sort') {
     sort_versions(@ARGV);
+} elsif ($command eq 'list') {
+    list_versions(@ARGV);
 }
 usage_error();

Modified: dists/trunk/linux-base/lib/DebianLinux.pm
==============================================================================
--- dists/trunk/linux-base/lib/DebianLinux.pm	Fri Apr  1 01:52:49 2011	(r17169)
+++ dists/trunk/linux-base/lib/DebianLinux.pm	Fri Apr  1 02:14:19 2011	(r17170)
@@ -18,11 +18,12 @@
 
 use strict;
 use warnings;
+use POSIX qw(uname);
 
 BEGIN {
     use Exporter ();
     our @ISA = qw(Exporter);
-    our @EXPORT_OK = qw(version_cmp);
+    our @EXPORT_OK = qw(version_cmp image_list);
 }
 
 sub version_split {
@@ -71,4 +72,22 @@
     }
 }
 
+# Find kernel image name stem for this architecture
+my $image_stem;
+if ((uname())[4] =~ /^(?:mips|parisc|powerpc|ppc)/) {
+    $image_stem = 'vmlinux';
+} else {
+    $image_stem = 'vmlinuz';
+}
+
+sub image_list {
+    my @results;
+    my $prefix = "/boot/$image_stem-";
+
+    for (glob("$prefix*")) {
+	push @results, [substr($_, length($prefix)), $_];
+    }
+    return @results;
+}
+
 1;

Modified: dists/trunk/linux-base/man/linux-version.1
==============================================================================
--- dists/trunk/linux-base/man/linux-version.1	Fri Apr  1 01:52:49 2011	(r17169)
+++ dists/trunk/linux-base/man/linux-version.1	Fri Apr  1 02:14:19 2011	(r17170)
@@ -6,6 +6,8 @@
 .BI linux\-version\ compare \ VERSION1\ OP\ VERSION2
 .HP
 .BR linux\-version\ sort \ [ \-\-reverse ]
+.HP
+.BR linux\-version\ list \ [ \-\-paths ]
 .IR VERSION1\ VERSION2 \ ...
 .SH DESCRIPTION
 \fBlinux\-version\fR operates on Linux kernel version strings as
@@ -24,6 +26,10 @@
 Sort the given version numbers and print them in order from lowest to
 highest.  If the \fB\-\-reverse\fR option is used, print them in order
 from highest to lowest.
+.TP
+\fBlist\fR [\fB\-\-paths\fR]
+List kernel versions installed in the customary location.  If the
+\fB\-\-paths\fR option, show the corresponding path for each version.
 .SH AUTHOR
 \fBlinux\-version\fR and this manual page were written by Ben
 Hutchings as part of the Debian \fBlinux\-base\fR package.



More information about the Kernel-svn-changes mailing list