/usr/bin/linux-version is in linux-base 4.0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #!/usr/bin/perl
# Copyright 2011 Ben Hutchings
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
use strict;
use warnings;
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.
The valid comparison operators are: lt le eq ge gt
EOT
}
sub usage_error {
usage(*STDERR{IO});
exit 2;
}
sub compare_versions {
my %op_map = qw(lt < le <= eq == ge >= gt >);
# Check arguments
if (@_ != 3) {
usage_error();
}
my ($left, $op, $right) = @_;
if (!exists($op_map{$op})) {
usage_error();
}
my $sign = version_cmp($left, $right);
exit !eval("$sign ${op_map{$op}} 0");
}
sub sort_versions {
# Check for --reverse option
my $sign = 1;
if (@_ >= 1 and $_[0] eq '--reverse') {
$sign = -1;
shift;
}
# Collect versions from argv or stdin (with optional suffix after a space)
my @versions;
if (@_) {
@versions = map({[$_, "\n"]} @_);
} else {
while (<STDIN>) {
/^([^ ]*)(.*\n?)$/ or die;
push @versions, [$1, $2];
}
}
for (sort({version_cmp($a->[0], $b->[0]) * $sign} @versions)) {
print @$_;
}
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();
}
my $command = shift;
if ($command eq 'help' or grep({$_ eq '--help'} $command, @ARGV)) {
usage(*STDOUT{IO});
exit 0;
} elsif ($command eq 'compare') {
compare_versions(@ARGV);
} elsif ($command eq 'sort') {
sort_versions(@ARGV);
} elsif ($command eq 'list') {
list_versions(@ARGV);
}
usage_error();
|