]>
Commit | Line | Data |
---|---|---|
776de3bc | 1 | #!/usr/bin/perl |
aff192e6 DM |
2 | |
3 | use strict; | |
776de3bc | 4 | use warnings; |
8794761f | 5 | use POSIX; |
aff192e6 | 6 | use Getopt::Long; |
8794761f | 7 | use PVE::API2::APT; |
aff192e6 | 8 | |
8794761f DM |
9 | my $pkgarray = PVE::API2::APT->versions({ node => 'localhost'}); |
10 | my $pkglist = {}; | |
11 | foreach my $pkg (@$pkgarray) { | |
12 | $pkglist->{$pkg->{Package}} = $pkg; | |
aff192e6 DM |
13 | } |
14 | ||
aff192e6 | 15 | sub print_status { |
8794761f DM |
16 | my ($pkg) = @_; |
17 | ||
18 | my $pkginfo = $pkglist->{$pkg}; | |
aff192e6 | 19 | |
8794761f DM |
20 | if (!$pkginfo) { |
21 | print "$pkg: unknown package - internal error\n"; | |
22 | return; | |
23 | } | |
aff192e6 | 24 | my $version = "not correctly installed"; |
8794761f DM |
25 | if ($pkginfo->{OldVersion} && $pkginfo->{CurrentState} eq 'Installed') { |
26 | $version = $pkginfo->{OldVersion}; | |
966a5de3 TL |
27 | } elsif ($pkginfo->{CurrentState} eq 'ConfigFiles') { |
28 | $version = 'residual config'; | |
aff192e6 DM |
29 | } |
30 | ||
8794761f DM |
31 | if ($pkginfo->{RunningKernel}) { |
32 | print "$pkg: $version (running kernel: $pkginfo->{RunningKernel})\n"; | |
33 | } elsif ($pkginfo->{ManagerVersion}) { | |
34 | print "$pkg: $version (running version: $pkginfo->{ManagerVersion})\n"; | |
aff192e6 DM |
35 | } else { |
36 | print "$pkg: $version\n"; | |
37 | } | |
38 | } | |
39 | ||
40 | sub print_usage { | |
41 | my $msg = shift; | |
42 | ||
43 | print STDERR "ERROR: $msg\n" if $msg; | |
44 | print STDERR "USAGE: pveversion [--verbose]\n"; | |
45 | ||
46 | } | |
47 | ||
48 | my $opt_verbose; | |
49 | ||
50 | if (!GetOptions ('verbose' => \$opt_verbose)) { | |
51 | print_usage (); | |
52 | exit (-1); | |
53 | } | |
54 | ||
55 | if (scalar (@ARGV) != 0) { | |
56 | print_usage (); | |
57 | exit (-1); | |
58 | } | |
59 | ||
8794761f DM |
60 | my $ver = PVE::pvecfg::package() . '/' . PVE::pvecfg::version_text(); |
61 | my (undef, undef, $kver) = POSIX::uname(); | |
aff192e6 | 62 | |
aff192e6 DM |
63 | |
64 | if (!$opt_verbose) { | |
8794761f | 65 | print "$ver (running kernel: $kver)\n"; |
aff192e6 DM |
66 | exit (0); |
67 | } | |
68 | ||
8794761f DM |
69 | foreach my $pkg (@$pkgarray) { |
70 | print_status($pkg->{Package}); | |
aff192e6 DM |
71 | } |
72 | ||
73 | exit 0; | |
74 | ||
75 | __END__ | |
76 | ||
77 | =head1 NAME | |
78 | ||
79 | pveversion - Proxmox VE version info | |
80 | ||
81 | =head1 SYNOPSIS | |
82 | ||
83 | pveversion [--verbose] | |
84 | ||
85 | =head1 DESCRIPTION | |
86 | ||
87 | Print version information for Proxmox VE packages. |