From c01f2dba5d05212645c8f03459b950004690898f Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sat, 19 Sep 2020 17:53:04 -0700 Subject: [PATCH] Fall back to apt command if apt-show-versions is missing https://github.com/webmin/webmin/pull/1302 --- software/apt-lib.pl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/software/apt-lib.pl b/software/apt-lib.pl index 9d185d009..8282c03a6 100755 --- a/software/apt-lib.pl +++ b/software/apt-lib.pl @@ -282,6 +282,32 @@ if (&has_command("apt-show-versions")) { } return @rv; } +elsif (&has_command("apt")) { + # Use the apt list command + local @rv; + &clean_language(); + &open_execute_command(PKGS, "apt list --upgradable 2>/dev/null", 1, 1); + while() { + if (/^(\S+)\/(\S+)\s+(\S+)\s+(\S+)\s+\[upgradable\s+from:\s+(\S+)\]/ && !$holds{$1}) { + local $pkg = { 'name' => $1, + 'source' => $2, + 'version' => $3, + 'arch' => $4 }; + if ($pkg->{'version'} =~ s/^(\S+)://) { + $pkg->{'epoch'} = $1; + } + $pkg->{'source'} =~ s/,.*$//; + push(@rv, $pkg); + } + } + close(PKGS); + &reset_environment(); + @rv = &filter_held_packages(@rv); + foreach my $pkg (@rv) { + $pkg->{'security'} = 1 if ($pkg->{'source'} =~ /security/i); + } + return @rv; + } else { # Need to manually compose by calling dpkg and apt-cache showpkg local %packages;