]> git.proxmox.com Git - pve-manager.git/blame - bin/pveversion
test: replication: mock cfs_(write|lock)_file
[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};
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
38sub 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
46my $opt_verbose;
47
48if (!GetOptions ('verbose' => \$opt_verbose)) {
49 print_usage ();
50 exit (-1);
51}
52
53if (scalar (@ARGV) != 0) {
54 print_usage ();
55 exit (-1);
56}
57
8794761f
DM
58my $ver = PVE::pvecfg::package() . '/' . PVE::pvecfg::version_text();
59my (undef, undef, $kver) = POSIX::uname();
aff192e6 60
aff192e6
DM
61
62if (!$opt_verbose) {
8794761f 63 print "$ver (running kernel: $kver)\n";
aff192e6
DM
64 exit (0);
65}
66
8794761f
DM
67foreach my $pkg (@$pkgarray) {
68 print_status($pkg->{Package});
aff192e6
DM
69}
70
71exit 0;
72
73__END__
74
75=head1 NAME
76
77pveversion - Proxmox VE version info
78
79=head1 SYNOPSIS
80
81pveversion [--verbose]
82
83=head1 DESCRIPTION
84
85Print version information for Proxmox VE packages.