pve-manager/bin/pveversion
Thomas Lamprecht f18dacb78f pveversion: fix removed packages with residual configs
Those ain't 'not correctly installed', so do not suggest the user
that.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2019-12-03 14:12:50 +01:00

88 lines
1.7 KiB
Perl
Executable File

#!/usr/bin/perl
use strict;
use warnings;
use POSIX;
use Getopt::Long;
use PVE::API2::APT;
my $pkgarray = PVE::API2::APT->versions({ node => 'localhost'});
my $pkglist = {};
foreach my $pkg (@$pkgarray) {
$pkglist->{$pkg->{Package}} = $pkg;
}
sub print_status {
my ($pkg) = @_;
my $pkginfo = $pkglist->{$pkg};
if (!$pkginfo) {
print "$pkg: unknown package - internal error\n";
return;
}
my $version = "not correctly installed";
if ($pkginfo->{OldVersion} && $pkginfo->{CurrentState} eq 'Installed') {
$version = $pkginfo->{OldVersion};
} elsif ($pkginfo->{CurrentState} eq 'ConfigFiles') {
$version = 'residual config';
}
if ($pkginfo->{RunningKernel}) {
print "$pkg: $version (running kernel: $pkginfo->{RunningKernel})\n";
} elsif ($pkginfo->{ManagerVersion}) {
print "$pkg: $version (running version: $pkginfo->{ManagerVersion})\n";
} 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);
}
my $ver = PVE::pvecfg::package() . '/' . PVE::pvecfg::version_text();
my (undef, undef, $kver) = POSIX::uname();
if (!$opt_verbose) {
print "$ver (running kernel: $kver)\n";
exit (0);
}
foreach my $pkg (@$pkgarray) {
print_status($pkg->{Package});
}
exit 0;
__END__
=head1 NAME
pveversion - Proxmox VE version info
=head1 SYNOPSIS
pveversion [--verbose]
=head1 DESCRIPTION
Print version information for Proxmox VE packages.