]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
Pakfire: Add new command line argument "status"
authorAlexander Koch <ipfire@starkstromkonsument.de>
Sat, 27 Apr 2019 19:26:45 +0000 (21:26 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 7 May 2019 22:51:20 +0000 (23:51 +0100)
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 <ipfire@starkstromkonsument.de>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/lib/functions.pl
src/pakfire/pakfire

index 12a405bd79a471288d6941c2527ac3c497e1f1d7..9ed911d0ce46d36949c220c8d2eefadf2e39a962 100644 (file)
@@ -108,6 +108,7 @@ sub usage {
   &Pakfire::message("               <update> - Contacts the servers for new lists of paks.");
   &Pakfire::message("               <upgrade> - Installs the latest version of all paks.");
   &Pakfire::message("               <list> - Outputs a short list with all available paks.");
+  &Pakfire::message("               <status> - 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;
index 041ba669a3b016ae236cc2d6647429f5efc407a5..c69a8d3ad6dcf056f83518c4910463938c01f5cd 100644 (file)
                } elsif ("$ARGV[1]" eq "upgrades") {
                        system("rm -f /etc/fcron.daily/pakfire-upgrade");
                }
+       } elsif ("$ARGV[0]" eq "status") {
+               &Pakfire::status;
        } else {
                &Pakfire::usage;
        }