]>
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}; | |
aff192e6 DM |
27 | } |
28 | ||
8794761f DM |
29 | if ($pkginfo->{RunningKernel}) { |
30 | print "$pkg: $version (running kernel: $pkginfo->{RunningKernel})\n"; | |
31 | } elsif ($pkginfo->{ManagerVersion}) { | |
32 | print "$pkg: $version (running version: $pkginfo->{ManagerVersion})\n"; | |
aff192e6 DM |
33 | } else { |
34 | print "$pkg: $version\n"; | |
35 | } | |
36 | } | |
37 | ||
38 | sub print_usage { | |
39 | my $msg = shift; | |
40 | ||
41 | print STDERR "ERROR: $msg\n" if $msg; | |
42 | print STDERR "USAGE: pveversion [--verbose]\n"; | |
43 | ||
44 | } | |
45 | ||
46 | my $opt_verbose; | |
47 | ||
48 | if (!GetOptions ('verbose' => \$opt_verbose)) { | |
49 | print_usage (); | |
50 | exit (-1); | |
51 | } | |
52 | ||
53 | if (scalar (@ARGV) != 0) { | |
54 | print_usage (); | |
55 | exit (-1); | |
56 | } | |
57 | ||
8794761f DM |
58 | my $ver = PVE::pvecfg::package() . '/' . PVE::pvecfg::version_text(); |
59 | my (undef, undef, $kver) = POSIX::uname(); | |
aff192e6 | 60 | |
aff192e6 DM |
61 | |
62 | if (!$opt_verbose) { | |
8794761f | 63 | print "$ver (running kernel: $kver)\n"; |
aff192e6 DM |
64 | exit (0); |
65 | } | |
66 | ||
8794761f DM |
67 | foreach my $pkg (@$pkgarray) { |
68 | print_status($pkg->{Package}); | |
aff192e6 DM |
69 | } |
70 | ||
71 | exit 0; | |
72 | ||
73 | __END__ | |
74 | ||
75 | =head1 NAME | |
76 | ||
77 | pveversion - Proxmox VE version info | |
78 | ||
79 | =head1 SYNOPSIS | |
80 | ||
81 | pveversion [--verbose] | |
82 | ||
83 | =head1 DESCRIPTION | |
84 | ||
85 | Print version information for Proxmox VE packages. |