public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Robin Roevens <robin.roevens@disroot.org>
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	[thread overview]
Message-ID: <20220728112136.30218-8-robin.roevens@disroot.org> (raw)
In-Reply-To: <20220728112136.30218-1-robin.roevens@disroot.org>

[-- Attachment #1: Type: text/plain, Size: 4544 bytes --]

- 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 = 5 means both core update
    and pak update is available

Signed-off-by: Robin Roevens <robin.roevens(a)disroot.org>
---
 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";
 }
 
-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 {
 }
 
 sub status {
-	# General info
-	my $return = "Core-Version: $Conf::version\n";
-	$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;
+	### This subroutine returns pakfire status information in a hash.
+	# Usage is without arguments
+
+	# Add core version info
+	my %status = &Pakfire::coredbinfo();
+
+	# Add last update info
+	$status{'LastUpdate'} = &General::age("/opt/pakfire/db/core/mine");
+	$status{'LastCoreListUpdate'} = &General::age("/opt/pakfire/db/lists/core-list.db");
+	$status{'LastServerListUpdate'} = &General::age("/opt/pakfire/db/lists/server-list.db");
+	$status{'LastPakListUpdate'} = &General::age("/opt/pakfire/db/lists/packages_list.db");
+
+	# Add number of available package updates
+	$status{'CoreUpdateAvailable'} = (defined $status{'AvailableRelease'}) ? "yes" : "no";
+	$status{'PakUpdatesAvailable'} = &Pakfire::updates_available();
+
+	# Add if reboot is required
+	$status{'RebootRequired'} = &Pakfire::reboot_required();
+
+	return %status;
 }
 
 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 = 0;
+		my %status = &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 += 2 if ($status{'CoreUpdateAvailable'} eq "yes");
+		$exitcode += 3 if ($status{'PakUpdatesAvailable'} eq "yes");
+		$exitcode += 4 if ($status{'RebootRequired'} eq "yes");
+		exit $exitcode;
 	} else {
 		&Pakfire::usage;
 	}
-- 
2.36.1


-- 
Dit bericht is gescanned op virussen en andere gevaarlijke
inhoud door MailScanner en lijkt schoon te zijn.


  parent reply	other threads:[~2022-07-28 11:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-28 11:21 [PATCH v2 00/10] pakfire: remove dup. code + seperate ui/logic Robin Roevens
2022-07-28 11:21 ` [PATCH v2 01/10] pakfire: Refactor dblist seperating UI and logic Robin Roevens
2022-07-28 11:21 ` [PATCH v2 02/10] pakfire: Translate WUI header/footer text Robin Roevens
2022-07-28 11:21 ` [PATCH v2 03/10] pakfire: Replace duplicate code with dblist functioncall Robin Roevens
2022-07-28 11:21 ` [PATCH v2 04/10] pakfire: Replace dbgetlist duplicate code Robin Roevens
2022-07-28 11:21 ` [PATCH v2 05/10] pakfire: Optimize upgradecore function Robin Roevens
2022-07-28 11:21 ` [PATCH v2 06/10] pakfire: Add list upgrade functionality Robin Roevens
2022-07-28 11:21 ` Robin Roevens [this message]
2022-07-28 11:21 ` [PATCH v2 08/10] pakfire: Replace status duplicate code Robin Roevens
2022-07-28 11:21 ` [PATCH v2 09/10] pakfire: Add getmetadata function Robin Roevens
2022-07-28 11:21 ` [PATCH v2 10/10] pakfire: Replace getmetadata duplicate code Robin Roevens
2022-07-28 13:51 ` [PATCH v2 00/10] pakfire: remove dup. code + seperate ui/logic Peter Müller
2022-07-29 20:11   ` Robin Roevens
2022-07-28 19:43 ` Michael Tremer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220728112136.30218-8-robin.roevens@disroot.org \
    --to=robin.roevens@disroot.org \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox