]> git.proxmox.com Git - pve-manager.git/blame - bin/pveversion
update shipped appliance info index
[pve-manager.git] / bin / pveversion
CommitLineData
776de3bc 1#!/usr/bin/perl
aff192e6
DM
2
3use strict;
776de3bc 4use warnings;
8794761f 5use POSIX;
aff192e6 6use Getopt::Long;
8794761f 7use PVE::API2::APT;
aff192e6 8
8794761f
DM
9my $pkgarray = PVE::API2::APT->versions({ node => 'localhost'});
10my $pkglist = {};
11foreach my $pkg (@$pkgarray) {
12 $pkglist->{$pkg->{Package}} = $pkg;
aff192e6
DM
13}
14
aff192e6 15sub 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
40sub 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
48my $opt_verbose;
49
50if (!GetOptions ('verbose' => \$opt_verbose)) {
51 print_usage ();
52 exit (-1);
bbef6b29 53}
aff192e6
DM
54
55if (scalar (@ARGV) != 0) {
56 print_usage ();
57 exit (-1);
58}
59
8794761f
DM
60my $ver = PVE::pvecfg::package() . '/' . PVE::pvecfg::version_text();
61my (undef, undef, $kver) = POSIX::uname();
aff192e6 62
aff192e6
DM
63
64if (!$opt_verbose) {
8794761f 65 print "$ver (running kernel: $kver)\n";
aff192e6
DM
66 exit (0);
67}
68
8794761f
DM
69foreach my $pkg (@$pkgarray) {
70 print_status($pkg->{Package});
aff192e6
DM
71}
72
73exit 0;
74
75__END__
76
77=head1 NAME
78
bbef6b29 79pveversion - Proxmox VE version info
aff192e6
DM
80
81=head1 SYNOPSIS
82
83pveversion [--verbose]
84
85=head1 DESCRIPTION
86
87Print version information for Proxmox VE packages.