From mboxrd@z Thu Jan 1 00:00:00 1970 From: Robin Roevens To: development@lists.ipfire.org Subject: [PATCH v2 07/10] pakfire: Refactor status seperating UI and logic Date: Thu, 28 Jul 2022 13:21:33 +0200 Message-ID: <20220728112136.30218-8-robin.roevens@disroot.org> In-Reply-To: <20220728112136.30218-1-robin.roevens@disroot.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5123295248578516855==" List-Id: --===============5123295248578516855== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable - Removed UI code from status function now returning hash with status properties. - Removed function coreupdate_available as it is now not used anymore - Added UI code to pakfire status routine - Added meaningfull exitcode to status: - 2: Core update available - 3: Pak update available - 4: Reboot required - Error codes can be added together: 2+3 =3D 5 means both core update and pak update is available Signed-off-by: Robin Roevens --- src/pakfire/lib/functions.pl | 50 +++++++++++++++--------------------- src/pakfire/pakfire | 19 +++++++++++++- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index d8b5c5a26..f87589bc4 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -914,16 +914,6 @@ sub updates_available { return "$updatecount"; } =20 -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"; @@ -934,26 +924,26 @@ sub reboot_required { } =20 sub status { - # General info - my $return =3D "Core-Version: $Conf::version\n"; - $return .=3D "Core-Update-Level: $Conf::core_mine\n"; - $return .=3D "Last update: " . &General::age("/opt/pakfire/db/core/mine") .= " ago\n"; - $return .=3D "Last core-list update: " . &General::age("/opt/pakfire/db/lis= ts/core-list.db") . " ago\n"; - $return .=3D "Last server-list update: " . &General::age("/opt/pakfire/db/l= ists/server-list.db") . " ago\n"; - $return .=3D "Last packages-list update: " . &General::age("/opt/pakfire/db= /lists/packages_list.db") . " ago\n"; - - # Get availability of core updates - $return .=3D "Core-Update available: " . &Pakfire::coreupdate_available() .= "\n"; - - # Get availability of package updates - $return .=3D "Package-Updates available: " . &Pakfire::updates_available() = . "\n"; - - # Test if reboot is required - $return .=3D "Reboot required: " . &Pakfire::reboot_required() . "\n"; - - # Return status text - print "$return"; - exit 1; + ### This subroutine returns pakfire status information in a hash. + # Usage is without arguments + + # Add core version info + my %status =3D &Pakfire::coredbinfo(); + + # Add last update info + $status{'LastUpdate'} =3D &General::age("/opt/pakfire/db/core/mine"); + $status{'LastCoreListUpdate'} =3D &General::age("/opt/pakfire/db/lists/core= -list.db"); + $status{'LastServerListUpdate'} =3D &General::age("/opt/pakfire/db/lists/se= rver-list.db"); + $status{'LastPakListUpdate'} =3D &General::age("/opt/pakfire/db/lists/packa= ges_list.db"); + + # Add number of available package updates + $status{'CoreUpdateAvailable'} =3D (defined $status{'AvailableRelease'}) ? = "yes" : "no"; + $status{'PakUpdatesAvailable'} =3D &Pakfire::updates_available(); + + # Add if reboot is required + $status{'RebootRequired'} =3D &Pakfire::reboot_required(); + + return %status; } =20 sub get_arch() { diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 766d91b81..331204a00 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -412,7 +412,24 @@ system("rm -f /etc/fcron.daily/pakfire-upgrade"); } } elsif ("$ARGV[0]" eq "status") { - &Pakfire::status; + my $exitcode =3D 0; + my %status =3D &Pakfire::status; + + print "Core-Version: $status{'CoreVersion'}\n"; + print "Core-Update-Level: $status{'Release'}\n"; + print "Last update: $status{'LastUpdate'} ago\n"; + print "Last core-list update: $status{'LastCoreListUpdate'} ago\n"; + print "Last server-list update: $status{'LastServerListUpdate'} ago\n"; + print "Last packages-list update: $status{'LastPakListUpdate'} ago\n"; + print "Core-Update available: $status{'CoreUpdateAvailable'}"; + print " ($status{'AvailableRelease'})" if ("$status{'CoreUpdateAvailable'}= " eq "yes"); + print "\nPackage-Updates available: $status{'PakUpdatesAvailable'}\n"; + print "Reboot required: $status{'RebootRequired'}\n"; + + $exitcode +=3D 2 if ($status{'CoreUpdateAvailable'} eq "yes"); + $exitcode +=3D 3 if ($status{'PakUpdatesAvailable'} eq "yes"); + $exitcode +=3D 4 if ($status{'RebootRequired'} eq "yes"); + exit $exitcode; } else { &Pakfire::usage; } --=20 2.36.1 --=20 Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn. --===============5123295248578516855==--