]> git.proxmox.com Git - pmg-api.git/commitdiff
implement pmgversion
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 22 Sep 2017 09:30:18 +0000 (11:30 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 22 Sep 2017 10:06:20 +0000 (12:06 +0200)
Makefile
PMG/API2/APT.pm
PMG/CLI/pmgversion.pm [new file with mode: 0755]
bin/pmgversion [new file with mode: 0755]

index 516a6b5764d7cefd8d4253b764f0de1db24b2403..2653f8bb8b32bc83b09cb1a1d4873df54c6b42ef 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ BASHCOMPLDIR=${DESTDIR}/usr/share/bash-completion/completions/
 REPOID=`./repoid.pl .git`
 
 SERVICES = pmgdaemon pmgproxy pmgtunnel pmgmirror
-CLITOOLS = pmgdb pmgconfig pmgperf pmgcm pmgqm pmgreport
+CLITOOLS = pmgdb pmgconfig pmgperf pmgcm pmgqm pmgreport pmgversion
 CLISCRIPTS = pmg-smtp-filter pmgsh pmgpolicy
 CRONSCRIPTS = pmg-hourly pmg-daily
 
index 10cf6172c09bd06af5dcbb29bf55f105b41b2994..0867143e801026874b0888b47eb39eaf27a7b765 100644 (file)
@@ -498,7 +498,7 @@ __PACKAGE__->register_method({
        my $pkgrecords = $cache->packages();
 
        # try to use a resonable ordering (most important things first)
-       my @list = qw(proxmox-mailgateway proxmox-spamassassin proxmox-mailgateway-gui proxmox-widget-toolkit);
+       my @list = qw(proxmox-mailgateway proxmox-mailgateway-gui proxmox-spamassassin proxmox-widget-toolkit);
 
        foreach my $pkgname (keys %$cache) {
            if ($pkgname =~ m/pve-kernel-/) {
@@ -536,8 +536,9 @@ __PACKAGE__->register_method({
            $res->{CurrentState} = $p->{CurrentState};
 
            # hack: add some useful information (used by 'pmgversion -v')
-           if ($pkgname eq 'proxmox-mailgateway') {
+           if ($pkgname eq 'proxmox-mailgateway-gui') {
                $res->{ManagerVersion} = $pmgver;
+           } elsif ($pkgname eq 'proxmox-mailgateway') {
                $res->{RunningKernel} = $kernel_release;
            }
 
diff --git a/PMG/CLI/pmgversion.pm b/PMG/CLI/pmgversion.pm
new file mode 100755 (executable)
index 0000000..38ce223
--- /dev/null
@@ -0,0 +1,86 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use POSIX;
+use Getopt::Long;
+use PMG::pmgcfg;
+use PMG::API2::APT;
+
+my $pkgarray = PMG::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};
+    }
+
+    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: pmgversion [--verbose]\n";
+
+}
+
+my $opt_verbose;
+
+if (!GetOptions ('verbose' => \$opt_verbose)) {
+    print_usage ();
+    exit (-1);
+} 
+
+if (scalar (@ARGV) != 0) {
+    print_usage ();
+    exit (-1);
+}
+
+my $ver =  PMG::pmgcfg::package() . '/' . PMG::pmgcfg::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
+
+pmgversion - Proxmox Mail Gateway version info
+
+=head1 SYNOPSIS
+
+pmgversion [--verbose]
+
+=head1 DESCRIPTION
+
+Print version information for Proxmox Mail Gateway packages.
diff --git a/bin/pmgversion b/bin/pmgversion
new file mode 100755 (executable)
index 0000000..0c4ced3
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/perl -T
+
+use strict;
+use warnings;
+
+use PMG::CLI::pmgversion;
+
+PMG::CLI::pmgversion->run_cli_handler();