From patchwork Wed Mar 9 22:56:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Roevens X-Patchwork-Id: 5332 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 4KDSJq2kRzz3xq8 for ; Wed, 9 Mar 2022 22:57:47 +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 4KDSJm0tgYz5Vn; Wed, 9 Mar 2022 22:57:44 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KDSJl4H6lz2xWt; Wed, 9 Mar 2022 22:57:43 +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 4KDSJj3yH5z2ymJ for ; Wed, 9 Mar 2022 22:57:41 +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 4KDSJj1v6pz5VQ for ; Wed, 9 Mar 2022 22:57:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 006B7400A4 for ; Wed, 9 Mar 2022 23:57:39 +0100 (CET) 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 5UdMuHoP0bID for ; Wed, 9 Mar 2022 23:57:37 +0100 (CET) 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 417A01B977; Wed, 9 Mar 2022 23:57:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1646866657; bh=D7hEvoMFKK93tBAhYld8JpzVr4OELUYQtDyXRL0ikjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=a44N/PP7diuVj/3iHXN3vUuZ5mCmG43ujcNN56wLhAwmYMh3LcMWgO+xMSw5gKvTb teom83VeJYAdueU7CBF1o2EroZwmBjscYvmfanhcHCkOOKjh+A9gIuszJVWB8Xxfkw EFA3ykuSjhlo0e9YL0AA8IHi7BqKZ02xJnOE0Ii3ChL1yZSWa0JjKcSTE4y3lA8cz4 Nry0p9WMGhn6vINgVNBAkvCvonk2pSddxzI6VImIIzED9kefD9Xw5P0jFrJu8c46ci VP/t53uy/TiKEf+DXcLSPAGS3g4MM6b3JSD92/q5kDTD8hw+n+eEcCFTeb+UKpOTPx mh8dARN1M9h3A== From: Robin Roevens To: development@lists.ipfire.org Subject: [PATCH 1/9] pakfire: Refactor dblist seperating UI and logic Date: Wed, 9 Mar 2022 23:56:47 +0100 Message-Id: <20220309225655.4472-2-robin.roevens@disroot.org> In-Reply-To: <20220309225655.4472-1-robin.roevens@disroot.org> References: <20220309225655.4472-1-robin.roevens@disroot.org> Mime-Version: 1.0 X-sicho-MailScanner-ID: 417A01B977.A8A80 X-sicho-MailScanner: Found to be clean X-sicho-MailScanner-From: robin.roevens@disroot.org X-sicho-MailScanner-Watermark: 1647471432.22838@0INSqWdpky7zvdDpDXDL8g ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1646866661; a=rsa-sha256; cv=none; b=k2uoIPWxreVd0tZtBNbKdZRDovjQt+ySAsPvMQdS2bWtwfp0NhunzB8ov8vxjmPJoKxWJ3 9pdmiQVKNeDQMUwK1b46WgXzoCzDGEP/J7MR6HQaCZxWzl1JHMjBNAEPCYKHyT43lWbXn5 vFcMBxBNT0fKX4RcBHuMo4CNoax9rUdinr42mKzryUzWJCX9jB6GnagrI9E1YnWf7PINa9 +uUVb2qWoTmEcun35oj/NHiM7au/qhNILojw3mt9+Hhec+h91RdsUy/x5kNhD+y89dTEQx umTOP41m3WVQKgpMC3TlVU4lBc3ldFv+iG+ZA8H28k84LCw2GkF43yHlTUzmCw== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b="a44N/PP7"; 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1646866661; 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=uR5hzcGI8hiGefFONOi6ZecGtQB9n5StGfTJtjwSivw=; b=q97nqv3YtukTwM7vdsW2e+2b7nMJfSU+T2/NkafvIGZjqfR+O7qu8s2nT3QEcyNGFg9L1B tox+ubWP4uovPfj1Ga8POgx1OY9K7ACy4G3O+jXTnmIDbwpaQlSRODIzSYgmHvGotOTqIh AK68PoK9nfFuoowIePbzOLb8Khj54UrRLMwEF7DMKcNDhBJ+BoocY28iWQFhRN+Py3zgJ9 skUuxzsedEfV9rgajjYRTJoYBoXqPePlfBsAYQD5WmCQ4R/nVjMSEIYk9Bd7JnHBg9DiTy TU78TLU3bDfbZ+kBJAJvvSq1qWylm/PmbpEIa43OIrl2Kxcw9OIdESPTcUzVvg== Authentication-Results: mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b="a44N/PP7"; 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 [-4.83 / 11.00]; BAYES_HAM(-3.00)[99.99%]; IP_REPUTATION_HAM(-1.15)[asn: 50673(-0.33), country: NL(-0.01), ip: 178.21.23.139(-0.82)]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM(-0.99)[-0.991]; SPF_REPUTATION_HAM(-0.68)[-0.67731760723277]; MV_CASE(0.50)[]; R_MISSING_CHARSET(0.50)[]; DMARC_POLICY_ALLOW(-0.50)[disroot.org,quarantine]; 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)[]; FROM_EQ_ENVFROM(0.00)[]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[disroot.org:+]; ASN(0.00)[asn:50673, ipnet:178.21.23.0/24, country:NL]; TO_DN_SOME(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; PREVIOUSLY_DELIVERED(0.00)[development@lists.ipfire.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; ARC_NA(0.00)[] X-Rspamd-Queue-Id: 4KDSJj1v6pz5VQ 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 dblist function and refactor it making it return a hash representing the pak db for easier handling of this data. - Moved core update check in dblist to new seperate dbcoreinfo function making it return a hash with current and possibly available core version info. - Update existing calls to dblist - Bring UI parts previously in dblist to pakfire program itself, pakfire.cgi and index.cgi with a few small enhancements: - Add currently installed version numbers to installed paks list in pakfire.cgi - Add 'Installed: yes/no' to pakfire list output so people not using colors have this information too. - Add update available details to pakfire list output if package has updates available. Signed-off-by: Robin Roevens --- html/cgi-bin/index.cgi | 6 +- html/cgi-bin/pakfire.cgi | 24 +++++- src/pakfire/lib/functions.pl | 147 ++++++++++++++++------------------- src/pakfire/pakfire | 99 +++++++++++++++++------ 4 files changed, 168 insertions(+), 108 deletions(-) diff --git a/html/cgi-bin/index.cgi b/html/cgi-bin/index.cgi index 18c26942e..6fecae1ff 100644 --- a/html/cgi-bin/index.cgi +++ b/html/cgi-bin/index.cgi @@ -604,7 +604,11 @@ if ($warnmessage) { &Header::closebox(); } -&Pakfire::dblist("upgrade", "notice"); +my %coredb = &Pakfire::coredbinfo(); +if (defined $coredb{'AvailableRelease'}) { + print "


$Lang::tr{'core notice 1'} $coredb{'Release'} $Lang::tr{'core notice 2'} $coredb{'AvailableRelease'} $Lang::tr{'core notice 3'}"; +} + if ( -e "/var/run/need_reboot" ) { print "
"; print "

$Lang::tr{'needreboot'}!"; diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index 65c67fb90..30a23128b 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -370,7 +370,17 @@ print < END - &Pakfire::dblist("upgrade", "forweb"); + my %coredb = &Pakfire::coredbinfo(); + if (defined $coredb{'AvailableRelease'}) { + print "\n"; + } + + my %upgradelist = &Pakfire::dblist("upgrade"); + foreach my $pak (sort keys %upgradelist) { + print "\n"; + } + + print < @@ -386,7 +396,11 @@ END @@ -398,7 +412,11 @@ END diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index d4e338f23..f08f43622 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -2,7 +2,7 @@ ############################################################################### # # # IPFire.org - A linux based firewall # -# Copyright (C) 2007-2021 IPFire Team # +# Copyright (C) 2007-2022 IPFire Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # @@ -44,7 +44,7 @@ my @VALID_KEY_FINGERPRINTS = ( ); # A small color-hash :D -my %color; +our %color; $color{'normal'} = "\033[0m"; $color{'black'} = "\033[0;30m"; $color{'darkgrey'} = "\033[1;30m"; @@ -426,108 +426,93 @@ sub dbgetlist { } } +sub coredbinfo { + ### This subroutine returns core db version information in a hash. + # Usage is without arguments + + eval(`grep "core_" $Conf::dbdir/lists/core-list.db`); + + my %coredb = ( + CoreVersion => $Conf::version, + Release => $Conf::core_mine, + ); + + $coredb{'AvailableRelease'} = $core_release if ("$Conf::core_mine" < "$core_release"); + + return %coredb; +} + sub dblist { - ### This subroutine lists the packages. - # You may also pass a filter: &Pakfire::dblist(filter) - # Usage is always with two arguments. - # filter may be: all, notinstalled, installed + ### This subroutine returns the packages from the packages_list db in a hash. + # It uses the currently cached version of packages_list. To ensure latest + # data, run Pakfire::dbgetlist first. + # You may also pass a filter: &Pakfire::dblist(filter) + # Usage is always with one argument. + # filter may be: all, notinstalled, installed, upgrade my $filter = shift; - my $forweb = shift; - my @updatepaks; + my %paklist = (); my $file; my $line; - my $prog; my %metadata; my @templine; - - ### Make sure that the list is not outdated. - #dbgetlist("noforce"); - + open(FILE, "<$Conf::dbdir/lists/packages_list.db"); my @db = ; close(FILE); - if ("$filter" eq "upgrade") { - if ("$forweb" ne "forweb" && "$forweb" ne "notice" ) {getcoredb("noforce");} - eval(`grep "core_" $Conf::dbdir/lists/core-list.db`); - if ("$core_release" > "$Conf::core_mine") { - if ("$forweb" eq "forweb") { - print "\n"; - } - elsif ("$forweb" eq "notice") { - print "


$Lang::tr{'core notice 1'} $Conf::core_mine $Lang::tr{'core notice 2'} $core_release $Lang::tr{'core notice 3'}"; - } else { - my $command = "Core-Update $Conf::version\nRelease: $Conf::core_mine -> $core_release\n"; - if ("$Pakfire::enable_colors" eq "1") { - print "$color{'lila'}$command$color{'normal'}\n"; - } else { - print "$command\n"; - } - } - } - + if ("$filter" ne "notinstalled") { opendir(DIR,"$Conf::dbdir/installed"); my @files = readdir(DIR); closedir(DIR); + foreach $file (@files) { next if ( $file eq "." ); next if ( $file eq ".." ); next if ( $file =~ /^old/ ); %metadata = parsemetafile("$Conf::dbdir/installed/$file"); - foreach $prog (@db) { - @templine = split(/\;/,$prog); - if (("$metadata{'Name'}" eq "$templine[0]") && ("$metadata{'Release'}" < "$templine[2]" && "$forweb" ne "notice")) { - push(@updatepaks,$metadata{'Name'}); - if ("$forweb" eq "forweb") { - print "\n"; - } else { - my $command = "Update: $metadata{'Name'}\nVersion: $metadata{'ProgVersion'} -> $templine[1]\nRelease: $metadata{'Release'} -> $templine[2]\n"; - if ("$Pakfire::enable_colors" eq "1") { - print "$color{'lila'}$command$color{'normal'}\n"; - } else { - print "$command\n"; - } - } + foreach $line (@db) { + next unless ($line =~ /.*;.*;.*;/ ); + @templine = split(/\;/,$line); + if (("$metadata{'Name'}" eq "$templine[0]") && ("$metadata{'Release'}" < "$templine[2]")) { #&& "$forweb" ne "notice")) { + # Add all upgradable paks to list + $paklist{"$metadata{'Name'}"} = { + ProgVersion => $metadata{'ProgVersion'}, + Release => $metadata{'Release'}, + AvailableProgVersion => $templine[1], + AvailableRelease => $templine[2], + Installed => "yes" + }; + last; + } elsif (("$metadata{'Name'}" eq "$templine[0]") && ("$filter" ne "upgrade")) { + # Add installed paks without an upgrade available to list + $paklist{"$metadata{'Name'}"} = { + ProgVersion => $metadata{'ProgVersion'}, + Release => $metadata{'Release'}, + Installed => "yes" + }; + last; } } } - return @updatepaks; - } else { - my $line; - my $use_color; - my @templine; - my $count; - foreach $line (sort @db) { + } + + # Add all not installed paks to list + if (("$filter" ne "upgrade") && ("$filter" ne "installed")) { + foreach $line (@db) { next unless ($line =~ /.*;.*;.*;/ ); - $use_color = ""; @templine = split(/\;/,$line); - if ("$filter" eq "notinstalled") { - next if ( -e "$Conf::dbdir/installed/meta-$templine[0]" ); - } elsif ("$filter" eq "installed") { - next unless ( -e "$Conf::dbdir/installed/meta-$templine[0]" ); - } - $count++; - if ("$forweb" eq "forweb") - { - if ("$filter" eq "notinstalled") { - print "\n"; - } else { - print "\n"; - } - } else { - if ("$Pakfire::enable_colors" eq "1") { - if (&isinstalled("$templine[0]")) { - $use_color = "$color{'red'}" - } else { - $use_color = "$color{'green'}" - } - } - print "${use_color}Name: $templine[0]\nProgVersion: $templine[1]\nRelease: $templine[2]$color{'normal'}\n\n"; - } + next if ((defined $paklist{"$templine[0]"}) || (&isinstalled($templine[0]) == 0)); + + $paklist{"$templine[0]"} = { + ProgVersion => "$templine[1]", + Release => "$templine[2]", + Installed => "no" + }; } - print "$count packages total.\n" unless ("$forweb" eq "forweb"); } + + return %paklist; } sub resolvedeps_one { @@ -896,10 +881,10 @@ sub progress_bar { sub updates_available { # Get packets with updates available - my @upgradepaks = &Pakfire::dblist("upgrade", "noweb"); + my %upgradepaks = &Pakfire::dblist("upgrade"); - # Get the length of the returned array - my $updatecount = scalar @upgradepaks; + # Get the length of the returned hash + my $updatecount = keys %upgradepaks; return "$updatecount"; } diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 6c77695c8..b4930e85d 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -270,14 +270,25 @@ &Pakfire::getcoredb("$force"); } elsif ("$ARGV[0]" eq "upgrade") { + my $use_color = ""; + my $reset_color = ""; + + if ("$Pakfire::enable_colors" eq "1") { + $reset_color = "$Pakfire::color{'normal'}"; + $use_color = "$Pakfire::color{'lightpurple'}"; + } + &Pakfire::upgradecore(); - my @upgradepaks = &Pakfire::dblist("upgrade", "noweb"); + my @deps = (); - - if (@upgradepaks) { + if (my %upgradepaks = &Pakfire::dblist("upgrade")) { # Resolve the dependencies of the to be upgraded packages - @deps = &Pakfire::resolvedeps_recursive(@upgradepaks); + @deps = &Pakfire::resolvedeps_recursive(keys %upgradepaks); + foreach $pak (sort keys %upgradepaks) { + print "${use_color}Update: $pak\nVersion: $upgradepaks{$pak}{'ProgVersion'} -> $upgradepaks{$pak}{'AvailableProgVersion'}\n"; + print "Release: $upgradepaks{$pak}{'Release'} -> $upgradepaks{$pak}{'AvailableRelease'}${reset_color}\n"; + } &Pakfire::message(""); &Pakfire::message("PAKFIRE UPGR: We are going to install all packages listed above."); if ($interactive) { @@ -290,36 +301,78 @@ exit 1; } } - } + + # Download packages + foreach $pak (sort keys %upgradepaks) { + &Pakfire::getpak("$pak", ""); + } - # Download packages - foreach $pak (@upgradepaks) { - &Pakfire::getpak("$pak", ""); + # Download dependencies + foreach $pak (@deps) { + &Pakfire::getpak("$pak", ""); + } + + # Install dependencies first + foreach $pak (@deps) { + &Pakfire::setuppak("$pak"); + } + + # Install all upgrades + foreach $pak (sort keys %upgradepaks) { + &Pakfire::upgradepak("$pak"); + } + } else { + &Pakfire::message("PAKFIRE WARN: No new package upgrades available."); } - # Download dependencies - foreach $pak (@deps) { - &Pakfire::getpak("$pak", ""); + } elsif ("$ARGV[0]" eq "list") { + my $count; + my $use_color = ""; + my $reset_color = ""; + my $filter = "all"; + + if ("$ARGV[1]" =~ /installed|notinstalled/) { + $filter = "$ARGV[1]"; + } else { + &Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]); } - # Install dependencies first - foreach $pak (@deps) { - &Pakfire::setuppak("$pak"); + my $pak; + my %paklist = &Pakfire::dblist($filter); + + if ("$Pakfire::enable_colors" eq "1") { + $reset_color = "$Pakfire::color{'normal'}"; + $use_color = "$Pakfire::color{'lightgreen'}"; } - # Install all upgrades - foreach $pak (@upgradepaks) { - &Pakfire::upgradepak("$pak"); + foreach $pak (sort keys %paklist) { + if ("$Pakfire::enable_colors" eq "1") { + if ("$paklist{$pak}{'Installed'}" eq "yes") { + if (defined $paklist{$pak}{'AvailableProgVersion'}) { + $use_color = "$Pakfire::color{'lightgreen'}"; + } else { + $use_color = "$Pakfire::color{'green'}"; + } + } else { + $use_color = "$Pakfire::color{'red'}"; + } + } + + print "${use_color}Name: $pak\nProgVersion: $paklist{$pak}{'ProgVersion'}\n"; + print "Release: $paklist{$pak}{'Release'}\nInstalled: $paklist{$pak}{'Installed'}\n"; + if (defined $paklist{$pak}{'AvailableProgVersion'}) { + print "Update available:\n Version: $paklist{$pak}{'ProgVersion'} -> $paklist{$pak}{'AvailableProgVersion'}\n Release: $paklist{$pak}{'Release'} -> $paklist{$pak}{'AvailableRelease'}\n"; + } + print "${reset_color}\n"; + } - } elsif ("$ARGV[0]" eq "list") { - if ("$ARGV[1]" =~ /installed|notinstalled/) { - &Pakfire::dblist("$ARGV[1]", "noweb"); + $count = keys %paklist; + if ($count > 0) { + print "$count packages total.\n"; } else { - &Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]); - &Pakfire::dblist("all", "noweb"); + &Pakfire::message("PAKFIRE WARN: No packages where found using filter $filter."); } - } elsif ("$ARGV[0]" eq "resolvedeps") { foreach (@ARGV) { next if ("$_" eq "resolvedeps");