2013-09-30 11:50:42 +02:00
#!/usr/bin/perl
2011-08-23 07:40:22 +02:00
use strict;
2013-09-30 11:50:42 +02:00
use warnings;
2013-06-21 11:21:57 +02:00
use POSIX;
2011-08-23 07:40:22 +02:00
use Getopt::Long;
2013-06-21 11:21:57 +02:00
use PVE::API2::APT;
2011-08-23 07:40:22 +02:00
2013-06-21 11:21:57 +02:00
my $pkgarray = PVE::API2::APT->versions({ node => 'localhost'});
my $pkglist = {};
foreach my $pkg (@$pkgarray) {
$pkglist->{$pkg->{Package}} = $pkg;
2011-08-23 07:40:22 +02:00
}
sub print_status {
2013-06-21 11:21:57 +02:00
my ($pkg) = @_;
my $pkginfo = $pkglist->{$pkg};
2011-08-23 07:40:22 +02:00
2013-06-21 11:21:57 +02:00
if (!$pkginfo) {
print "$pkg: unknown package - internal error\n";
return;
}
2011-08-23 07:40:22 +02:00
my $version = "not correctly installed";
2013-06-21 11:21:57 +02:00
if ($pkginfo->{OldVersion} && $pkginfo->{CurrentState} eq 'Installed') {
$version = $pkginfo->{OldVersion};
2011-08-23 07:40:22 +02:00
}
2013-06-21 11:21:57 +02:00
if ($pkginfo->{RunningKernel}) {
print "$pkg: $version (running kernel: $pkginfo->{RunningKernel})\n";
} elsif ($pkginfo->{ManagerVersion}) {
print "$pkg: $version (running version: $pkginfo->{ManagerVersion})\n";
2011-08-23 07:40:22 +02:00
} else {
print "$pkg: $version\n";
}
}
sub print_usage {
my $msg = shift;
print STDERR "ERROR: $msg\n" if $msg;
print STDERR "USAGE: pveversion [--verbose]\n";
}
my $opt_verbose;
if (!GetOptions ('verbose' => \$opt_verbose)) {
print_usage ();
exit (-1);
}
if (scalar (@ARGV) != 0) {
print_usage ();
exit (-1);
}
2013-06-21 11:21:57 +02:00
my $ver = PVE::pvecfg::package() . '/' . PVE::pvecfg::version_text();
my (undef, undef, $kver) = POSIX::uname();
2011-08-23 07:40:22 +02:00
if (!$opt_verbose) {
2013-06-21 11:21:57 +02:00
print "$ver (running kernel: $kver)\n";
2011-08-23 07:40:22 +02:00
exit (0);
}
2013-06-21 11:21:57 +02:00
foreach my $pkg (@$pkgarray) {
print_status($pkg->{Package});
2011-08-23 07:40:22 +02:00
}
exit 0;
__END__
=head1 NAME
pveversion - Proxmox VE version info
=head1 SYNOPSIS
pveversion [--verbose]
=head1 DESCRIPTION
Print version information for Proxmox VE packages.