From: Alexander Koch Date: Sat, 27 Apr 2019 19:26:45 +0000 (+0200) Subject: Pakfire: Add new command line argument "status" X-Git-Tag: v2.23-core133~159 X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=commitdiff_plain;h=090af02e07889d6d62b346a3330f563ec6181ec4 Pakfire: Add new command line argument "status" This enables Pakfire to return a Status-Summary for the Current Core-Update-Level, time since last updates, the availability of a core-/packet-update and if a reboot is required to complete an update. This can be used by monitoring agents (e.g. zabbix_agentd) to monitor the update status of the IPFire device. Signed-off-by: Alexander Koch Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 12a405bd79..9ed911d0ce 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -108,6 +108,7 @@ sub usage { &Pakfire::message(" - Contacts the servers for new lists of paks."); &Pakfire::message(" - Installs the latest version of all paks."); &Pakfire::message(" - Outputs a short list with all available paks."); + &Pakfire::message(" - Outputs a summary about available core upgrades, updates and a required reboot"); &Pakfire::message(""); &Pakfire::message(" Global options:"); &Pakfire::message(" --non-interactive --> Enables the non-interactive mode."); @@ -893,4 +894,55 @@ sub progress_bar { sprintf "$color{'lightgreen'}%-20s %7s |%-${width}s| %10s$color{'normal'}\r",$show_bfile, $progress, $char x (($width-1)*$got/$total). '>', beautifysize($got); } +sub updates_available { + # Get packets with updates available + my @upgradepaks = &Pakfire::dblist("upgrade", "noweb"); + + # Get the length of the returned array + my $updatecount = scalar @upgradepaks; + + return "$updatecount"; +} + +sub coreupdate_available { + eval(`grep "core_" $Conf::dbdir/lists/core-list.db`); + if ("$core_release" > "$Conf::core_mine") { + return "yes ($core_release)"; + } + else { + return "no"; + } +} + +sub reboot_required { + if ( -e "/var/run/need_reboot" ) { + return "yes"; + } + else { + return "no"; + } +} + +sub status { + # General info + my $return = "Core-Update-Level: $Conf::core_mine\n"; + $return .= "Last update: " . &General::age("/opt/pakfire/db/core/mine") . " ago\n"; + $return .= "Last core-list update: " . &General::age("/opt/pakfire/db/lists/core-list.db") . " ago\n"; + $return .= "Last server-list update: " . &General::age("/opt/pakfire/db/lists/server-list.db") . " ago\n"; + $return .= "Last packages-list update: " . &General::age("/opt/pakfire/db/lists/packages_list.db") . " ago\n"; + + # Get availability of core updates + $return .= "Core-Update available: " . &Pakfire::coreupdate_available() . "\n"; + + # Get availability of package updates + $return .= "Package-Updates available: " . &Pakfire::updates_available() . "\n"; + + # Test if reboot is required + $return .= "Reboot required: " . &Pakfire::reboot_required() . "\n"; + + # Return status text + print "$return"; + exit 1; +} + 1; diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 041ba669a3..c69a8d3ad6 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -322,6 +322,8 @@ } elsif ("$ARGV[1]" eq "upgrades") { system("rm -f /etc/fcron.daily/pakfire-upgrade"); } + } elsif ("$ARGV[0]" eq "status") { + &Pakfire::status; } else { &Pakfire::usage; }