From patchwork Thu Jul 28 11:21:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Roevens X-Patchwork-Id: 5771 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4LtpCb5FVkz3wvM for ; Thu, 28 Jul 2022 11:22:35 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4LtpCT3N3cz5Rb; Thu, 28 Jul 2022 11:22:29 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4LtpCS5Dvhz303b; Thu, 28 Jul 2022 11:22:28 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4LtpCR697Gz2yXK for ; Thu, 28 Jul 2022 11:22:27 +0000 (UTC) Received: from knopi.disroot.org (knopi.disroot.org [178.21.23.139]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4LtpCR51H9z1Dp for ; Thu, 28 Jul 2022 11:22:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 5120840DC8 for ; Thu, 28 Jul 2022 13:22:27 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YlHmFdpoGvF5 for ; Thu, 28 Jul 2022 13:22:26 +0200 (CEST) Received: from chojin.sicho.home (amaterasu.sicho.home [192.168.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (no client certificate requested) (Authenticated sender) by hachiman (MailScanner Milter) with SMTP id 428BF560B3; Thu, 28 Jul 2022 13:21:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1659007340; bh=hzmFkHlLHJr0buI/7+DZAN68pqJOMks2+QM/+aPNLYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T+nmrxFYkIsnmM4aQK/NbQuSb2HloThflRMfB7J14372oQ4yVzAXQb7C/Y3a3qeW1 zSsa6ijZphdArVLvdtFkD4kgNM02YLATZk3JAGVAS55o07c1IlxwOERQkmbqCnLM/q kpS2o/hicMQEW03FjRWxDHnbbEgVpAoK0EbqFZCga42ZDG//8t/uMcmI0Rz+7K6uoC MA4azRY4yf8zVvzbTW4u/gbL8+9Jm09ReUOztRhCkbsdBuaRpspiolF/TMiA0TcS35 yLbznypEhEV0xfZjH7v0D509DEoh5g2Gm4jIfmQ5824Nryw308ITQFpZ1/fUzHYK5s BLUDiWtPMGFgg== 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> References: <20220728112136.30218-1-robin.roevens@disroot.org> Mime-Version: 1.0 X-sicho-MailScanner-ID: 428BF560B3.A8A80 X-sicho-MailScanner: Found to be clean X-sicho-MailScanner-From: robin.roevens@disroot.org X-sicho-MailScanner-Watermark: 1659612114.77205@KAzKUTsDhoGVdS0TR5z1Bw ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1659007347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=AzFiopZQSyltinsgTuuxyENPFigNmf3BLJ7d8hDLTwA=; b=apOIVIx4XR7B7t4Qh9CZfXxrppVjuIe/5ixbq/DH0+pCtC2WQ+GD2cxknDb3gTivZHOc8U aIaCcssahhTw8B5RtH3WRWRcdoLcAf8yCI/4Umk6NYxprW5nMvLXdA7ZHzlep59RrX6K4o 136FT3ZVV50Kts++7gJqWtTDXXWATOacTx41Gu+6HpNyTwDqV+liaNx/VLaOmorEgAE+5c dlNxW7Xvfh7T7IavXMneUMpycDHbO1+F3ACDZ59gUo3FUsTWOHteUk/2c6D2Su09sQsgCT NysdOGT9D8S2lminssj75pQkXXwUVvgg7MGghheJSR2SQNVBWY2j7gHVY4HcEg== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=T+nmrxFY; dmarc=pass (policy=quarantine) header.from=disroot.org; spf=pass (mail01.ipfire.org: domain of robin.roevens@disroot.org designates 178.21.23.139 as permitted sender) smtp.mailfrom=robin.roevens@disroot.org ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1659007347; a=rsa-sha256; cv=none; b=b6sRRJPdS7mWIR+t4pN7bq88nlZ/RswuJZSxoQzEIf2ZAQb0P2zTJTJ6S/43beQN2TpkXp 7v4VPZ1bec5eHNe0uNiPlT8xWOL0YJExli7N2ABZ6qYi/5H9mkeZeZjbm1p58BT3jrcX15 H3YA8o5LEPsdlLi14WC0MiApyOckjLC0YP5AKwf8nUu8eHalT0mgG+lUNAbcaWuSoSu4aE QxP1dvLFek0/j9iR0y6HdumvI6dy9KDatAtveYa/M3w6cXXC2AP9g9tYj1tBGZLEaToywr kTnFL0k+6eyHokr2RlT0TcN6y3o2HCYv2Gh2ebc19W9UTnPkocNU9h5TTGxPhw== X-Rspamd-Queue-Id: 4LtpCR51H9z1Dp Authentication-Results: mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=T+nmrxFY; dmarc=pass (policy=quarantine) header.from=disroot.org; spf=pass (mail01.ipfire.org: domain of robin.roevens@disroot.org designates 178.21.23.139 as permitted sender) smtp.mailfrom=robin.roevens@disroot.org X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [-3.84 / 11.00]; BAYES_HAM(-3.00)[99.99%]; NEURAL_HAM(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; SPF_REPUTATION_HAM(-0.82)[-0.81818744443554]; DMARC_POLICY_ALLOW(-0.50)[disroot.org,quarantine]; R_MISSING_CHARSET(0.50)[]; MV_CASE(0.50)[]; R_SPF_ALLOW(-0.20)[+a:c]; R_DKIM_ALLOW(-0.20)[disroot.org:s=mail]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; IP_REPUTATION_HAM(-0.01)[asn: 50673(0.00), country: NL(-0.01), ip: 178.21.23.139(0.00)]; ASN(0.00)[asn:50673, ipnet:178.21.23.0/24, country:NL]; FROM_EQ_ENVFROM(0.00)[]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[development@lists.ipfire.org]; DKIM_TRACE(0.00)[disroot.org:+]; TO_DN_SOME(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_COUNT_THREE(0.00)[4]; ARC_NA(0.00)[] X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" - 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 --- 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; }