Hi all
In a previous patchset extra metadata was added to paks. The intention of this patchset was to make use of this metadata in pakfire and services.cgi. Along the road it was noted by Michael and Jonatan that there was a lot of duplicate and/or ugly code going on there that should be improved and not duplicated once more.
I have been working on this for quite some time, seperating logic and UI to have more generic functions in pakfire that can be reused more avoiding duplicate code in pakfire and other scripts that need data from pakfire. Here and there I also added other improvements as the cleaner code made those easy to implement.
I hope I have split the changes in small enough patches to make them easier to test.
- Patch 1: The function Pakfire::dblist is used to get a list of all paks but, until now, printed this list as a user formatted text which then needed to be catched and parsed again or parts of its code was duplicated to directly parse the .db files. This patch removes all UI parts from the function and refactors it to return the pak list as a hash instead of printing it as text. Also removed the core upgrade check and output from that function and added a function Pakfire::coredbinfo which returns available core db data as a hash. While moving the UI parts to the places where dblist is called I also added a bit more verbosity to the 'pakfire list' command by - adding an 'Installed: yes/no' field, so that also without color output this info is available. And - when a package upgrade is available it will now also be displayed. Example output of pakfire list: --- ...
Name: wio ProgVersion: 1.3.2 Release: 14 Installed: yes
Name: xinetd ProgVersion: 2.3.15 Release: 2 Installed: no
Name: zabbix_agentd ProgVersion: 4.2.6 Release: 4 Installed: yes Update available: Version: 4.2.6 -> 5.0.21 Release: 4 -> 5
204 packages total. --- And finaly I added the currently installed version to each installed pak in pakfire.cgi as that info is now available there.
- Patch 2: The result of previous patch are 2 'library' functions which are now the go-to functions if you need data from the core-list.db or packages_list.db files. Those files should not be parsed manually anymore anywhere else. This patch replaces such manual parsing in the 'pakfire install' routine.
- Patch 3: Does the same in the Pakfire::dbgetlist function. Also in this function functionality already in Pakfire::getmetafile was duplicated. This was also replaced by a call to getmetafile.
- Patch 4: Parsing of core-list.db in Pakfire::coreupdate_available is replaced with a call to the new Pakfire::coredbinfo.
- Patch 5: Removes core-list.db parsing and upgrade check from Pakfire::upgradecore and move it to the 'pakfire upgrade' routine adding a bit more verbosity along the way.
- Patch 6: Add a new filter 'upgrade' to the 'pakfire list' command. This filter was already available in Pakfire::dblist previously specificly to accomodate pakfire.cgi. Now this filter is also available for the CLI user, displaying a list of only the packages that need updates. Adding core update info as first list entry if an upgrade is available. Also fixed a small bug: previously 'pakfire list --no-colors installed' was not understood. Now it works like the install|remove commands.
- Patch 7: Remove UI elements from the Pakfire::status function now returning a hash with status information. Moving UI part to the 'pakfire status' routine. Replaced pakfire.cgi code duplicating the retrieval of the status info by a call to this Pakfire::status function.
- Patch 8: Adds a Pakfire::getmetadata function to get the metadata of a specific pak in a hash. Both 'installed' or 'latest' metadata can be requested. This function is for use everywhere pak metadata is required without having to know anything about inner working of pakfire db/meta-files. This functions is put in use for a new 'pakfire info <pak(s)>' routine for the CLI user to get all available metadata for a pak. And finaly the main purpose of this patchset: in services.cgi duplicate and or ugly code is replaced with Pakfire::dblist and Pakfire::getmetadata calls to determine which services are installed.
- Patch 9: Changes the workflow of the 'pakfire upgrade' routine. Previously when 'pakfire upgrade' was launched, a core update was immediatly installed. Then available pak updates where listed and user confirmation was asked (when not using -y). Firstly I found it quite rude of pakfire to immediatly perform the core upgrade when it should be 'interactive'. Secondly by then asking user confirmation for the pak updates, it was possible for the user to answer no and end up with a system where the installed addons are compiled against a previous core and probably no longer work. So that is not really a 'free choice' then :-) Now all upgrade info is gathered first and an upgrade summary is presented to the user (more in the style of the output when a pak is installed or removed) and confirmation is requested. Only after the user confirming the upgrade the core and the paks are upgraded in one go (except ofcourse when -y is used, then no confirmation is asked).
Example output of 'pakfire upgrade' now: --- CORE INFO: Checking for Core updates... PAKFIRE INFO: Checking for package updates... PAKFIRE RESV: zabbix_agentd: Resolving dependencies... PAKFIRE RESV: zabbix_agentd: Need to install dependency: fping PAKFIRE RESV: fping: Resolving dependencies...
PAKFIRE INFO: Upgrade summary:
CORE INFO: Core-Update 2.27.2-x86_64 to install: CORE UPGR: Release: 163 -> 165
PAKFIRE INFO: New dependencies to install: PAKFIRE INFO: fping - 30.00 KB
PAKFIRE INFO: Total size: ~ 30.00 KB
PAKFIRE INFO: Packages to upgrade: PAKFIRE UPGR: zabbix_agentd 4.2.6-4 -> 5.0.21-5
PAKFIRE INFO: Is this okay? [y/N] ---
Which looks much cleaner to me than before, and the user has the actual choice to cancel the upgrade before anything happened.
I know it is a big patchset and quite intrusive to the inner workings of pakfire, but I tried to test everything as thoroughly as possible and it should not break pakfire :-). It does make it a bit less errorprone, more robust and future-proof, easier to extend and to use both by the user and in other scripts.
Regards Robin
- 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 robin.roevens@disroot.org --- 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 "<br /><br /><br /><a href='pakfire.cgi'>$Lang::tr{'core notice 1'} $coredb{'Release'} $Lang::tr{'core notice 2'} $coredb{'AvailableRelease'} $Lang::tr{'core notice 3'}</a>"; +} + if ( -e "/var/run/need_reboot" ) { print "<div style='text-align:center; color:red;'>"; print "<br/><br/>$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; <select name="UPDPAKS" class="pflist" size="5" disabled> END
- &Pakfire::dblist("upgrade", "forweb"); + my %coredb = &Pakfire::coredbinfo(); + if (defined $coredb{'AvailableRelease'}) { + print "<option value="core">Core-Update -- $coredb{'CoreVersion'} -- Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n"; + } + + my %upgradelist = &Pakfire::dblist("upgrade"); + foreach my $pak (sort keys %upgradelist) { + print "<option value="$pak">Update: $pak -- Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n"; + } + + print <<END; </select> <input type='hidden' name='ACTION' value='upgrade' /> @@ -386,7 +396,11 @@ END <select name="INSPAKS" class="pflist" size="10" multiple> END
- &Pakfire::dblist("notinstalled", "forweb"); + my %notinstalledlist = &Pakfire::dblist("notinstalled"); + foreach my $pak (sort keys %notinstalledlist) { + print "<option value="$pak">$pak-$notinstalledlist{$pak}{'ProgVersion'}-$notinstalledlist{$pak}{'Release'}</option>\n"; + } + print <<END; </select> <input type='hidden' name='ACTION' value='install' /> @@ -398,7 +412,11 @@ END <select name="DELPAKS" class="pflist" size="10" multiple> END
- &Pakfire::dblist("installed", "forweb"); + my %installedlist = &Pakfire::dblist("installed"); + foreach my $pak (sort keys %installedlist) { + print "<option value="$pak">$pak-$installedlist{$pak}{'ProgVersion'}-$installedlist{$pak}{'Release'}</option>\n"; + } + print <<END; </select> <input type='hidden' name='ACTION' value='remove' /> 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 info@ipfire.org # +# Copyright (C) 2007-2022 IPFire Team info@ipfire.org # # # # 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 = <FILE>; 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 "<option value="core">Core-Update -- $Conf::version -- Release: $Conf::core_mine -> $core_release</option>\n"; - } - elsif ("$forweb" eq "notice") { - print "<br /><br /><br /><a href='pakfire.cgi'>$Lang::tr{'core notice 1'} $Conf::core_mine $Lang::tr{'core notice 2'} $core_release $Lang::tr{'core notice 3'}</a>"; - } 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 "<option value="$metadata{'Name'}">Update: $metadata{'Name'} -- Version: $metadata{'ProgVersion'} -> $templine[1] -- Release: $metadata{'Release'} -> $templine[2]</option>\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 "<option value="$templine[0]">$templine[0]-$templine[1]-$templine[2]</option>\n"; - } else { - print "<option value="$templine[0]">$templine[0]</option>\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");
Hello Robin,
Thank you for looking into Pakfire and making this thing more robust.
I have been meaning to give you a good review on this, but it is a lot of code with a lot of changes, which cannot introduce any regressions, because if something breaks we cannot fix it in an update...
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- Removed UI code from dblist function and refactor it making it return
a hash representing the pak db for easier handling of this data.
Yes. This is a good idea.
- 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.
Again, this would have been easier to review if it was split into smaller changes.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
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 "<br /><br /><br /><a href='pakfire.cgi'>$Lang::tr{'core notice 1'} $coredb{'Release'} $Lang::tr{'core notice 2'} $coredb{'AvailableRelease'} $Lang::tr{'core notice 3'}</a>";
+}
if ( -e "/var/run/need_reboot" ) { print "<div style='text-align:center; color:red;'>"; print "<br/><br/>$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; <select name="UPDPAKS" class="pflist" size="5" disabled> END
- &Pakfire::dblist("upgrade", "forweb");
- my %coredb = &Pakfire::coredbinfo();
- if (defined $coredb{'AvailableRelease'}) {
print "<option value=\"core\">Core-Update -- $coredb{'CoreVersion'} -- Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n";
- }
The strings “Core-Update” (without the dash) and “Release” should be translated so that they make sense in other languages. You can do that with $Lang::tr (I am sure you know).
- my %upgradelist = &Pakfire::dblist("upgrade");
- foreach my $pak (sort keys %upgradelist) {
print "<option value=\"$pak\">Update: $pak -- Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n";
- }
Same again here.
As a UI element, <select> is a very stupid idea. I have no idea why I ever picked that - presumably because there was the intention that users can pick what they want to install and what not. We should move away from this I believe.
- print <<END; </select> <input type='hidden' name='ACTION' value='upgrade' />
@@ -386,7 +396,11 @@ END <select name="INSPAKS" class="pflist" size="10" multiple> END
- &Pakfire::dblist("notinstalled", "forweb");
- my %notinstalledlist = &Pakfire::dblist("notinstalled");
- foreach my $pak (sort keys %notinstalledlist) {
print "<option value=\"$pak\">$pak-$notinstalledlist{$pak}{'ProgVersion'}-$notinstalledlist{$pak}{'Release'}</option>\n";
- }
- print <<END; </select> <input type='hidden' name='ACTION' value='install' />
@@ -398,7 +412,11 @@ END <select name="DELPAKS" class="pflist" size="10" multiple> END
- &Pakfire::dblist("installed", "forweb");
- my %installedlist = &Pakfire::dblist("installed");
- foreach my $pak (sort keys %installedlist) {
print "<option value=\"$pak\">$pak-$installedlist{$pak}{'ProgVersion'}-$installedlist{$pak}{'Release'}</option>\n";
- }
- print <<END; </select> <input type='hidden' name='ACTION' value='remove' />
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 info@ipfire.org # +# Copyright (C) 2007-2022 IPFire Team info@ipfire.org # # # # 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`);
I know the eval() statement has been used in the past, but since we touched this code now, can we remove this and just parse the line that we are looking for?
I consider this a security problem as it allows code injection.
- 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 = <FILE>; 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 "<option value=\"core\">Core-Update -- $Conf::version -- Release: $Conf::core_mine -> $core_release</option>\n";
}
elsif ("$forweb" eq "notice") {
print "<br /><br /><br /><a href='pakfire.cgi'>$Lang::tr{'core notice 1'} $Conf::core_mine $Lang::tr{'core notice 2'} $core_release $Lang::tr{'core notice 3'}</a>";
} 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 "<option value=\"$metadata{'Name'}\">Update: $metadata{'Name'} -- Version: $metadata{'ProgVersion'} -> $templine[1] -- Release: $metadata{'Release'} -> $templine[2]</option>\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 "<option value=\"$templine[0]\">$templine[0]-$templine[1]-$templine[2]</option>\n";
} else {
print "<option value=\"$templine[0]\">$templine[0]</option>\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;
}
This all looks good to me.
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) {
} else {print "$count packages total.\n";
&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");
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
-Michael
Hi Michael
Michael Tremer schreef op ma 21-03-2022 om 16:18 [+0000]:
Hello Robin,
Thank you for looking into Pakfire and making this thing more robust.
I have been meaning to give you a good review on this, but it is a lot of code with a lot of changes, which cannot introduce any regressions, because if something breaks we cannot fix it in an update...
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- Removed UI code from dblist function and refactor it making it
return a hash representing the pak db for easier handling of this data.
Yes. This is a good idea.
- 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.
Again, this would have been easier to review if it was split into smaller changes.
I'm doing my best :-) .. but I'm not sure how I should have split this up more ? Assuming every patch should leave the system in a fully functioning state ? By reworking the dblist function, I had to include the changes to the calls to that function, and due to the removal of the ui parts from it, I also had to include the ui additions in other places I only see those small visual enhancements in the ui parts that are now outside of the dblist function as candidate changes for separate patches, but then, as that code is already new in this patch, just changing exactly what is displayed UI-wise didn't look invasive enough to separate it ?
Signed-off-by: Robin Roevens robin.roevens@disroot.org
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 "<br /><br /><br /><a href='pakfire.cgi'>$Lang::tr{'core notice 1'} $coredb{'Release'} $Lang::tr{'core notice 2'} $coredb{'AvailableRelease'} $Lang::tr{'core notice 3'}</a>"; +}
if ( -e "/var/run/need_reboot" ) { print "<div style='text-align:center; color:red;'>"; print "<br/><br/>$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; <select name="UPDPAKS" class="pflist" size="5" disabled> END
- &Pakfire::dblist("upgrade", "forweb"); + my %coredb = &Pakfire::coredbinfo(); + if (defined $coredb{'AvailableRelease'}) { + print "<option value="core">Core-Update -- $coredb{'CoreVersion'} -- Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n"; + }
The strings “Core-Update” (without the dash) and “Release” should be translated so that they make sense in other languages. You can do that with $Lang::tr (I am sure you know).
Agreed, I don't think it was originally in this place as this came out of the previous dblist function. But you are right, I will use Lang::tr
+ my %upgradelist = &Pakfire::dblist("upgrade"); + foreach my $pak (sort keys %upgradelist) { + print "<option value="$pak">Update: $pak -- Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n"; + }
Same again here.
As a UI element, <select> is a very stupid idea. I have no idea why I ever picked that - presumably because there was the intention that users can pick what they want to install and what not. We should move away from this I believe.
Completely agree :-).. I was already trying to completely redesign the look of the pakfire webui page, to for example also include the summary now available in pak metadata. But I did not yet have a satisfying design in mind .. but I will probably propose something for this here with some mockup screenshots soon. So for now I kept it like it was.
print <<END; </select> <input type='hidden' name='ACTION' value='upgrade' /> @@ -386,7 +396,11 @@ END <select name="INSPAKS" class="pflist" size="10" multiple> END
- &Pakfire::dblist("notinstalled", "forweb"); + my %notinstalledlist = &Pakfire::dblist("notinstalled"); + foreach my $pak (sort keys %notinstalledlist) { + print "<option value="$pak">$pak- $notinstalledlist{$pak}{'ProgVersion'}- $notinstalledlist{$pak}{'Release'}</option>\n"; + }
print <<END; </select> <input type='hidden' name='ACTION' value='install' /> @@ -398,7 +412,11 @@ END <select name="DELPAKS" class="pflist" size="10" multiple> END
- &Pakfire::dblist("installed", "forweb"); + my %installedlist = &Pakfire::dblist("installed"); + foreach my $pak (sort keys %installedlist) { + print "<option value="$pak">$pak- $installedlist{$pak}{'ProgVersion'}- $installedlist{$pak}{'Release'}</option>\n"; + }
print <<END; </select> <input type='hidden' name='ACTION' value='remove' /> 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 info@ipfire.org # +# Copyright (C) 2007-2022 IPFire Team info@ipfire.org # # # # 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`);
I know the eval() statement has been used in the past, but since we touched this code now, can we remove this and just parse the line that we are looking for?
Done in patch 4/9. Due to splitting up my changes in separate patches as much as I thought possible :-)
Robin
I consider this a security problem as it allows code injection.
+ 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 = <FILE>; 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 "<option value="core">Core- Update -- $Conf::version -- Release: $Conf::core_mine -> $core_release</option>\n"; - } - elsif ("$forweb" eq "notice") { - print "<br /><br /><br /><a href='pakfire.cgi'>$Lang::tr{'core notice 1'} $Conf::core_mine $Lang::tr{'core notice 2'} $core_release $Lang::tr{'core notice 3'}</a>"; - } 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{'N ame'}); - if ("$forweb" eq "forweb") { - print "<option value="$metadata{'Name'}">Update: $metadata{'Name'} -- Version: $metadata{'ProgVersion'} -> $templine[1] -- Release: $metadata{'Release'} -> $templine[2]</option>\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'}, + AvailableProgVersio n => $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 "<option value="$templine[0]">$templine[0]-$templine[1]- $templine[2]</option>\n"; - } else { - print "<option value="$templine[0]">$templine[0]</option>\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; }
This all looks good to me.
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"); -- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
-Michael
Hi Michael
Robin Roevens schreef op di 22-03-2022 om 13:39 [+0100]:
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; <select name="UPDPAKS" class="pflist" size="5" disabled> END
- &Pakfire::dblist("upgrade", "forweb"); + my %coredb = &Pakfire::coredbinfo(); + if (defined $coredb{'AvailableRelease'}) { + print "<option value="core">Core-Update -- $coredb{'CoreVersion'} -- Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n"; + }
The strings “Core-Update” (without the dash) and “Release” should be translated so that they make sense in other languages. You can do that with $Lang::tr (I am sure you know).
Agreed, I don't think it was originally in this place as this came out of the previous dblist function. But you are right, I will use Lang::tr
I looked in the translation files, and currently there doesn't seem to be a translation string for "Core Update" and "Release". Should I just add it (to English and Dutch, I can)? Or did I overlook it ?
Regards
Robin
Hello,
On 23 Mar 2022, at 19:18, Robin Roevens robin.roevens@disroot.org wrote:
Hi Michael
Robin Roevens schreef op di 22-03-2022 om 13:39 [+0100]:
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; <select name="UPDPAKS" class="pflist" size="5" disabled> END
&Pakfire::dblist("upgrade", "forweb");
my %coredb = &Pakfire::coredbinfo();
if (defined $coredb{'AvailableRelease'}) {
print "<option value=\"core\">Core-Update --
$coredb{'CoreVersion'} -- Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n";
}
The strings “Core-Update” (without the dash) and “Release” should be translated so that they make sense in other languages. You can do that with $Lang::tr (I am sure you know).
Agreed, I don't think it was originally in this place as this came out of the previous dblist function. But you are right, I will use Lang::tr
I looked in the translation files, and currently there doesn't seem to be a translation string for "Core Update" and "Release". Should I just add it (to English and Dutch, I can)? Or did I overlook it ?
Yes, please just add the strings that you will need.
There are plenty of people who are native Germans here. Please get one of them to contribute the German strings. I don’t know who else we have on this list, but of course other languages are welcome too :)
Regards
Robin
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Replace pakfire install code duplicating dblist working with call to actual dblist function.
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- src/pakfire/pakfire | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-)
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index b4930e85d..f23110cf5 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -107,42 +107,30 @@ ### Make sure that the list is not outdated. &Pakfire::dbgetlist("noforce");
- open(FILE, "<$Conf::dbdir/lists/packages_list.db"); - my @db = <FILE>; - close(FILE); + my %paklist = &Pakfire::dblist("all");
my $dep; my @deps; my $pak; my @paks; my @temp; - my @templine; - my $found = 0; my $return; my @all; foreach $pak (@ARGV) { unless ("$pak" =~ "^-") { - $return = &Pakfire::isinstalled($pak); - if ($return eq 0) { - &Pakfire::message("PAKFIRE INFO: $pak is already installed"); - next; - } - $found = 0; - foreach (@db) { - @templine = split(/;/,$_); - if ("$templine[0]" eq "$pak" ) { - push(@paks,$pak); - push(@all,$pak); - @temp = &Pakfire::resolvedeps("$pak"); - foreach $dep (@temp) { - push(@deps,$dep) if $dep; - push(@all,$dep) if $dep; - } - $found = 1; - break; + if (defined $paklist{$pak}) { + if ("$paklist{$pak}{'Installed'}" eq "yes") { + &Pakfire::message("PAKFIRE INFO: $pak is already installed"); + next; } - } - if ($found == 0) { + push(@paks,$pak); + push(@all,$pak); + @temp = &Pakfire::resolvedeps("$pak"); + foreach $dep (@temp) { + push(@deps,$dep) if $dep; + push(@all,$dep) if $dep; + } + } else { &Pakfire::message(""); &Pakfire::message("PAKFIRE WARN: The pak "$pak" is not known. Please try running "pakfire update"."); }
This looks good to me.
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
Replace pakfire install code duplicating dblist working with call to actual dblist function.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/pakfire | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-)
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index b4930e85d..f23110cf5 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -107,42 +107,30 @@ ### Make sure that the list is not outdated. &Pakfire::dbgetlist("noforce");
open(FILE, "<$Conf::dbdir/lists/packages_list.db");
my @db = <FILE>;
close(FILE);
my %paklist = &Pakfire::dblist("all");
my $dep; my @deps; my $pak; my @paks; my @temp;
my @templine;
my $return; my @all; foreach $pak (@ARGV) { unless ("$pak" =~ "^-") {my $found = 0;
$return = &Pakfire::isinstalled($pak);
if ($return eq 0) {
&Pakfire::message("PAKFIRE INFO: $pak is already installed");
next;
}
$found = 0;
foreach (@db) {
@templine = split(/;/,$_);
if ("$templine[0]" eq "$pak" ) {
push(@paks,$pak);
push(@all,$pak);
@temp = &Pakfire::resolvedeps("$pak");
foreach $dep (@temp) {
push(@deps,$dep) if $dep;
push(@all,$dep) if $dep;
}
$found = 1;
break;
if (defined $paklist{$pak}) {
if ("$paklist{$pak}{'Installed'}" eq "yes") {
&Pakfire::message("PAKFIRE INFO: $pak is already installed");
next; }
}
if ($found == 0) {
push(@paks,$pak);
push(@all,$pak);
@temp = &Pakfire::resolvedeps("$pak");
foreach $dep (@temp) {
push(@deps,$dep) if $dep;
push(@all,$dep) if $dep;
}
} else { &Pakfire::message(""); &Pakfire::message("PAKFIRE WARN: The pak \"$pak\" is not known. Please try running \"pakfire update\"."); }
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Replace dbgetlist code duplicating dblist and getmetafile workings with call to actual dblist and getmetafile functions.
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- src/pakfire/lib/functions.pl | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index f08f43622..0caa4787e 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -401,9 +401,7 @@ sub dbgetlist { my %metadata; my @templine;
- open(FILE, "<$Conf::dbdir/lists/packages_list.db"); - my @db = <FILE>; - close(FILE); + my %paklist = &Pakfire::dblist("all");
opendir(DIR,"$Conf::dbdir/meta"); my @files = readdir(DIR); @@ -415,13 +413,9 @@ sub dbgetlist { next if ( $file =~ /^old/ ); %metadata = parsemetafile("$Conf::dbdir/meta/$file");
- foreach $prog (@db) { - @templine = split(/;/,$prog); - if (("$metadata{'Name'}" eq "$templine[0]") && ("$metadata{'Release'}" ne "$templine[2]")) { - move("$Conf::dbdir/meta/meta-$metadata{'Name'}","$Conf::dbdir/meta/old_meta-$metadata{'Name'}"); - fetchfile("meta/meta-$metadata{'Name'}", ""); - move("$Conf::cachedir/meta-$metadata{'Name'}", "$Conf::dbdir/meta/meta-$metadata{'Name'}"); - } + if ((defined $paklist{"$metadata{'Name'}"}) && ("$paklist{"$metadata{'Name'}"}{'Release'}" ne "$metadata{'Release'}")) { + move("$Conf::dbdir/meta/meta-$metadata{'Name'}","$Conf::dbdir/meta/old_meta-$metadata{'Name'}"); + getmetafile($metadata{'Name'}); } } }
This looks okay, too.
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
Replace dbgetlist code duplicating dblist and getmetafile workings with call to actual dblist and getmetafile functions.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/lib/functions.pl | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index f08f43622..0caa4787e 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -401,9 +401,7 @@ sub dbgetlist { my %metadata; my @templine;
- open(FILE, "<$Conf::dbdir/lists/packages_list.db");
- my @db = <FILE>;
- close(FILE);
my %paklist = &Pakfire::dblist("all");
opendir(DIR,"$Conf::dbdir/meta"); my @files = readdir(DIR);
@@ -415,13 +413,9 @@ sub dbgetlist { next if ( $file =~ /^old/ ); %metadata = parsemetafile("$Conf::dbdir/meta/$file");
foreach $prog (@db) {
@templine = split(/\;/,$prog);
if (("$metadata{'Name'}" eq "$templine[0]") && ("$metadata{'Release'}" ne "$templine[2]")) {
move("$Conf::dbdir/meta/meta-$metadata{'Name'}","$Conf::dbdir/meta/old_meta-$metadata{'Name'}");
fetchfile("meta/meta-$metadata{'Name'}", "");
move("$Conf::cachedir/meta-$metadata{'Name'}", "$Conf::dbdir/meta/meta-$metadata{'Name'}");
}
if ((defined $paklist{"$metadata{'Name'}"}) && ("$paklist{\"$metadata{'Name'}\"}{'Release'}" ne "$metadata{'Release'}")) {
move("$Conf::dbdir/meta/meta-$metadata{'Name'}","$Conf::dbdir/meta/old_meta-$metadata{'Name'}");
} }getmetafile($metadata{'Name'});
}
2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Replace coreupdate_available code duplicating coredbinfo workings with call to actual coredbinfo function.
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- src/pakfire/lib/functions.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 0caa4787e..1e2729485 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -884,9 +884,10 @@ sub updates_available { }
sub coreupdate_available { - eval(`grep "core_" $Conf::dbdir/lists/core-list.db`); - if ("$core_release" > "$Conf::core_mine") { - return "yes ($core_release)"; + my %coredb = &Pakfire::coredbinfo(); + + if ("$coredb{'AvailableRelease'}" > "$coredb{'Release'}") { + return "yes ($coredb{'AvailableRelease'})"; } else { return "no";
This is a lot nicer without eval().
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
Replace coreupdate_available code duplicating coredbinfo workings with call to actual coredbinfo function.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/lib/functions.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 0caa4787e..1e2729485 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -884,9 +884,10 @@ sub updates_available { }
sub coreupdate_available {
- eval(`grep "core_" $Conf::dbdir/lists/core-list.db`);
- if ("$core_release" > "$Conf::core_mine") {
return "yes ($core_release)";
- my %coredb = &Pakfire::coredbinfo();
- if ("$coredb{'AvailableRelease'}" > "$coredb{'Release'}") {
} else { return "no";return "yes ($coredb{'AvailableRelease'})";
Is returning a string what we want here?
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Hi Michael
Michael Tremer schreef op ma 21-03-2022 om 16:21 [+0000]:
This is a lot nicer without eval().
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
Replace coreupdate_available code duplicating coredbinfo workings with call to actual coredbinfo function.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/lib/functions.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 0caa4787e..1e2729485 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -884,9 +884,10 @@ sub updates_available { }
sub coreupdate_available { - eval(`grep "core_" $Conf::dbdir/lists/core-list.db`); - if ("$core_release" > "$Conf::core_mine") { - return "yes ($core_release)"; + my %coredb = &Pakfire::coredbinfo();
+ if ("$coredb{'AvailableRelease'}" > "$coredb{'Release'}") { + return "yes ($coredb{'AvailableRelease'})"; } else { return "no";
Is returning a string what we want here?
Valid question.. I will look into it. In the light of moving UI out of the library functions that would certainly be the right thing to do (not returning strings here).
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Hi
Robin Roevens schreef op di 22-03-2022 om 13:42 [+0100]:
Hi Michael
Michael Tremer schreef op ma 21-03-2022 om 16:21 [+0000]:
This is a lot nicer without eval().
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
Replace coreupdate_available code duplicating coredbinfo workings with call to actual coredbinfo function.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/lib/functions.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 0caa4787e..1e2729485 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -884,9 +884,10 @@ sub updates_available { }
sub coreupdate_available { - eval(`grep "core_" $Conf::dbdir/lists/core-list.db`); - if ("$core_release" > "$Conf::core_mine") { - return "yes ($core_release)"; + my %coredb = &Pakfire::coredbinfo();
+ if ("$coredb{'AvailableRelease'}" > "$coredb{'Release'}") { + return "yes ($coredb{'AvailableRelease'})"; } else { return "no";
Is returning a string what we want here?
Valid question.. I will look into it. In the light of moving UI out of the library functions that would certainly be the right thing to do (not returning strings here).
I looked into it and found out that the only place where this function is actually used is in Pakfire::status which I rewrite a few patches later and this function becomes obsolete. So this patch is actually pointless :-).. I will remove it and remove the function coreupdate_available. This information is available from either function coredbinfo (wether key 'AvailableRelease' exists) of from the new status function (returns hash with a key 'CoreUpdateAvailable' = yes/no)
Robin
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
upgradecore function should just upgrade the core: Moved check if upgrade is necessary to pakfire upgrade code, removing code from upgradecore function duplicating codedbinfo workings. Also adding more vebosity to pakfire upgrade.
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- src/pakfire/lib/functions.pl | 47 +++++++++++++++--------------------- src/pakfire/pakfire | 16 +++++++++++- 2 files changed, 35 insertions(+), 28 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 1e2729485..6287367f5 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -735,35 +735,28 @@ sub setuppak { }
sub upgradecore { - getcoredb("noforce"); - eval(`grep "core_" $Conf::dbdir/lists/core-list.db`); - if ("$core_release" > "$Conf::core_mine") { - # Safety check for lazy testers: - # Before we upgrade to the latest release, we re-install the previous release - # to make sure that the tester has always been on the latest version. - my $tree = &get_tree(); - $Conf::core_mine-- if ($tree eq "testing" || $tree eq "unstable"); - - message("CORE UPGR: Upgrading from release $Conf::core_mine to $core_release"); - - my @seq = `seq $Conf::core_mine $core_release`; - shift @seq; - my $release; - foreach $release (@seq) { - chomp($release); - getpak("core-upgrade-$release"); - } - - foreach $release (@seq) { - chomp($release); - upgradepak("core-upgrade-$release"); - } - - system("echo $core_release > $Conf::coredir/mine"); + # Safety check for lazy testers: + # Before we upgrade to the latest release, we re-install the previous release + # to make sure that the tester has always been on the latest version. + my $tree = &get_tree(); + $Conf::core_mine-- if ($tree eq "testing" || $tree eq "unstable");
- } else { - message("CORE ERROR: No new upgrades available. You are on release $Conf::core_mine."); + message("CORE UPGR: Upgrading from release $Conf::core_mine to $core_release"); + + my @seq = `seq $Conf::core_mine $core_release`; + shift @seq; + my $release; + foreach $release (@seq) { + chomp($release); + getpak("core-upgrade-$release"); } + + foreach $release (@seq) { + chomp($release); + upgradepak("core-upgrade-$release"); + } + + system("echo $core_release > $Conf::coredir/mine"); }
sub isinstalled { diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index f23110cf5..2fb9adce7 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -266,7 +266,21 @@ $use_color = "$Pakfire::color{'lightpurple'}"; }
- &Pakfire::upgradecore(); + &Pakfire::message("CORE INFO: Checking for Core updates..."); + + ### Make sure that the core db is not outdated. + &Pakfire::getcoredb("noforce"); + my %coredb = &Pakfire::coredbinfo(); + + if (defined $coredb{'AvailableRelease'}) { + &Pakfire::upgradecore(); + } else { + &Pakfire::message("CORE WARN: No new Core upgrades available. You are on release ".$coredb{'Release'}); + } + + &Pakfire::message("PAKFIRE INFO: Checking for package updates..."); + ### Make sure that the package list is not outdated. + &Pakfire::dbgetlist("noforce"); my @deps = (); if (my %upgradepaks = &Pakfire::dblist("upgrade")) {
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
upgradecore function should just upgrade the core: Moved check if upgrade is necessary to pakfire upgrade code, removing code from upgradecore function duplicating codedbinfo workings. Also adding more vebosity to pakfire upgrade.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/lib/functions.pl | 47 +++++++++++++++--------------------- src/pakfire/pakfire | 16 +++++++++++- 2 files changed, 35 insertions(+), 28 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 1e2729485..6287367f5 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -735,35 +735,28 @@ sub setuppak { }
sub upgradecore {
- getcoredb("noforce");
- eval(`grep "core_" $Conf::dbdir/lists/core-list.db`);
- if ("$core_release" > "$Conf::core_mine") {
# Safety check for lazy testers:
# Before we upgrade to the latest release, we re-install the previous release
# to make sure that the tester has always been on the latest version.
my $tree = &get_tree();
$Conf::core_mine-- if ($tree eq "testing" || $tree eq "unstable");
message("CORE UPGR: Upgrading from release $Conf::core_mine to $core_release");
my @seq = `seq $Conf::core_mine $core_release`;
shift @seq;
my $release;
foreach $release (@seq) {
chomp($release);
getpak("core-upgrade-$release");
}
foreach $release (@seq) {
chomp($release);
upgradepak("core-upgrade-$release");
}
system("echo $core_release > $Conf::coredir/mine");
- # Safety check for lazy testers:
- # Before we upgrade to the latest release, we re-install the previous release
- # to make sure that the tester has always been on the latest version.
- my $tree = &get_tree();
- $Conf::core_mine-- if ($tree eq "testing" || $tree eq "unstable");
- } else {
message("CORE ERROR: No new upgrades available. You are on release $Conf::core_mine.");
- message("CORE UPGR: Upgrading from release $Conf::core_mine to $core_release");
- my @seq = `seq $Conf::core_mine $core_release`;
Can we remove this shell command call? This should be easily replaced with native Perl.
- shift @seq;
- my $release;
- foreach $release (@seq) {
chomp($release);
}getpak("core-upgrade-$release");
- foreach $release (@seq) {
chomp($release);
upgradepak("core-upgrade-$release");
- }
- system("echo $core_release > $Conf::coredir/mine");
}
sub isinstalled { diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index f23110cf5..2fb9adce7 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -266,7 +266,21 @@ $use_color = "$Pakfire::color{'lightpurple'}"; }
&Pakfire::upgradecore();
&Pakfire::message("CORE INFO: Checking for Core updates...");
### Make sure that the core db is not outdated.
&Pakfire::getcoredb("noforce");
my %coredb = &Pakfire::coredbinfo();
if (defined $coredb{'AvailableRelease'}) {
&Pakfire::upgradecore();
} else {
&Pakfire::message("CORE WARN: No new Core upgrades available. You are on release ".$coredb{'Release'});
Here, the Core Update is being called Core Upgrade. That might be coming from somewhere else. In the end we should probably reword lots of the error messages to make them consistent and easy to understand.
}
&Pakfire::message("PAKFIRE INFO: Checking for package updates...");
### Make sure that the package list is not outdated.
my @deps = (); if (my %upgradepaks = &Pakfire::dblist("upgrade")) {&Pakfire::dbgetlist("noforce");
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Michael Tremer schreef op ma 21-03-2022 om 16:24 [+0000]:
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
upgradecore function should just upgrade the core: Moved check if upgrade is necessary to pakfire upgrade code, removing code from upgradecore function duplicating codedbinfo workings. Also adding more vebosity to pakfire upgrade.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/lib/functions.pl | 47 +++++++++++++++------------------
src/pakfire/pakfire | 16 +++++++++++- 2 files changed, 35 insertions(+), 28 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 1e2729485..6287367f5 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -735,35 +735,28 @@ sub setuppak { }
sub upgradecore { - getcoredb("noforce"); - eval(`grep "core_" $Conf::dbdir/lists/core-list.db`); - if ("$core_release" > "$Conf::core_mine") { - # Safety check for lazy testers: - # Before we upgrade to the latest release, we re- install the previous release - # to make sure that the tester has always been on the latest version. - my $tree = &get_tree(); - $Conf::core_mine-- if ($tree eq "testing" || $tree eq "unstable");
- message("CORE UPGR: Upgrading from release $Conf::core_mine to $core_release");
- my @seq = `seq $Conf::core_mine $core_release`; - shift @seq; - my $release; - foreach $release (@seq) { - chomp($release); - getpak("core-upgrade-$release"); - }
- foreach $release (@seq) { - chomp($release); - upgradepak("core-upgrade-$release"); - }
- system("echo $core_release > $Conf::coredir/mine"); + # Safety check for lazy testers: + # Before we upgrade to the latest release, we re-install the previous release + # to make sure that the tester has always been on the latest version. + my $tree = &get_tree(); + $Conf::core_mine-- if ($tree eq "testing" || $tree eq "unstable");
- } else { - message("CORE ERROR: No new upgrades available. You are on release $Conf::core_mine."); + message("CORE UPGR: Upgrading from release $Conf::core_mine to $core_release"); + + my @seq = `seq $Conf::core_mine $core_release`;
Can we remove this shell command call? This should be easily replaced with native Perl.
Strange.. I can remember I changed that to ($Conf::core_mine..$core_release) .. must have gone lost somewhere in my drafts. I will change it.
+ shift @seq; + my $release; + foreach $release (@seq) { + chomp($release); + getpak("core-upgrade-$release"); } + + foreach $release (@seq) { + chomp($release); + upgradepak("core-upgrade-$release"); + } + + system("echo $core_release > $Conf::coredir/mine"); }
sub isinstalled { diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index f23110cf5..2fb9adce7 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -266,7 +266,21 @@ $use_color = "$Pakfire::color{'lightpurple'}"; }
- &Pakfire::upgradecore(); + &Pakfire::message("CORE INFO: Checking for Core updates...");
+ ### Make sure that the core db is not outdated. + &Pakfire::getcoredb("noforce"); + my %coredb = &Pakfire::coredbinfo();
+ if (defined $coredb{'AvailableRelease'}) { + &Pakfire::upgradecore(); + } else { + &Pakfire::message("CORE WARN: No new Core upgrades available. You are on release ".$coredb{'Release'});
Here, the Core Update is being called Core Upgrade. That might be coming from somewhere else. In the end we should probably reword lots of the error messages to make them consistent and easy to understand.
Yes, also "pakfire update" vs "pakfire upgrade", possibly the reason why it is called "core upgrade" here. Should I change everything to 'update' ? But then I think it would also be more clear if 'pakfire update' would update the system instead of only the pakfire db? So maybe we can 'rename' 'pakfire update' to 'pakfire refresh' and then rename 'pakfire upgrade' to 'pakfire update'... (possibly keeping 'pakfire upgrade' as an alias for 'pakfire update' for some backward compatibility) I'm a bit reticent about this as it changes the existing meaning of 'pakfire update' but I think that it would be more consistent in the end ?
+ }
+ &Pakfire::message("PAKFIRE INFO: Checking for package updates..."); + ### Make sure that the package list is not outdated. + &Pakfire::dbgetlist("noforce"); my @deps = (); if (my %upgradepaks = &Pakfire::dblist("upgrade")) { -- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Hey,
On 22 Mar 2022, at 12:58, Robin Roevens robin.roevens@disroot.org wrote:
Michael Tremer schreef op ma 21-03-2022 om 16:24 [+0000]:
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
upgradecore function should just upgrade the core: Moved check if upgrade is necessary to pakfire upgrade code, removing code from upgradecore function duplicating codedbinfo workings. Also adding more vebosity to pakfire upgrade.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/lib/functions.pl | 47 +++++++++++++++------------------
src/pakfire/pakfire | 16 +++++++++++- 2 files changed, 35 insertions(+), 28 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 1e2729485..6287367f5 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -735,35 +735,28 @@ sub setuppak { }
sub upgradecore {
getcoredb("noforce");
eval(`grep "core_" $Conf::dbdir/lists/core-list.db`);
if ("$core_release" > "$Conf::core_mine") {
# Safety check for lazy testers:
# Before we upgrade to the latest release, we re-
install the previous release
# to make sure that the tester has always been on
the latest version.
my $tree = &get_tree();
$Conf::core_mine-- if ($tree eq "testing" || $tree
eq "unstable");
message("CORE UPGR: Upgrading from release
$Conf::core_mine to $core_release");
my @seq = `seq $Conf::core_mine $core_release`;
shift @seq;
my $release;
foreach $release (@seq) {
chomp($release);
getpak("core-upgrade-$release");
}
foreach $release (@seq) {
chomp($release);
upgradepak("core-upgrade-$release");
}
system("echo $core_release > $Conf::coredir/mine");
# Safety check for lazy testers:
# Before we upgrade to the latest release, we re-install
the previous release
# to make sure that the tester has always been on the
latest version.
my $tree = &get_tree();
$Conf::core_mine-- if ($tree eq "testing" || $tree eq
"unstable");
} else {
message("CORE ERROR: No new upgrades available. You
are on release $Conf::core_mine.");
message("CORE UPGR: Upgrading from release $Conf::core_mine
to $core_release");
my @seq = `seq $Conf::core_mine $core_release`;
Can we remove this shell command call? This should be easily replaced with native Perl.
Strange.. I can remember I changed that to ($Conf::core_mine..$core_release) .. must have gone lost somewhere in my drafts. I will change it.
Okay. Thank you.
shift @seq;
my $release;
foreach $release (@seq) {
chomp($release);
getpak("core-upgrade-$release"); }
foreach $release (@seq) {
chomp($release);
upgradepak("core-upgrade-$release");
}
system("echo $core_release > $Conf::coredir/mine");
}
sub isinstalled { diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index f23110cf5..2fb9adce7 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -266,7 +266,21 @@ $use_color = "$Pakfire::color{'lightpurple'}"; }
&Pakfire::upgradecore();
&Pakfire::message("CORE INFO: Checking for Core
updates...");
### Make sure that the core db is not outdated.
&Pakfire::getcoredb("noforce");
my %coredb = &Pakfire::coredbinfo();
if (defined $coredb{'AvailableRelease'}) {
&Pakfire::upgradecore();
} else {
&Pakfire::message("CORE WARN: No new Core
upgrades available. You are on release ".$coredb{'Release'});
Here, the Core Update is being called Core Upgrade. That might be coming from somewhere else. In the end we should probably reword lots of the error messages to make them consistent and easy to understand.
Yes, also "pakfire update" vs "pakfire upgrade", possibly the reason why it is called "core upgrade" here. Should I change everything to 'update' ?
No, this is a little bit similar to apt-get which has an update and an upgrade command. That was the intention at least.
I would just change the name “Core Upgrade” to “Core Update” because that is what we call it. It is only an aesthetic change.
But then I think it would also be more clear if 'pakfire update' would update the system instead of only the pakfire db? So maybe we can 'rename' 'pakfire update' to 'pakfire refresh' and then rename 'pakfire upgrade' to 'pakfire update'... (possibly keeping 'pakfire upgrade' as an alias for 'pakfire update' for some backward compatibility)
This would break people’s scripts, so I wouldn’t say this is worth it.
I'm a bit reticent about this as it changes the existing meaning of 'pakfire update' but I think that it would be more consistent in the end ?
}
&Pakfire::message("PAKFIRE INFO: Checking for
package updates...");
### Make sure that the package list is not
outdated.
&Pakfire::dbgetlist("noforce"); my @deps = (); if (my %upgradepaks = &Pakfire::dblist("upgrade"))
{
2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
- Added possibility to list available upgrades from commandline using 'pakfire list upgrade'. - Bugfix: allow [options] between 'list' and [installed/notinstalled/ upgrade]
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- src/pakfire/lib/functions.pl | 2 +- src/pakfire/pakfire | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 6287367f5..b35aed6a3 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -114,7 +114,7 @@ sub usage { &Pakfire::message("Usage: pakfire <install|remove> [options] <pak(s)>"); &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(" <list> [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks."); &Pakfire::message(" <status> - Outputs a summary about available core upgrades, updates and a required reboot"); &Pakfire::message(""); &Pakfire::message(" Global options:"); diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 2fb9adce7..b529db77a 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -333,7 +333,9 @@ my $reset_color = ""; my $filter = "all";
- if ("$ARGV[1]" =~ /installed|notinstalled/) { + shift if ("$ARGV[1]" =~ "^-"); + + if ("$ARGV[1]" =~ /installed|notinstalled|upgrade/) { $filter = "$ARGV[1]"; } else { &Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]); @@ -347,6 +349,16 @@ $use_color = "$Pakfire::color{'lightgreen'}"; }
+ # Check for available core upgrade first if list of upgrades is requested + if ("$filter" eq "upgrade") { + my %coredb = &Pakfire::coredbinfo(); + + if (defined $coredb{'AvailableRelease'}) { + print "${use_color}Core-Update $coredb{'CoreVersion'}\n"; + print "Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}${reset_color}\n\n"; + } + } + foreach $pak (sort keys %paklist) { if ("$Pakfire::enable_colors" eq "1") { if ("$paklist{$pak}{'Installed'}" eq "yes") {
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- Added possibility to list available upgrades from commandline
using 'pakfire list upgrade'.
- Bugfix: allow [options] between 'list' and [installed/notinstalled/
upgrade]
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/lib/functions.pl | 2 +- src/pakfire/pakfire | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 6287367f5..b35aed6a3 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -114,7 +114,7 @@ sub usage { &Pakfire::message("Usage: pakfire <install|remove> [options] <pak(s)>"); &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(" <list> [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks."); &Pakfire::message(" <status> - Outputs a summary about available core upgrades, updates and a required reboot"); &Pakfire::message(""); &Pakfire::message(" Global options:");
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 2fb9adce7..b529db77a 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -333,7 +333,9 @@ my $reset_color = ""; my $filter = "all";
if ("$ARGV[1]" =~ /installed|notinstalled/) {
shift if ("$ARGV[1]" =~ "^-");
} else { &Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]);if ("$ARGV[1]" =~ /installed|notinstalled|upgrade/) { $filter = "$ARGV[1]";
@@ -347,6 +349,16 @@ $use_color = "$Pakfire::color{'lightgreen'}"; }
# Check for available core upgrade first if list of upgrades is requested
if ("$filter" eq "upgrade") {
my %coredb = &Pakfire::coredbinfo();
if (defined $coredb{'AvailableRelease'}) {
print "${use_color}Core-Update $coredb{'CoreVersion'}\n";
print "Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}${reset_color}\n\n";
}
}
Here we should add an exit code, because monitoring people love them :)
- foreach $pak (sort keys %paklist) { if ("$Pakfire::enable_colors" eq "1") { if ("$paklist{$pak}{'Installed'}" eq "yes") {
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Michael Tremer schreef op ma 21-03-2022 om 16:33 [+0000]:
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- Added possibility to list available upgrades from commandline
using 'pakfire list upgrade'.
- Bugfix: allow [options] between 'list' and
[installed/notinstalled/ upgrade]
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/lib/functions.pl | 2 +- src/pakfire/pakfire | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 6287367f5..b35aed6a3 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -114,7 +114,7 @@ sub usage { &Pakfire::message("Usage: pakfire <install|remove> [options] <pak(s)>"); &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(" <list> [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks."); &Pakfire::message(" <status> - Outputs a summary about available core upgrades, updates and a required reboot"); &Pakfire::message(""); &Pakfire::message(" Global options:"); diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 2fb9adce7..b529db77a 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -333,7 +333,9 @@ my $reset_color = ""; my $filter = "all";
- if ("$ARGV[1]" =~ /installed|notinstalled/) { + shift if ("$ARGV[1]" =~ "^-");
+ if ("$ARGV[1]" =~ /installed|notinstalled|upgrade/) { $filter = "$ARGV[1]"; } else { &Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]); @@ -347,6 +349,16 @@ $use_color = "$Pakfire::color{'lightgreen'}"; }
+ # Check for available core upgrade first if list of upgrades is requested + if ("$filter" eq "upgrade") { + my %coredb = &Pakfire::coredbinfo();
+ if (defined $coredb{'AvailableRelease'}) { + print "${use_color}Core-Update $coredb{'CoreVersion'}\n"; + print "Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}${reset_color}\n\n"; + } + }
Here we should add an exit code, because monitoring people love them :)
Agreed :-).. will look into it.
foreach $pak (sort keys %paklist) { if ("$Pakfire::enable_colors" eq "1") { if ("$paklist{$pak}{'Installed'}" eq "yes") { -- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
- removed UI related code from status function and refactor it to returning hash representing pakfire status. - Add UI part to pakfire script - Use pakfire status function in pakfire.cgi, removing duplicate code
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- html/cgi-bin/pakfire.cgi | 39 ++++++++++++++++------------------- src/pakfire/lib/functions.pl | 40 ++++++++++++++++++------------------ src/pakfire/pakfire | 13 +++++++++++- 3 files changed, 50 insertions(+), 42 deletions(-)
diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index 30a23128b..d62b6058f 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -37,6 +37,9 @@ my %color = (); my %pakfiresettings = (); my %mainsettings = ();
+# Get Pakfire status +my %pakfire_status = &Pakfire::status(); + # Load general settings &General::readhash("${General::swroot}/main/settings", %mainsettings); &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", %color); @@ -66,7 +69,7 @@ if($cgiparams{'ACTION'} eq 'json-getstatus') { my %status = ( 'running' => &_is_pakfire_busy() || "0", 'running_since' => &General::age("$Pakfire::lockfile") || "0s", - 'reboot' => (-e "/var/run/need_reboot") || "0", + 'reboot' => ("$pakfire_status{'RebootRequired'}" eq "yes") || "0", 'failure' => $failure || "0" );
@@ -333,32 +336,26 @@ END exit; }
-my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`; -chomp($core_release); -my $core_update_age = &General::age("/opt/pakfire/db/core/mine"); -my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db"); -my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db"); -my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db"); - &Header::openbox("100%", "center", "Pakfire");
print <<END; <table id="pfmain"> END -if ( -e "/var/run/need_reboot") { +if ("$pakfire_status{'RebootRequired'}" eq "yes") { print "\t\t<tr><td colspan='2'><a href='/cgi-bin/shutdown.cgi'>$Lang::tr{'needreboot'}!</a></td></tr>\n"; } + print <<END; <tr><td class="heading">$Lang::tr{'pakfire system state'}:</td> <td class="heading">$Lang::tr{'available updates'}:</td></tr>
- <tr><td><strong>$Lang::tr{'pakfire core update level'}: $core_release</strong> + <tr><td><strong>$Lang::tr{'pakfire core update level'}: $pakfire_status{'Release'}</strong> <hr> <div class="pflist"> - $Lang::tr{'pakfire last update'} $core_update_age $Lang::tr{'pakfire ago'}<br> - $Lang::tr{'pakfire last serverlist update'} $server_update_age $Lang::tr{'pakfire ago'}<br> - $Lang::tr{'pakfire last core list update'} $corelist_update_age $Lang::tr{'pakfire ago'}<br> - $Lang::tr{'pakfire last package update'} $packages_update_age $Lang::tr{'pakfire ago'} + $Lang::tr{'pakfire last update'} $pakfire_status{'LastUpdate'} $Lang::tr{'pakfire ago'}<br> + $Lang::tr{'pakfire last serverlist update'} $pakfire_status{'LastServerListUpdate'} $Lang::tr{'pakfire ago'}<br> + $Lang::tr{'pakfire last core list update'} $pakfire_status{'LastCoreListUpdate'} $Lang::tr{'pakfire ago'}<br> + $Lang::tr{'pakfire last package update'} $pakfire_status{'LastPakListUpdate'} $Lang::tr{'pakfire ago'} </div> <form method='post' action='$ENV{'SCRIPT_NAME'}'> <input type='hidden' name='ACTION' value='update' /> @@ -370,17 +367,17 @@ print <<END; <select name="UPDPAKS" class="pflist" size="5" disabled> END
- my %coredb = &Pakfire::coredbinfo(); - if (defined $coredb{'AvailableRelease'}) { - print "<option value="core">Core-Update -- $coredb{'CoreVersion'} -- Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n"; + if ("$pakfire_status{'CoreUpdateAvailable'}" eq "yes") { + print "<option value="core">Core-Update -- $pakfire_status{'CoreVersion'} -- Release: $pakfire_status{'Release'} -> $pakfire_status{'AvailableRelease'}</option>\n"; }
- my %upgradelist = &Pakfire::dblist("upgrade"); - foreach my $pak (sort keys %upgradelist) { - print "<option value="$pak">Update: $pak -- Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n"; + if ($pakfire_status{'PakUpdatesAvailable'} > 0) { + my %upgradelist = &Pakfire::dblist("upgrade"); + foreach my $pak (sort keys %upgradelist) { + print "<option value="$pak">Update: $pak -- Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n"; + } }
- print <<END; </select> <input type='hidden' name='ACTION' value='upgrade' /> diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index b35aed6a3..028a0277e 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -897,26 +897,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 b529db77a..0ed8aacd4 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -406,7 +406,18 @@ system("rm -f /etc/fcron.daily/pakfire-upgrade"); } } elsif ("$ARGV[0]" eq "status") { - &Pakfire::status; + 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"; } else { &Pakfire::usage; }
Hey,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- removed UI related code from status function and refactor it
to returning hash representing pakfire status.
- Add UI part to pakfire script
- Use pakfire status function in pakfire.cgi, removing duplicate code
Signed-off-by: Robin Roevens robin.roevens@disroot.org
html/cgi-bin/pakfire.cgi | 39 ++++++++++++++++------------------- src/pakfire/lib/functions.pl | 40 ++++++++++++++++++------------------ src/pakfire/pakfire | 13 +++++++++++- 3 files changed, 50 insertions(+), 42 deletions(-)
diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index 30a23128b..d62b6058f 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -37,6 +37,9 @@ my %color = (); my %pakfiresettings = (); my %mainsettings = ();
+# Get Pakfire status +my %pakfire_status = &Pakfire::status();
# Load general settings &General::readhash("${General::swroot}/main/settings", %mainsettings); &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", %color); @@ -66,7 +69,7 @@ if($cgiparams{'ACTION'} eq 'json-getstatus') { my %status = ( 'running' => &_is_pakfire_busy() || "0", 'running_since' => &General::age("$Pakfire::lockfile") || "0s",
'reboot' => (-e "/var/run/need_reboot") || "0",
'failure' => $failure || "0" );'reboot' => ("$pakfire_status{'RebootRequired'}" eq "yes") || "0",
Okay.
@@ -333,32 +336,26 @@ END exit; }
-my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`; -chomp($core_release); -my $core_update_age = &General::age("/opt/pakfire/db/core/mine"); -my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db"); -my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db"); -my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db");
&Header::openbox("100%", "center", "Pakfire");
print <<END;
<table id="pfmain"> END -if ( -e "/var/run/need_reboot") { +if ("$pakfire_status{'RebootRequired'}" eq "yes") { print "\t\t<tr><td colspan='2'><a href='/cgi-bin/shutdown.cgi'>$Lang::tr{'needreboot'}!</a></td></tr>\n"; } + print <<END; <tr><td class="heading">$Lang::tr{'pakfire system state'}:</td> <td class="heading">$Lang::tr{'available updates'}:</td></tr>
<tr><td><strong>$Lang::tr{'pakfire core update level'}: $core_release</strong>
<tr><td><strong>$Lang::tr{'pakfire core update level'}: $pakfire_status{'Release'}</strong> <hr> <div class="pflist">
$Lang::tr{'pakfire last update'} $core_update_age $Lang::tr{'pakfire ago'}<br>
$Lang::tr{'pakfire last serverlist update'} $server_update_age $Lang::tr{'pakfire ago'}<br>
$Lang::tr{'pakfire last core list update'} $corelist_update_age $Lang::tr{'pakfire ago'}<br>
$Lang::tr{'pakfire last package update'} $packages_update_age $Lang::tr{'pakfire ago'}
$Lang::tr{'pakfire last update'} $pakfire_status{'LastUpdate'} $Lang::tr{'pakfire ago'}<br>
$Lang::tr{'pakfire last serverlist update'} $pakfire_status{'LastServerListUpdate'} $Lang::tr{'pakfire ago'}<br>
$Lang::tr{'pakfire last core list update'} $pakfire_status{'LastCoreListUpdate'} $Lang::tr{'pakfire ago'}<br>
$Lang::tr{'pakfire last package update'} $pakfire_status{'LastPakListUpdate'} $Lang::tr{'pakfire ago'} </div>
Is it actually useful to show those timestamps? If anything, the last update of the lists (all together) would be interesting.
I do not think that it is important to know when the last update was installed. How do you feel about this?
<form method='post' action='$ENV{'SCRIPT_NAME'}'> <input type='hidden' name='ACTION' value='update' />
@@ -370,17 +367,17 @@ print <<END; <select name="UPDPAKS" class="pflist" size="5" disabled> END
- my %coredb = &Pakfire::coredbinfo();
- if (defined $coredb{'AvailableRelease'}) {
print "<option value=\"core\">Core-Update -- $coredb{'CoreVersion'} -- Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n";
- if ("$pakfire_status{'CoreUpdateAvailable'}" eq "yes") {
}print "<option value=\"core\">Core-Update -- $pakfire_status{'CoreVersion'} -- Release: $pakfire_status{'Release'} -> $pakfire_status{'AvailableRelease'}</option>\n";
See my remarks on localisation in my other email.
- my %upgradelist = &Pakfire::dblist("upgrade");
- foreach my $pak (sort keys %upgradelist) {
print "<option value=\"$pak\">Update: $pak -- Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n";
- if ($pakfire_status{'PakUpdatesAvailable'} > 0) {
my %upgradelist = &Pakfire::dblist("upgrade");
foreach my $pak (sort keys %upgradelist) {
print "<option value=\"$pak\">Update: $pak -- Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n";
}}
- print <<END; </select> <input type='hidden' name='ACTION' value='upgrade' />
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index b35aed6a3..028a0277e 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -897,26 +897,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 b529db77a..0ed8aacd4 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -406,7 +406,18 @@ system("rm -f /etc/fcron.daily/pakfire-upgrade"); } } elsif ("$ARGV[0]" eq "status") {
&Pakfire::status;
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";
The return status was lost here. I do not know why we would always return 1, but I would say that it makes sense to indicate whether updates are available or all is good.
} else { &Pakfire::usage; } -- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Hi
Michael Tremer schreef op ma 21-03-2022 om 16:28 [+0000]:
Hey,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- removed UI related code from status function and refactor it
to returning hash representing pakfire status.
- Add UI part to pakfire script
- Use pakfire status function in pakfire.cgi, removing duplicate
code
Signed-off-by: Robin Roevens robin.roevens@disroot.org
html/cgi-bin/pakfire.cgi | 39 ++++++++++++++++-----------------
src/pakfire/lib/functions.pl | 40 ++++++++++++++++++---------------
src/pakfire/pakfire | 13 +++++++++++- 3 files changed, 50 insertions(+), 42 deletions(-)
diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index 30a23128b..d62b6058f 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -37,6 +37,9 @@ my %color = (); my %pakfiresettings = (); my %mainsettings = ();
+# Get Pakfire status +my %pakfire_status = &Pakfire::status();
# Load general settings &General::readhash("${General::swroot}/main/settings", %mainsettings); &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colo rs.txt", %color); @@ -66,7 +69,7 @@ if($cgiparams{'ACTION'} eq 'json-getstatus') { my %status = ( 'running' => &_is_pakfire_busy() || "0", 'running_since' => &General::age("$Pakfire::lockfile") || "0s", - 'reboot' => (-e "/var/run/need_reboot") || "0", + 'reboot' => ("$pakfire_status{'RebootRequired'}" eq "yes") || "0", 'failure' => $failure || "0" );
Okay.
@@ -333,32 +336,26 @@ END exit; }
-my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`; -chomp($core_release); -my $core_update_age = &General::age("/opt/pakfire/db/core/mine"); -my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db"); -my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db"); -my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db");
&Header::openbox("100%", "center", "Pakfire");
print <<END; <table id="pfmain"> END -if ( -e "/var/run/need_reboot") { +if ("$pakfire_status{'RebootRequired'}" eq "yes") { print "\t\t<tr><td colspan='2'><a href='/cgi- bin/shutdown.cgi'>$Lang::tr{'needreboot'}!</a></td></tr>\n"; }
print <<END; <tr><td class="heading">$Lang::tr{'pakfire system state'}:</td> <td class="heading">$Lang::tr{'available updates'}:</td></tr>
- <tr><td><strong>$Lang::tr{'pakfire core update level'}: $core_release</strong> + <tr><td><strong>$Lang::tr{'pakfire core update level'}: $pakfire_status{'Release'}</strong> <hr> <div class="pflist"> - $Lang::tr{'pakfire last update'} $core_update_age $Lang::tr{'pakfire ago'}<br> - $Lang::tr{'pakfire last serverlist update'} $server_update_age $Lang::tr{'pakfire ago'}<br> - $Lang::tr{'pakfire last core list update'} $corelist_update_age $Lang::tr{'pakfire ago'}<br> - $Lang::tr{'pakfire last package update'} $packages_update_age $Lang::tr{'pakfire ago'} + $Lang::tr{'pakfire last update'} $pakfire_status{'LastUpdate'} $Lang::tr{'pakfire ago'}<br> + $Lang::tr{'pakfire last serverlist update'} $pakfire_status{'LastServerListUpdate'} $Lang::tr{'pakfire ago'}<br> + $Lang::tr{'pakfire last core list update'} $pakfire_status{'LastCoreListUpdate'} $Lang::tr{'pakfire ago'}<br> + $Lang::tr{'pakfire last package update'} $pakfire_status{'LastPakListUpdate'} $Lang::tr{'pakfire ago'} </div>
Is it actually useful to show those timestamps? If anything, the last update of the lists (all together) would be interesting.
I do not think that it is important to know when the last update was installed. How do you feel about this?
I gave the current pakfire wui a good long stare.. and indeed I have to conclude that there is not much added value to show these. Last lists update is indeed the only timestamp that is interesting as there is also a button to refresh them now. But as I already plan to overhaul that page completely, I will integrate the removal of all those timestamps there.
<form method='post' action='$ENV{'SCRIPT_NAME'}'> <input type='hidden' name='ACTION' value='update' /> @@ -370,17 +367,17 @@ print <<END; <select name="UPDPAKS" class="pflist" size="5" disabled> END
- my %coredb = &Pakfire::coredbinfo(); - if (defined $coredb{'AvailableRelease'}) { - print "<option value="core">Core-Update -- $coredb{'CoreVersion'} -- Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n"; + if ("$pakfire_status{'CoreUpdateAvailable'}" eq "yes") { + print "<option value="core">Core-Update -- $pakfire_status{'CoreVersion'} -- Release: $pakfire_status{'Release'} -> $pakfire_status{'AvailableRelease'}</option>\n"; }
See my remarks on localisation in my other email.
Noted, will change it.
- my %upgradelist = &Pakfire::dblist("upgrade"); - foreach my $pak (sort keys %upgradelist) { - print "<option value="$pak">Update: $pak -- Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n"; + if ($pakfire_status{'PakUpdatesAvailable'} > 0) { + my %upgradelist = &Pakfire::dblist("upgrade"); + foreach my $pak (sort keys %upgradelist) { + print "<option value="$pak">Update: $pak -- Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n"; + } }
print <<END; </select> <input type='hidden' name='ACTION' value='upgrade' /> diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index b35aed6a3..028a0277e 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -897,26 +897,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 b529db77a..0ed8aacd4 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -406,7 +406,18 @@ system("rm -f /etc/fcron.daily/pakfire- upgrade"); } } elsif ("$ARGV[0]" eq "status") { - &Pakfire::status; + 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";
The return status was lost here. I do not know why we would always return 1, but I would say that it makes sense to indicate whether updates are available or all is good.
Indeed, I missed the return value.. Will add one.
Regards
Robin
} else { &Pakfire::usage; } -- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Hello,
On 23 Mar 2022, at 19:56, Robin Roevens robin.roevens@disroot.org wrote:
Hi
Michael Tremer schreef op ma 21-03-2022 om 16:28 [+0000]:
Hey,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- removed UI related code from status function and refactor it
to returning hash representing pakfire status.
- Add UI part to pakfire script
- Use pakfire status function in pakfire.cgi, removing duplicate
code
Signed-off-by: Robin Roevens robin.roevens@disroot.org
html/cgi-bin/pakfire.cgi | 39 ++++++++++++++++-----------------
src/pakfire/lib/functions.pl | 40 ++++++++++++++++++---------------
src/pakfire/pakfire | 13 +++++++++++- 3 files changed, 50 insertions(+), 42 deletions(-)
diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index 30a23128b..d62b6058f 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -37,6 +37,9 @@ my %color = (); my %pakfiresettings = (); my %mainsettings = ();
+# Get Pakfire status +my %pakfire_status = &Pakfire::status();
# Load general settings &General::readhash("${General::swroot}/main/settings", %mainsettings); &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colo rs.txt", %color); @@ -66,7 +69,7 @@ if($cgiparams{'ACTION'} eq 'json-getstatus') { my %status = ( 'running' => &_is_pakfire_busy() || "0", 'running_since' => &General::age("$Pakfire::lockfile") || "0s",
- 'reboot' => (-e "/var/run/need_reboot") || "0",
- 'reboot' => ("$pakfire_status{'RebootRequired'}" eq
"yes") || "0", 'failure' => $failure || "0" );
Okay.
@@ -333,32 +336,26 @@ END exit; }
-my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`; -chomp($core_release); -my $core_update_age = &General::age("/opt/pakfire/db/core/mine"); -my $corelist_update_age = &General::age("/opt/pakfire/db/lists/core-list.db"); -my $server_update_age = &General::age("/opt/pakfire/db/lists/server-list.db"); -my $packages_update_age = &General::age("/opt/pakfire/db/lists/packages_list.db");
&Header::openbox("100%", "center", "Pakfire");
print <<END;
<table id="pfmain"> END -if ( -e "/var/run/need_reboot") { +if ("$pakfire_status{'RebootRequired'}" eq "yes") { print "\t\t<tr><td colspan='2'><a href='/cgi- bin/shutdown.cgi'>$Lang::tr{'needreboot'}!</a></td></tr>\n"; } + print <<END; <tr><td class="heading">$Lang::tr{'pakfire system state'}:</td> <td class="heading">$Lang::tr{'available updates'}:</td></tr>
<tr><td><strong>$Lang::tr{'pakfire core update
level'}: $core_release</strong>
<tr><td><strong>$Lang::tr{'pakfire core update
level'}: $pakfire_status{'Release'}</strong>
<hr> <div class="pflist"> - $Lang::tr{'pakfire last update'} $core_update_age $Lang::tr{'pakfire ago'}<br> - $Lang::tr{'pakfire last serverlist update'} $server_update_age $Lang::tr{'pakfire ago'}<br> - $Lang::tr{'pakfire last core list update'} $corelist_update_age $Lang::tr{'pakfire ago'}<br> - $Lang::tr{'pakfire last package update'} $packages_update_age $Lang::tr{'pakfire ago'} + $Lang::tr{'pakfire last update'} $pakfire_status{'LastUpdate'} $Lang::tr{'pakfire ago'}<br> + $Lang::tr{'pakfire last serverlist update'} $pakfire_status{'LastServerListUpdate'} $Lang::tr{'pakfire ago'}<br> + $Lang::tr{'pakfire last core list update'} $pakfire_status{'LastCoreListUpdate'} $Lang::tr{'pakfire ago'}<br> + $Lang::tr{'pakfire last package update'} $pakfire_status{'LastPakListUpdate'} $Lang::tr{'pakfire ago'} </div>
Is it actually useful to show those timestamps? If anything, the last update of the lists (all together) would be interesting.
I do not think that it is important to know when the last update was installed. How do you feel about this?
I gave the current pakfire wui a good long stare.. and indeed I have to conclude that there is not much added value to show these. Last lists update is indeed the only timestamp that is interesting as there is also a button to refresh them now. But as I already plan to overhaul that page completely, I will integrate the removal of all those timestamps there.
Let’s talk about that plan before you start coding.
<form method='post' action='$ENV{'SCRIPT_NAME'}'> <input type='hidden' name='ACTION' value='update' /> @@ -370,17 +367,17 @@ print <<END; <select name="UPDPAKS" class="pflist" size="5" disabled> END
- my %coredb = &Pakfire::coredbinfo();
- if (defined $coredb{'AvailableRelease'}) {
- print "<option value="core">Core-Update --
$coredb{'CoreVersion'} -- Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n";
- if ("$pakfire_status{'CoreUpdateAvailable'}" eq "yes") {
- print "<option value="core">Core-Update --
$pakfire_status{'CoreVersion'} -- Release: $pakfire_status{'Release'} -> $pakfire_status{'AvailableRelease'}</option>\n"; }
See my remarks on localisation in my other email.
Noted, will change it.
- my %upgradelist = &Pakfire::dblist("upgrade");
- foreach my $pak (sort keys %upgradelist) {
- print "<option value="$pak">Update: $pak --
Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n";
- if ($pakfire_status{'PakUpdatesAvailable'} > 0) {
- my %upgradelist = &Pakfire::dblist("upgrade");
- foreach my $pak (sort keys %upgradelist) {
- print "<option value="$pak">Update: $pak
-- Version: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- Release: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n";
- }
}
print <<END;
</select> <input type='hidden' name='ACTION' value='upgrade' /> diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index b35aed6a3..028a0277e 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -897,26 +897,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 b529db77a..0ed8aacd4 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -406,7 +406,18 @@ system("rm -f /etc/fcron.daily/pakfire- upgrade"); } } elsif ("$ARGV[0]" eq "status") {
- &Pakfire::status;
- 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";
The return status was lost here. I do not know why we would always return 1, but I would say that it makes sense to indicate whether updates are available or all is good.
Indeed, I missed the return value.. Will add one.
Regards
Robin
} else { &Pakfire::usage; } -- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
- Added new getmetadata function for easy access to all available metadata of a pak without knowledge about or need to parse pakfire internal db files. - Added new 'pakfire info' functionality for displaying all available metadata of (a) pak(s) to the user, using the new getmetadata. - Use getmetadata function in services.cgi to determine installed addon services to display. Removing code duplication and intel that should only be known by pakfire itself.
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- html/cgi-bin/services.cgi | 81 ++++++++++++++++++------------------ src/pakfire/lib/functions.pl | 55 ++++++++++++++++++++++++ src/pakfire/pakfire | 58 ++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 40 deletions(-)
diff --git a/html/cgi-bin/services.cgi b/html/cgi-bin/services.cgi index 237475735..896c95ec3 100644 --- a/html/cgi-bin/services.cgi +++ b/html/cgi-bin/services.cgi @@ -29,6 +29,7 @@ require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; require "${General::swroot}/graphs.pl"; +require "/opt/pakfire/lib/functions.pl";
my %color = (); my %mainsettings = (); @@ -160,51 +161,51 @@ END
my $lines=0; # Used to count the outputlines to make different bgcolor
- # Generate list of installed addon pak's - opendir (DIR, "/opt/pakfire/db/installed") || die "Cannot opendir /opt/pakfire/db/installed/: $!"; - my @pak = sort readdir DIR; - closedir(DIR); - - foreach (@pak){ - chomp($_); - next unless (m/^meta-/); - s/^meta-//; - - # Check which of the paks are services - if (-e "/etc/init.d/$_") { - # blacklist some packages - # - # alsa has trouble with the volume saving and was not really stopped - # mdadm should not stopped with webif because this could crash the system - # - if ( $_ eq 'squid' ) { - next; - } - if ( ($_ ne "alsa") && ($_ ne "mdadm") ) { - $lines++; - if ($lines % 2){ - print "<tr>"; - $col="bgcolor='$color{'color22'}'"; - }else{ - print "<tr>"; - $col="bgcolor='$color{'color20'}'"; - } + my @paks; + my @addon_services;
- print "<td align='left' $col width='31%'>$_</td> "; - my $status = isautorun($_,$col); - print "$status "; - print "<td align='center' $col width='8%'><a href='services.cgi?$_!start'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>"; - print "<td align='center' $col width='8%'><a href='services.cgi?$_!stop'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go-down.png' border='0' /></a></td> "; - my $status = &isrunningaddon($_,$col); - $status =~ s/\[[0-1];[0-9]+m//g; - - chomp($status); - print "$status"; - print "</tr>"; + # Generate list of installed addon pak services + my %paklist = &Pakfire::dblist("installed"); + + foreach my $pak (keys %paklist) { + my %metadata = &Pakfire::getmetadata($pak, "installed"); + + if ("$metadata{'Services'}") { + foreach my $service (split(/ /, "$metadata{'Services'}")) { + push(@addon_services, $service); } } }
+ foreach (@addon_services) { + $lines++; + if ($lines % 2){ + print "<tr>"; + $col="bgcolor='$color{'color22'}'"; + }else{ + print "<tr>"; + $col="bgcolor='$color{'color20'}'"; + } + print "<td align='left' $col width='31%'>$_</td> "; + my $status = isautorun($_,$col); + print "$status "; + # Don't allow user to start/stop folowing services from webui: + # - alsa has trouble with the volume saving and was not really stopped + if ($_ eq "alsa") { + print "<td align='center' $col width='8%'></td>"; + print "<td align='center' $col width='8%'></td> "; + } else { + print "<td align='center' $col width='8%'><a href='services.cgi?$_!start'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>"; + print "<td align='center' $col width='8%'><a href='services.cgi?$_!stop'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go-down.png' border='0' /></a></td> "; + } + my $status = isrunningaddon($_,$col); + $status =~ s/\[[0-1];[0-9]+m//g; + + chomp($status); + print "$status"; + print "</tr>"; + } + print "</table></div>\n"; &Header::closebox();
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 028a0277e..6dda8d688 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -115,6 +115,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> [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks."); + &Pakfire::message(" <info> <pak> [<pak> ...] - Output pak metadata."); &Pakfire::message(" <status> - Outputs a summary about available core upgrades, updates and a required reboot"); &Pakfire::message(""); &Pakfire::message(" Global options:"); @@ -674,6 +675,60 @@ sub parsemetafile { return %metadata; }
+sub getmetadata { + ### This subroutine returns a hash of available info for a package + # Pass package name and type of info as argument: Pakfire::getmetadata(package, type_of_info) + # Type_of_info can be "latest" or "installed" + # Usage is always with two argument. + my ($pak, $type) = @_; + + my %metadata = ( + Name => $pak, + Installed => "no", + Available => "no"); + my %installed_metadata = (); + + my @templine; + my @file; + + ### Get available version information + if ("$type" eq "latest") { + ### Check if package is in packages_list and get latest available version + my %db = Pakfire::dblist("all"); + + if (defined $db{$pak}) { + ### Get and parse latest available metadata + if (getmetafile("$pak")) { + %metadata = parsemetafile("$Conf::dbdir/meta/meta-$pak"); + + $metadata{'Available'} = "yes"; + ### Rename version info fields + $metadata{'AvailableProgVersion'} = delete $metadata{'ProgVersion'}; + $metadata{'AvailableRelease'} = delete $metadata{'Release'}; + } + } + } + + ### Parse installed pak metadata + if (&isinstalled($pak) == 0) { + %installed_metadata = parsemetafile("$Conf::dbdir/installed/meta-$pak"); + + if ("$type" eq "latest" && exists($metadata{'AvailableProgVersion'})) { + ### Add installed version info to latest metadata + $metadata{'ProgVersion'} = $installed_metadata{'ProgVersion'}; + $metadata{'Release'} = $installed_metadata{'Release'}; + } else { + ### Use metadata of installed pak + %metadata = %installed_metadata; + } + $metadata{'Installed'} = 'yes'; + } else { + $metadata{'Installed'} = 'no'; + } + + return %metadata; +} + sub decryptpak { my $pak = shift;
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 0ed8aacd4..9935481a5 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -387,6 +387,64 @@ } else { &Pakfire::message("PAKFIRE WARN: No packages where found using filter $filter."); } + } elsif ("$ARGV[0]" eq "info") { + shift; + + my @paks; + my $pak; + foreach $pak (@ARGV) { + unless ("$pak" =~ "^-") { + push(@paks,$pak); + } + } + + unless ("@paks") { + Pakfire::message("PAKFIRE ERROR: missing package name"); + Pakfire::usage; + exit 1; + } + + foreach $pak (@paks) { + my %metadata = Pakfire::getmetadata($pak, "latest"); + + ### Check if pakfile was actually found + if ($metadata{'Installed'} eq "no" && $metadata{'Available'} eq "no") { + Pakfire::message("PAKFIRE WARN: Pak '$pak' not found."); + last; + } + + unless (defined $metadata{'Available'}) { + Pakfire::message("PAKFIRE WARN: Unable to retrieve latest metadata for $pak. Information may be outdated.") + } + + ### Printout metadata in a user friendly format + print "Name: $metadata{'Name'}\n"; + print "Summary: $metadata{'Summary'}\n"; + if ($metadata{'Available'} eq "yes") { + print "Version: $metadata{'AvailableProgVersion'}-$metadata{'AvailableRelease'}\n"; + } else { + print "Version: $metadata{'ProgVersion'}-$metadata{'Release'}\n"; + } + print "Size: " . Pakfire::beautifysize("$metadata{'Size'}") . "\n"; + print "Dependencies: $metadata{'Dependencies'}\n"; + print "Pakfile: $metadata{'File'}\n"; + print "Service InitScripts: $metadata{'Services'}\n"; + print "Installed: $metadata{'Installed'}\n"; + ### Generate a pak status message + if (! defined $metadata{'Available'}) { + print "Status: unknown (an error occured retrieving latest pak metadata)"; + } elsif ($metadata{'Available'} eq "no") { + print "Status: obsolete (version $metadata{'ProgVersion'}-$metadata{'Release'} is installed)\n"; + } elsif ($metadata{'Installed'} eq "yes" && "$metadata{'Release'}" < "$metadata{'AvailableRelease'}") { + print "Status: outdated (version $metadata{'ProgVersion'}-$metadata{'Release'} is installed)\n"; + } elsif ($metadata{'Installed'} eq "yes") { + print "Status: up-to-date\n"; + } else { + print "Status: not installed\n"; + } + print "\n"; + } + } elsif ("$ARGV[0]" eq "resolvedeps") { foreach (@ARGV) { next if ("$_" eq "resolvedeps");
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- Added new getmetadata function for easy access to all available
metadata of a pak without knowledge about or need to parse pakfire internal db files.
- Added new 'pakfire info' functionality for displaying all available
metadata of (a) pak(s) to the user, using the new getmetadata.
- Use getmetadata function in services.cgi to determine installed
addon services to display. Removing code duplication and intel that should only be known by pakfire itself.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
html/cgi-bin/services.cgi | 81 ++++++++++++++++++------------------ src/pakfire/lib/functions.pl | 55 ++++++++++++++++++++++++ src/pakfire/pakfire | 58 ++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 40 deletions(-)
diff --git a/html/cgi-bin/services.cgi b/html/cgi-bin/services.cgi index 237475735..896c95ec3 100644 --- a/html/cgi-bin/services.cgi +++ b/html/cgi-bin/services.cgi @@ -29,6 +29,7 @@ require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; require "${General::swroot}/graphs.pl"; +require "/opt/pakfire/lib/functions.pl";
my %color = (); my %mainsettings = (); @@ -160,51 +161,51 @@ END
my $lines=0; # Used to count the outputlines to make different bgcolor
- # Generate list of installed addon pak's
- opendir (DIR, "/opt/pakfire/db/installed") || die "Cannot opendir /opt/pakfire/db/installed/: $!";
- my @pak = sort readdir DIR;
- closedir(DIR);
- foreach (@pak){
chomp($_);
next unless (m/^meta-/);
s/^meta-//;
# Check which of the paks are services
if (-e "/etc/init.d/$_") {
# blacklist some packages
#
# alsa has trouble with the volume saving and was not really stopped
# mdadm should not stopped with webif because this could crash the system
#
if ( $_ eq 'squid' ) {
next;
}
if ( ($_ ne "alsa") && ($_ ne "mdadm") ) {
$lines++;
if ($lines % 2){
print "<tr>";
$col="bgcolor='$color{'color22'}'";
}else{
print "<tr>";
$col="bgcolor='$color{'color20'}'";
}
- my @paks;
- my @addon_services;
print "<td align='left' $col width='31%'>$_</td> ";
my $status = isautorun($_,$col);
print "$status ";
print "<td align='center' $col width='8%'><a href='services.cgi?$_!start'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>";
print "<td align='center' $col width='8%'><a href='services.cgi?$_!stop'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go-down.png' border='0' /></a></td> ";
my $status = &isrunningaddon($_,$col);
$status =~ s/\\[[0-1]\;[0-9]+m//g;
chomp($status);
print "$status";
print "</tr>";
# Generate list of installed addon pak services
my %paklist = &Pakfire::dblist("installed");
foreach my $pak (keys %paklist) {
my %metadata = &Pakfire::getmetadata($pak, "installed");
if ("$metadata{'Services'}") {
foreach my $service (split(/ /, "$metadata{'Services'}")) {
push(@addon_services, $service); }
} }
foreach (@addon_services) {
$lines++;
if ($lines % 2){
print "<tr>";
$col="bgcolor='$color{'color22'}'";
}else{
print "<tr>";
$col="bgcolor='$color{'color20'}'";
}
print "<td align='left' $col width='31%'>$_</td> ";
my $status = isautorun($_,$col);
print "$status ";
# Don't allow user to start/stop folowing services from webui:
# - alsa has trouble with the volume saving and was not really stopped
if ($_ eq "alsa") {
print "<td align='center' $col width='8%'></td>";
print "<td align='center' $col width='8%'></td> ";
Is this still a problem? Why do we even catch this here?
} else {
print "<td align='center' $col width='8%'><a href='services.cgi?$_!start'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>";
print "<td align='center' $col width='8%'><a href='services.cgi?$_!stop'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go-down.png' border='0' /></a></td> ";
}
my $status = isrunningaddon($_,$col);
$status =~ s/\\[[0-1]\;[0-9]+m//g;
chomp($status);
print "$status";
print "</tr>";
- }
- print "</table></div>\n"; &Header::closebox();
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 028a0277e..6dda8d688 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -115,6 +115,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> [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks.");
- &Pakfire::message(" <info> <pak> [<pak> ...] - Output pak metadata."); &Pakfire::message(" <status> - Outputs a summary about available core upgrades, updates and a required reboot"); &Pakfire::message(""); &Pakfire::message(" Global options:");
@@ -674,6 +675,60 @@ sub parsemetafile { return %metadata; }
+sub getmetadata {
- ### This subroutine returns a hash of available info for a package
- # Pass package name and type of info as argument: Pakfire::getmetadata(package, type_of_info)
- # Type_of_info can be "latest" or "installed"
- # Usage is always with two argument.
- my ($pak, $type) = @_;
- my %metadata = (
Name => $pak,
Installed => "no",
Available => "no");
- my %installed_metadata = ();
- my @templine;
- my @file;
- ### Get available version information
- if ("$type" eq "latest") {
### Check if package is in packages_list and get latest available version
my %db = Pakfire::dblist("all");
if (defined $db{$pak}) {
### Get and parse latest available metadata
if (getmetafile("$pak")) {
%metadata = parsemetafile("$Conf::dbdir/meta/meta-$pak");
$metadata{'Available'} = "yes";
### Rename version info fields
$metadata{'AvailableProgVersion'} = delete $metadata{'ProgVersion'};
$metadata{'AvailableRelease'} = delete $metadata{'Release'};
Why is the delete necessary?
}
}
- }
- ### Parse installed pak metadata
- if (&isinstalled($pak) == 0) {
%installed_metadata = parsemetafile("$Conf::dbdir/installed/meta-$pak");
if ("$type" eq "latest" && exists($metadata{'AvailableProgVersion'})) {
### Add installed version info to latest metadata
$metadata{'ProgVersion'} = $installed_metadata{'ProgVersion'};
$metadata{'Release'} = $installed_metadata{'Release'};
} else {
### Use metadata of installed pak
%metadata = %installed_metadata;
}
$metadata{'Installed'} = 'yes';
- } else {
$metadata{'Installed'} = 'no';
- }
- return %metadata;
+}
sub decryptpak { my $pak = shift;
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 0ed8aacd4..9935481a5 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -387,6 +387,64 @@ } else { &Pakfire::message("PAKFIRE WARN: No packages where found using filter $filter."); }
- } elsif ("$ARGV[0]" eq "info") {
shift;
my @paks;
my $pak;
foreach $pak (@ARGV) {
unless ("$pak" =~ "^-") {
push(@paks,$pak);
}
}
unless ("@paks") {
Pakfire::message("PAKFIRE ERROR: missing package name");
Pakfire::usage;
exit 1;
}
foreach $pak (@paks) {
my %metadata = Pakfire::getmetadata($pak, "latest");
### Check if pakfile was actually found
if ($metadata{'Installed'} eq "no" && $metadata{'Available'} eq "no") {
Pakfire::message("PAKFIRE WARN: Pak '$pak' not found.");
last;
}
unless (defined $metadata{'Available'}) {
Pakfire::message("PAKFIRE WARN: Unable to retrieve latest metadata for $pak. Information may be outdated.")
}
### Printout metadata in a user friendly format
print "Name: $metadata{'Name'}\n";
print "Summary: $metadata{'Summary'}\n";
if ($metadata{'Available'} eq "yes") {
print "Version: $metadata{'AvailableProgVersion'}-$metadata{'AvailableRelease'}\n";
} else {
print "Version: $metadata{'ProgVersion'}-$metadata{'Release'}\n";
}
print "Size: " . Pakfire::beautifysize("$metadata{'Size'}") . "\n";
print "Dependencies: $metadata{'Dependencies'}\n";
print "Pakfile: $metadata{'File'}\n";
print "Service InitScripts: $metadata{'Services'}\n";
print "Installed: $metadata{'Installed'}\n";
### Generate a pak status message
if (! defined $metadata{'Available'}) {
print "Status: unknown (an error occured retrieving latest pak metadata)";
} elsif ($metadata{'Available'} eq "no") {
print "Status: obsolete (version $metadata{'ProgVersion'}-$metadata{'Release'} is installed)\n";
} elsif ($metadata{'Installed'} eq "yes" && "$metadata{'Release'}" < "$metadata{'AvailableRelease'}") {
print "Status: outdated (version $metadata{'ProgVersion'}-$metadata{'Release'} is installed)\n";
} elsif ($metadata{'Installed'} eq "yes") {
print "Status: up-to-date\n";
} else {
print "Status: not installed\n";
}
print "\n";
}
- } elsif ("$ARGV[0]" eq "resolvedeps") { foreach (@ARGV) { next if ("$_" eq "resolvedeps");
This looks very good.
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Michael Tremer schreef op ma 21-03-2022 om 16:32 [+0000]:
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- Added new getmetadata function for easy access to all available
metadata of a pak without knowledge about or need to parse pakfire internal db files.
- Added new 'pakfire info' functionality for displaying all
available metadata of (a) pak(s) to the user, using the new getmetadata.
- Use getmetadata function in services.cgi to determine installed
addon services to display. Removing code duplication and intel that should only be known by pakfire itself.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
html/cgi-bin/services.cgi | 81 ++++++++++++++++++---------------
src/pakfire/lib/functions.pl | 55 ++++++++++++++++++++++++ src/pakfire/pakfire | 58 ++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 40 deletions(-)
diff --git a/html/cgi-bin/services.cgi b/html/cgi-bin/services.cgi index 237475735..896c95ec3 100644 --- a/html/cgi-bin/services.cgi +++ b/html/cgi-bin/services.cgi @@ -29,6 +29,7 @@ require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; require "${General::swroot}/graphs.pl"; +require "/opt/pakfire/lib/functions.pl";
my %color = (); my %mainsettings = (); @@ -160,51 +161,51 @@ END
my $lines=0; # Used to count the outputlines to make different bgcolor
- # Generate list of installed addon pak's - opendir (DIR, "/opt/pakfire/db/installed") || die "Cannot opendir /opt/pakfire/db/installed/: $!"; - my @pak = sort readdir DIR; - closedir(DIR);
- foreach (@pak){ - chomp($_); - next unless (m/^meta-/); - s/^meta-//;
- # Check which of the paks are services - if (-e "/etc/init.d/$_") { - # blacklist some packages - # - # alsa has trouble with the volume saving and was not really stopped - # mdadm should not stopped with webif because this could crash the system - # - if ( $_ eq 'squid' ) { - next; - } - if ( ($_ ne "alsa") && ($_ ne "mdadm") ) { - $lines++; - if ($lines % 2){ - print "<tr>";
$col="bgcolor='$color{'color2 2'}'"; - }else{ - print "<tr>";
$col="bgcolor='$color{'color2 0'}'"; - } + my @paks; + my @addon_services;
- print "<td align='left' $col width='31%'>$_</td> "; - my $status = isautorun($_,$col); - print "$status "; - print "<td align='center' $col width='8%'><a href='services.cgi?$_!start'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>"; - print "<td align='center' $col width='8%'><a href='services.cgi?$_!stop'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go- down.png' border='0' /></a></td> "; - my $status = &isrunningaddon($_,$col); - $status =~ s/\[[0-1];[0-9]+m//g;
- chomp($status); - print "$status"; - print "</tr>"; + # Generate list of installed addon pak services + my %paklist = &Pakfire::dblist("installed");
+ foreach my $pak (keys %paklist) { + my %metadata = &Pakfire::getmetadata($pak, "installed"); + + if ("$metadata{'Services'}") { + foreach my $service (split(/ /, "$metadata{'Services'}")) { + push(@addon_services, $service); } } }
+ foreach (@addon_services) { + $lines++; + if ($lines % 2){ + print "<tr>"; + $col="bgcolor='$color{'color22'}'"; + }else{ + print "<tr>"; + $col="bgcolor='$color{'color20'}'"; + } + print "<td align='left' $col width='31%'>$_</td> "; + my $status = isautorun($_,$col); + print "$status "; + # Don't allow user to start/stop folowing services from webui: + # - alsa has trouble with the volume saving and was not really stopped + if ($_ eq "alsa") { + print "<td align='center' $col width='8%'></td>"; + print "<td align='center' $col width='8%'></td> ";
Is this still a problem? Why do we even catch this here?
Not sure.. Never tested it. I will try to set up a test env with a sound card .. not sure if I will succeed. never started a vm with sound here before .. So if someone else can test this more easily ?
+ } else { + print "<td align='center' $col width='8%'><a href='services.cgi?$_!start'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>"; + print "<td align='center' $col width='8%'><a href='services.cgi?$_!stop'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go- down.png' border='0' /></a></td> "; + } + my $status = isrunningaddon($_,$col); + $status =~ s/\[[0-1];[0-9]+m//g;
+ chomp($status); + print "$status"; + print "</tr>"; + }
print "</table></div>\n"; &Header::closebox();
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 028a0277e..6dda8d688 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -115,6 +115,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> [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks."); + &Pakfire::message(" <info> <pak> [<pak> ...] - Output pak metadata."); &Pakfire::message(" <status> - Outputs a summary about available core upgrades, updates and a required reboot"); &Pakfire::message(""); &Pakfire::message(" Global options:"); @@ -674,6 +675,60 @@ sub parsemetafile { return %metadata; }
+sub getmetadata { + ### This subroutine returns a hash of available info for a package + # Pass package name and type of info as argument: Pakfire::getmetadata(package, type_of_info) + # Type_of_info can be "latest" or "installed" + # Usage is always with two argument. + my ($pak, $type) = @_;
+ my %metadata = ( + Name => $pak, + Installed => "no", + Available => "no"); + my %installed_metadata = ();
+ my @templine; + my @file;
+ ### Get available version information + if ("$type" eq "latest") { + ### Check if package is in packages_list and get latest available version + my %db = Pakfire::dblist("all"); + + if (defined $db{$pak}) { + ### Get and parse latest available metadata + if (getmetafile("$pak")) { + %metadata = parsemetafile("$Conf::dbdir/meta/meta-$pak");
+ $metadata{'Available'} = "yes"; + ### Rename version info fields + $metadata{'AvailableProgVersion'} = delete $metadata{'ProgVersion'}; + $metadata{'AvailableRelease'} = delete $metadata{'Release'};
Why is the delete necessary?
This is actually a rename of the key from 'ProgVersion' to 'AvailableProgVersion'; delete removes the key from the hash, and returns its value, which is added to the hash as the new key 'Available...'. If I would remove the delete, the same info would be in the hash, once in 'ProgVersion' and once in 'AvailableProgVersion'. And in case the pak is not installed, it would be returned as such from this function; while existence of 'ProgVersion'/'Release' sort of implicates that the pak is installed. (Checks should be based on 'Installed' = yes/no but it could lead to confusion to keep them)
+ } + } + } + + ### Parse installed pak metadata + if (&isinstalled($pak) == 0) { + %installed_metadata = parsemetafile("$Conf::dbdir/installed/meta-$pak");
+ if ("$type" eq "latest" && exists($metadata{'AvailableProgVersion'})) { + ### Add installed version info to latest metadata + $metadata{'ProgVersion'} = $installed_metadata{'ProgVersion'}; + $metadata{'Release'} = $installed_metadata{'Release'}; + } else { + ### Use metadata of installed pak + %metadata = %installed_metadata; + } + $metadata{'Installed'} = 'yes'; + } else { + $metadata{'Installed'} = 'no'; + }
+ return %metadata; +}
sub decryptpak { my $pak = shift;
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 0ed8aacd4..9935481a5 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -387,6 +387,64 @@ } else { &Pakfire::message("PAKFIRE WARN: No packages where found using filter $filter."); } + } elsif ("$ARGV[0]" eq "info") { + shift;
+ my @paks; + my $pak; + foreach $pak (@ARGV) { + unless ("$pak" =~ "^-") { + push(@paks,$pak); + } + }
+ unless ("@paks") { + Pakfire::message("PAKFIRE ERROR: missing package name"); + Pakfire::usage; + exit 1; + }
+ foreach $pak (@paks) { + my %metadata = Pakfire::getmetadata($pak, "latest");
+ ### Check if pakfile was actually found + if ($metadata{'Installed'} eq "no" && $metadata{'Available'} eq "no") { + Pakfire::message("PAKFIRE WARN: Pak '$pak' not found."); + last; + }
+ unless (defined $metadata{'Available'}) { + Pakfire::message("PAKFIRE WARN: Unable to retrieve latest metadata for $pak. Information may be outdated.") + }
+ ### Printout metadata in a user friendly format + print "Name: $metadata{'Name'}\n"; + print "Summary: $metadata{'Summary'}\n"; + if ($metadata{'Available'} eq "yes") { + print "Version: $metadata{'AvailableProgVersion'}-$metadata{'AvailableRelease'}\n"; + } else { + print "Version: $metadata{'ProgVersion'}-$metadata{'Release'}\n"; + } + print "Size: " . Pakfire::beautifysize("$metadata{'Size'}") . "\n"; + print "Dependencies: $metadata{'Dependencies'}\n"; + print "Pakfile: $metadata{'File'}\n"; + print "Service InitScripts: $metadata{'Services'}\n"; + print "Installed: $metadata{'Installed'}\n"; + ### Generate a pak status message + if (! defined $metadata{'Available'}) { + print "Status: unknown (an error occured retrieving latest pak metadata)"; + } elsif ($metadata{'Available'} eq "no") { + print "Status: obsolete (version $metadata{'ProgVersion'}-$metadata{'Release'} is installed)\n"; + } elsif ($metadata{'Installed'} eq "yes" && "$metadata{'Release'}" < "$metadata{'AvailableRelease'}") { + print "Status: outdated (version $metadata{'ProgVersion'}-$metadata{'Release'} is installed)\n"; + } elsif ($metadata{'Installed'} eq "yes") { + print "Status: up-to-date\n"; + } else { + print "Status: not installed\n"; + } + print "\n"; + }
} elsif ("$ARGV[0]" eq "resolvedeps") { foreach (@ARGV) { next if ("$_" eq "resolvedeps");
This looks very good.
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Hey,
On 22 Mar 2022, at 13:28, Robin Roevens robin.roevens@disroot.org wrote:
Michael Tremer schreef op ma 21-03-2022 om 16:32 [+0000]:
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- Added new getmetadata function for easy access to all available
metadata of a pak without knowledge about or need to parse pakfire internal db files.
- Added new 'pakfire info' functionality for displaying all
available metadata of (a) pak(s) to the user, using the new getmetadata.
- Use getmetadata function in services.cgi to determine installed
addon services to display. Removing code duplication and intel that should only be known by pakfire itself.
Signed-off-by: Robin Roevens robin.roevens@disroot.org
html/cgi-bin/services.cgi | 81 ++++++++++++++++++---------------
src/pakfire/lib/functions.pl | 55 ++++++++++++++++++++++++ src/pakfire/pakfire | 58 ++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 40 deletions(-)
diff --git a/html/cgi-bin/services.cgi b/html/cgi-bin/services.cgi index 237475735..896c95ec3 100644 --- a/html/cgi-bin/services.cgi +++ b/html/cgi-bin/services.cgi @@ -29,6 +29,7 @@ require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; require "${General::swroot}/graphs.pl"; +require "/opt/pakfire/lib/functions.pl";
my %color = (); my %mainsettings = (); @@ -160,51 +161,51 @@ END
my $lines=0; # Used to count the outputlines to make
different bgcolor
# Generate list of installed addon pak's
opendir (DIR, "/opt/pakfire/db/installed") || die "Cannot
opendir /opt/pakfire/db/installed/: $!";
my @pak = sort readdir DIR;
closedir(DIR);
foreach (@pak){
chomp($_);
next unless (m/^meta-/);
s/^meta-//;
# Check which of the paks are services
if (-e "/etc/init.d/$_") {
# blacklist some packages
#
# alsa has trouble with the volume saving
and was not really stopped
# mdadm should not stopped with webif
because this could crash the system
#
if ( $_ eq 'squid' ) {
next;
}
if ( ($_ ne "alsa") && ($_ ne "mdadm") ) {
$lines++;
if ($lines % 2){
print "<tr>";
$col="bgcolor='$color{'color2
2'}'";
}else{
print "<tr>";
$col="bgcolor='$color{'color2
0'}'";
}
my @paks;
my @addon_services;
print "<td align='left' $col
width='31%'>$_</td> ";
my $status = isautorun($_,$col);
print "$status ";
print "<td align='center' $col
width='8%'><a href='services.cgi?$_!start'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>";
print "<td align='center' $col
width='8%'><a href='services.cgi?$_!stop'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go- down.png' border='0' /></a></td> ";
my $status =
&isrunningaddon($_,$col);
$status =~ s/\\[[0-1]\;[0-9]+m//g;
chomp($status);
print "$status";
print "</tr>";
# Generate list of installed addon pak services
my %paklist = &Pakfire::dblist("installed");
foreach my $pak (keys %paklist) {
my %metadata = &Pakfire::getmetadata($pak,
"installed");
if ("$metadata{'Services'}") {
foreach my $service (split(/ /,
"$metadata{'Services'}")) {
push(@addon_services, $service); } } }
foreach (@addon_services) {
$lines++;
if ($lines % 2){
print "<tr>";
$col="bgcolor='$color{'color22'}'";
}else{
print "<tr>";
$col="bgcolor='$color{'color20'}'";
}
print "<td align='left' $col width='31%'>$_</td> ";
my $status = isautorun($_,$col);
print "$status ";
# Don't allow user to start/stop folowing services
from webui:
# - alsa has trouble with the volume saving and
was not really stopped
if ($_ eq "alsa") {
print "<td align='center' $col
width='8%'></td>";
print "<td align='center' $col
width='8%'></td> ";
Is this still a problem? Why do we even catch this here?
Not sure.. Never tested it. I will try to set up a test env with a sound card .. not sure if I will succeed. never started a vm with sound here before .. So if someone else can test this more easily ?
VMs can easily emulate sound hardware, but I wouldn’t even bother here. This should just work and if it doesn’t that should be caught in the initscript and not in some random CGI file.
} else {
print "<td align='center' $col
width='8%'><a href='services.cgi?$_!start'><img alt='$Lang::tr{'start'}' title='$Lang::tr{'start'}' src='/images/go-up.png' border='0' /></a></td>";
print "<td align='center' $col
width='8%'><a href='services.cgi?$_!stop'><img alt='$Lang::tr{'stop'}' title='$Lang::tr{'stop'}' src='/images/go- down.png' border='0' /></a></td> ";
}
my $status = isrunningaddon($_,$col);
$status =~ s/\\[[0-1]\;[0-9]+m//g;
chomp($status);
print "$status";
print "</tr>";
}
print "</table></div>\n"; &Header::closebox();
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 028a0277e..6dda8d688 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -115,6 +115,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> [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks.");
- &Pakfire::message(" <info> <pak> [<pak> ...] -
Output pak metadata."); &Pakfire::message(" <status> - Outputs a summary about available core upgrades, updates and a required reboot"); &Pakfire::message(""); &Pakfire::message(" Global options:"); @@ -674,6 +675,60 @@ sub parsemetafile { return %metadata; }
+sub getmetadata {
### This subroutine returns a hash of available info for a
package
# Pass package name and type of info as argument:
Pakfire::getmetadata(package, type_of_info)
# Type_of_info can be "latest" or "installed"
# Usage is always with two argument.
my ($pak, $type) = @_;
my %metadata = (
Name => $pak,
Installed => "no",
Available => "no");
my %installed_metadata = ();
my @templine;
my @file;
### Get available version information
if ("$type" eq "latest") {
### Check if package is in packages_list and get
latest available version
my %db = Pakfire::dblist("all");
if (defined $db{$pak}) {
### Get and parse latest available metadata
if (getmetafile("$pak")) {
%metadata =
parsemetafile("$Conf::dbdir/meta/meta-$pak");
$metadata{'Available'} = "yes";
### Rename version info fields
$metadata{'AvailableProgVersion'} =
delete $metadata{'ProgVersion'};
$metadata{'AvailableRelease'} =
delete $metadata{'Release'};
Why is the delete necessary?
This is actually a rename of the key from 'ProgVersion' to 'AvailableProgVersion'; delete removes the key from the hash, and returns its value, which is added to the hash as the new key 'Available...'. If I would remove the delete, the same info would be in the hash, once in 'ProgVersion' and once in 'AvailableProgVersion'. And in case the pak is not installed, it would be returned as such from this function; while existence of 'ProgVersion'/'Release' sort of implicates that the pak is installed. (Checks should be based on 'Installed' = yes/no but it could lead to confusion to keep them)
Hmm, okay.
}
}
}
### Parse installed pak metadata
if (&isinstalled($pak) == 0) {
%installed_metadata =
parsemetafile("$Conf::dbdir/installed/meta-$pak");
if ("$type" eq "latest" &&
exists($metadata{'AvailableProgVersion'})) {
### Add installed version info to latest
metadata
$metadata{'ProgVersion'} =
$installed_metadata{'ProgVersion'};
$metadata{'Release'} =
$installed_metadata{'Release'};
} else {
### Use metadata of installed pak
%metadata = %installed_metadata;
}
$metadata{'Installed'} = 'yes';
} else {
$metadata{'Installed'} = 'no';
}
return %metadata;
+}
sub decryptpak { my $pak = shift;
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 0ed8aacd4..9935481a5 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -387,6 +387,64 @@ } else { &Pakfire::message("PAKFIRE WARN: No packages where found using filter $filter."); }
} elsif ("$ARGV[0]" eq "info") {
shift;
my @paks;
my $pak;
foreach $pak (@ARGV) {
unless ("$pak" =~ "^-") {
push(@paks,$pak);
}
}
unless ("@paks") {
Pakfire::message("PAKFIRE ERROR: missing
package name");
Pakfire::usage;
exit 1;
}
foreach $pak (@paks) {
my %metadata = Pakfire::getmetadata($pak,
"latest");
### Check if pakfile was actually found
if ($metadata{'Installed'} eq "no" &&
$metadata{'Available'} eq "no") {
Pakfire::message("PAKFIRE WARN: Pak
'$pak' not found.");
last;
}
unless (defined $metadata{'Available'}) {
Pakfire::message("PAKFIRE WARN:
Unable to retrieve latest metadata for $pak. Information may be outdated.")
}
### Printout metadata in a user friendly
format
print "Name: $metadata{'Name'}\n";
print "Summary: $metadata{'Summary'}\n";
if ($metadata{'Available'} eq "yes") {
print "Version:
$metadata{'AvailableProgVersion'}-$metadata{'AvailableRelease'}\n";
} else {
print "Version:
$metadata{'ProgVersion'}-$metadata{'Release'}\n";
}
print "Size: " .
Pakfire::beautifysize("$metadata{'Size'}") . "\n";
print "Dependencies:
$metadata{'Dependencies'}\n";
print "Pakfile: $metadata{'File'}\n";
print "Service InitScripts:
$metadata{'Services'}\n";
print "Installed:
$metadata{'Installed'}\n";
### Generate a pak status message
if (! defined $metadata{'Available'}) {
print "Status: unknown (an error
occured retrieving latest pak metadata)";
} elsif ($metadata{'Available'} eq "no") {
print "Status: obsolete (version
$metadata{'ProgVersion'}-$metadata{'Release'} is installed)\n";
} elsif ($metadata{'Installed'} eq "yes" &&
"$metadata{'Release'}" < "$metadata{'AvailableRelease'}") {
print "Status: outdated (version
$metadata{'ProgVersion'}-$metadata{'Release'} is installed)\n";
} elsif ($metadata{'Installed'} eq "yes") {
print "Status: up-to-date\n";
} else {
print "Status: not installed\n";
}
print "\n";
}
} elsif ("$ARGV[0]" eq "resolvedeps") { foreach (@ARGV) { next if ("$_" eq "resolvedeps");
This looks very good.
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
- Revamped 'pakfire update' more in the style of 'pakfire install' for a more consistent look and feel. - Add core update details to output - Add new dependencies to install to output - First collect all upgrade info, then perform core update together with available package updates and after user confirmation (without -y).
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- src/pakfire/pakfire | 79 +++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 28 deletions(-)
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 9935481a5..0a144c517 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -258,51 +258,76 @@ &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::message("CORE INFO: Checking for Core updates..."); - ### Make sure that the core db is not outdated. &Pakfire::getcoredb("noforce"); - my %coredb = &Pakfire::coredbinfo();
- if (defined $coredb{'AvailableRelease'}) { - &Pakfire::upgradecore(); - } else { - &Pakfire::message("CORE WARN: No new Core upgrades available. You are on release ".$coredb{'Release'}); - } + my %coredb = &Pakfire::coredbinfo(); + &Pakfire::message("CORE WARN: No new Core upgrades available. You are on release ".$coredb{'Release'}) unless (defined $coredb{'AvailableRelease'});
&Pakfire::message("PAKFIRE INFO: Checking for package updates..."); ### Make sure that the package list is not outdated. &Pakfire::dbgetlist("noforce"); my @deps = (); - if (my %upgradepaks = &Pakfire::dblist("upgrade")) { - # Resolve the dependencies of the to be upgraded packages - @deps = &Pakfire::resolvedeps_recursive(keys %upgradepaks); + my %upgradepaks = &Pakfire::dblist("upgrade");
- 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"; - } + # Resolve the dependencies of the to be upgraded packages + @deps = &Pakfire::resolvedeps_recursive(keys %upgradepaks) if (%upgradepaks); + &Pakfire::message("PAKFIRE WARN: No new package upgrades available.") unless (@deps); + + if (defined $coredb{'AvailableRelease'} || %upgradepaks) { + &Pakfire::message(""); &Pakfire::message(""); - &Pakfire::message("PAKFIRE UPGR: We are going to install all packages listed above."); + &Pakfire::message("PAKFIRE INFO: Upgrade summary:"); + &Pakfire::message(""); + + if (defined $coredb{'AvailableRelease'}) { + &Pakfire::message("CORE INFO: Core-Update $coredb{'CoreVersion'} to install:"); + &Pakfire::message("CORE UPGR: Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}"); + &Pakfire::message(""); + } + + if (@deps) { + &Pakfire::message("PAKFIRE INFO: New dependencies to install:"); + my $totalsize = 0; + foreach $pak (@deps) { + unless (defined $upgradepaks{$pak} || &Pakfire::isinstalled($pak) == 0) { + my $size = &Pakfire::getsize("$pak"); + $totalsize += $size; + $size = &Pakfire::beautifysize($size); + &Pakfire::message("PAKFIRE INFO: $pak \t - $size"); + } + } + $totalsize = &Pakfire::beautifysize($totalsize); + &Pakfire::message(""); + &Pakfire::message("PAKFIRE INFO: Total size: \t ~ $totalsize"); + &Pakfire::message(""); + } + + if (%upgradepaks) { + &Pakfire::message("PAKFIRE INFO: Packages to upgrade:"); + foreach $pak (sort keys %upgradepaks) { + &Pakfire::message("PAKFIRE UPGR: $pak\t$upgradepaks{$pak}{'ProgVersion'}-$upgradepaks{$pak}{'Release'} -> $upgradepaks{$pak}{'AvailableProgVersion'}-$upgradepaks{$pak}{'AvailableRelease'}"); + } + &Pakfire::message(""); + } + if ($interactive) { - &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]"); + &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]"); my $ret = <STDIN>; chomp($ret); &Pakfire::logger("PAKFIRE INFO: Answer: $ret"); if ( $ret ne "y" ) { - &Pakfire::message("PAKFIRE ERROR: Installation aborted."); - exit 1; + &Pakfire::message("PAKFIRE ERROR: Installation aborted."); + exit 1; } } + + # Perform core update + if (defined $coredb{'AvailableRelease'}) { + &Pakfire::upgradecore(); + } # Download packages foreach $pak (sort keys %upgradepaks) { @@ -323,8 +348,6 @@ foreach $pak (sort keys %upgradepaks) { &Pakfire::upgradepak("$pak"); } - } else { - &Pakfire::message("PAKFIRE WARN: No new package upgrades available."); }
} elsif ("$ARGV[0]" eq "list") {
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- Revamped 'pakfire update' more in the style of 'pakfire
install' for a more consistent look and feel.
- Add core update details to output
- Add new dependencies to install to output
- First collect all upgrade info, then perform core update
together with available package updates and after user confirmation (without -y).
I am sorry to disappoint Tom, but this is quite likely a no-can-do.
The problem is that we are repeatedly tight on disk space which makes downloading everything first a bit of a problem.
We do not have any mechanism that checks whether enough space for either the downloads or for extracting the update is available, which is why the old way was more of a step-by-step system.
I don’t like the old system at all, but I would propose to add a function that checks if enough disk space is available before it asks the user whether they want to continue.
That should consider:
* The download size of the updates * The download size of all add-ons * The extracted size (for simplicity probably assuming that the core update is only adding new files) * The extracted size of all add-ons
Then, we can even drop some last checks in the update scripts that aborted the update process if disk space was running low.
How does that sound?
-Michael
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/pakfire | 79 +++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 28 deletions(-)
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 9935481a5..0a144c517 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -258,51 +258,76 @@ &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::message("CORE INFO: Checking for Core updates...");
### Make sure that the core db is not outdated. &Pakfire::getcoredb("noforce");
my %coredb = &Pakfire::coredbinfo();
if (defined $coredb{'AvailableRelease'}) {
&Pakfire::upgradecore();
} else {
&Pakfire::message("CORE WARN: No new Core upgrades available. You are on release ".$coredb{'Release'});
}
my %coredb = &Pakfire::coredbinfo();
&Pakfire::message("CORE WARN: No new Core upgrades available. You are on release ".$coredb{'Release'}) unless (defined $coredb{'AvailableRelease'});
&Pakfire::message("PAKFIRE INFO: Checking for package updates..."); ### Make sure that the package list is not outdated. &Pakfire::dbgetlist("noforce");
my @deps = ();
if (my %upgradepaks = &Pakfire::dblist("upgrade")) {
# Resolve the dependencies of the to be upgraded packages
@deps = &Pakfire::resolvedeps_recursive(keys %upgradepaks);
my %upgradepaks = &Pakfire::dblist("upgrade");
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";
}
# Resolve the dependencies of the to be upgraded packages
@deps = &Pakfire::resolvedeps_recursive(keys %upgradepaks) if (%upgradepaks);
&Pakfire::message("PAKFIRE WARN: No new package upgrades available.") unless (@deps);
if (defined $coredb{'AvailableRelease'} || %upgradepaks) {
&Pakfire::message(""); &Pakfire::message("");
&Pakfire::message("PAKFIRE UPGR: We are going to install all packages listed above.");
&Pakfire::message("PAKFIRE INFO: Upgrade summary:");
&Pakfire::message("");
if (defined $coredb{'AvailableRelease'}) {
&Pakfire::message("CORE INFO: Core-Update $coredb{'CoreVersion'} to install:");
&Pakfire::message("CORE UPGR: Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}");
&Pakfire::message("");
}
if (@deps) {
&Pakfire::message("PAKFIRE INFO: New dependencies to install:");
my $totalsize = 0;
foreach $pak (@deps) {
unless (defined $upgradepaks{$pak} || &Pakfire::isinstalled($pak) == 0) {
my $size = &Pakfire::getsize("$pak");
$totalsize += $size;
$size = &Pakfire::beautifysize($size);
&Pakfire::message("PAKFIRE INFO: $pak \t - $size");
}
}
$totalsize = &Pakfire::beautifysize($totalsize);
&Pakfire::message("");
&Pakfire::message("PAKFIRE INFO: Total size: \t ~ $totalsize");
&Pakfire::message("");
}
if (%upgradepaks) {
&Pakfire::message("PAKFIRE INFO: Packages to upgrade:");
foreach $pak (sort keys %upgradepaks) {
&Pakfire::message("PAKFIRE UPGR: $pak\t$upgradepaks{$pak}{'ProgVersion'}-$upgradepaks{$pak}{'Release'} -> $upgradepaks{$pak}{'AvailableProgVersion'}-$upgradepaks{$pak}{'AvailableRelease'}");
}
&Pakfire::message("");
}
if ($interactive) {
&Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]");
&Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]"); my $ret = <STDIN>; chomp($ret); &Pakfire::logger("PAKFIRE INFO: Answer: $ret"); if ( $ret ne "y" ) {
&Pakfire::message("PAKFIRE ERROR: Installation aborted.");
exit 1;
&Pakfire::message("PAKFIRE ERROR: Installation aborted.");
exit 1; } }
# Perform core update
if (defined $coredb{'AvailableRelease'}) {
&Pakfire::upgradecore();
} # Download packages foreach $pak (sort keys %upgradepaks) {
@@ -323,8 +348,6 @@ foreach $pak (sort keys %upgradepaks) { &Pakfire::upgradepak("$pak"); }
} else {
&Pakfire::message("PAKFIRE WARN: No new package upgrades available.");
}
} elsif ("$ARGV[0]" eq "list") {
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Michael Tremer schreef op ma 21-03-2022 om 16:36 [+0000]:
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- Revamped 'pakfire update' more in the style of 'pakfire
install' for a more consistent look and feel.
- Add core update details to output
- Add new dependencies to install to output
- First collect all upgrade info, then perform core update
together with available package updates and after user confirmation (without -y).
I am sorry to disappoint Tom, but this is quite likely a no-can-do.
The problem is that we are repeatedly tight on disk space which makes downloading everything first a bit of a problem.
I'm not sure what you mean? Originally the upgrade function forced a core upgrade first, then retrieved info about pak updates and requested confirmation to install them. I changed this into first retrieving all pak and core update info (not the paks or core themselves), presenting the info to the user and asking confirmation. After that the core is downloaded and installed, then the paks are downloaded and installed. So in terms of disk space usage, nothing should have changed except that pak metadata is now downloaded before the core update is performed. But those few text files should not be the problem I assume?
We do not have any mechanism that checks whether enough space for either the downloads or for extracting the update is available, which is why the old way was more of a step-by-step system.
I don’t like the old system at all, but I would propose to add a function that checks if enough disk space is available before it asks the user whether they want to continue.
That should consider:
- The download size of the updates
- The download size of all add-ons
- The extracted size (for simplicity probably assuming that the core
update is only adding new files)
- The extracted size of all add-ons
Great minds think alike, I suppose :-) I was already in the middle of trying to implement size checking. But I didn't want the current patchset submission to be postponed for that. (The last patch was already some kind of 'extra' and not really that related to the purpose of that patchset (the cleanup of dblist and using extra metadata))
I already did want to check some things about the size calculation here on the mailing list, but I figured that this patchset should first need to be accepted, as the size calculation would depend on it.
But now that we are on this topic.. I wanted to verify here if the size recorded in the meta-files, is the size of the tar-files? And since everything is tarred without compression (or so I think?) this should more or less be equal to the installed size ? Or am I mistaken? If we ever decide to actually compress those we will need to record uncompressed size in the metadata.
Then for calculation, I was thinking about separating temporary space and installed space: * core update: -- Required tempspace: size of new core (tar-file) -- required installspace: size of new core * new dependencies: -- required tempspace: sum of size of all required deps (tar files) -- required installspace: sum of size of all required deps * pak updates: -- required tempspace: sum of size of all required paks (tar files) -- required installspace: for each pak: size of installed pak version - size of new pak version
in the end total required space is tempspace + installspace, if installspace is positive. It can in theory also be negative (no core update and size of updated paks is less than previous versions), then required space = tempspace.. I'm not sure if downloaded pakfiles/core-updates are deleted after install..? Or after some time ? I did not immediately find it in the code. We could implement some cache pruning ('pakfire clear' or 'pakfire clear-cache' or so?)
this size diff at least for pak updates should be quite accurate, as previous pak is uninstalled and new pak is installed during update.
I have been trying to calculate the actual size of a core update.. but only just now I figured that a core update file is probably not a full ipfire fs, but only the diff in files against previous core update :-) For the actual size of a core update, we would need to have a diff of the size of a clean ipfire on previous core and a clean ipfire on next core.. But I don't think that is data we have already available or could easily have available ? So assuming core update only adds files is probably indeed the safest straight-forward method. Other method could be to assume a percentage of new files-size in a core update..?
Robin
Then, we can even drop some last checks in the update scripts that aborted the update process if disk space was running low.
How does that sound?
-Michael
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/pakfire | 79 +++++++++++++++++++++++++++++-------------
1 file changed, 51 insertions(+), 28 deletions(-)
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 9935481a5..0a144c517 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -258,51 +258,76 @@ &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::message("CORE INFO: Checking for Core updates...");
### Make sure that the core db is not outdated. &Pakfire::getcoredb("noforce"); - my %coredb = &Pakfire::coredbinfo();
- if (defined $coredb{'AvailableRelease'}) { - &Pakfire::upgradecore(); - } else { - &Pakfire::message("CORE WARN: No new Core upgrades available. You are on release ".$coredb{'Release'}); - } + my %coredb = &Pakfire::coredbinfo(); + &Pakfire::message("CORE WARN: No new Core upgrades available. You are on release ".$coredb{'Release'}) unless (defined $coredb{'AvailableRelease'});
&Pakfire::message("PAKFIRE INFO: Checking for package updates..."); ### Make sure that the package list is not outdated. &Pakfire::dbgetlist("noforce"); my @deps = (); - if (my %upgradepaks = &Pakfire::dblist("upgrade")) { - # Resolve the dependencies of the to be upgraded packages - @deps = &Pakfire::resolvedeps_recursive(keys %upgradepaks); + my %upgradepaks = &Pakfire::dblist("upgrade");
- 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"; - } + # Resolve the dependencies of the to be upgraded packages + @deps = &Pakfire::resolvedeps_recursive(keys %upgradepaks) if (%upgradepaks); + &Pakfire::message("PAKFIRE WARN: No new package upgrades available.") unless (@deps);
+ if (defined $coredb{'AvailableRelease'} || %upgradepaks) { + &Pakfire::message(""); &Pakfire::message(""); - &Pakfire::message("PAKFIRE UPGR: We are going to install all packages listed above."); + &Pakfire::message("PAKFIRE INFO: Upgrade summary:"); + &Pakfire::message("");
+ if (defined $coredb{'AvailableRelease'}) { + &Pakfire::message("CORE INFO: Core- Update $coredb{'CoreVersion'} to install:"); + &Pakfire::message("CORE UPGR: Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}"); + &Pakfire::message(""); + }
+ if (@deps) { + &Pakfire::message("PAKFIRE INFO: New dependencies to install:"); + my $totalsize = 0; + foreach $pak (@deps) { + unless (defined $upgradepaks{$pak} || &Pakfire::isinstalled($pak) == 0) { + my $size = &Pakfire::getsize("$pak"); + $totalsize += $size; + $size = &Pakfire::beautifysize($size); + &Pakfire::message(" PAKFIRE INFO: $pak \t - $size"); + } + } + $totalsize = &Pakfire::beautifysize($totalsize); + &Pakfire::message(""); + &Pakfire::message("PAKFIRE INFO: Total size: \t ~ $totalsize"); + &Pakfire::message(""); + }
+ if (%upgradepaks) { + &Pakfire::message("PAKFIRE INFO: Packages to upgrade:"); + foreach $pak (sort keys %upgradepaks) { + &Pakfire::message("PAKFIRE UPGR: $pak\t$upgradepaks{$pak}{'ProgVersion'}- $upgradepaks{$pak}{'Release'} -> $upgradepaks{$pak}{'AvailableProgVersion'}- $upgradepaks{$pak}{'AvailableRelease'}"); + } + &Pakfire::message(""); + }
if ($interactive) { - &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]"); + &Pakfire::message("PAKFIRE INFO: Is this okay? [y/N]"); my $ret = <STDIN>; chomp($ret); &Pakfire::logger("PAKFIRE INFO: Answer: $ret");need if ( $ret ne "y" ) { - &Pakfire::message("PAKFIRE ERROR: Installation aborted."); - exit 1; + &Pakfire::message("PAKFIRE ERROR: Installation aborted."); + exit 1; } }
+ # Perform core update + if (defined $coredb{'AvailableRelease'}) { + &Pakfire::upgradecore(); + } # Download packages foreach $pak (sort keys %upgradepaks) { @@ -323,8 +348,6 @@ foreach $pak (sort keys %upgradepaks) { &Pakfire::upgradepak("$pak"); } - } else { - &Pakfire::message("PAKFIRE WARN: No new package upgrades available."); }
} elsif ("$ARGV[0]" eq "list") {
2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
Hello,
On 22 Mar 2022, at 18:32, Robin Roevens robin.roevens@disroot.org wrote:
Michael Tremer schreef op ma 21-03-2022 om 16:36 [+0000]:
Hello,
On 9 Mar 2022, at 22:56, Robin Roevens robin.roevens@disroot.org wrote:
- Revamped 'pakfire update' more in the style of 'pakfire
install' for a more consistent look and feel.
- Add core update details to output
- Add new dependencies to install to output
- First collect all upgrade info, then perform core update
together with available package updates and after user confirmation (without -y).
I am sorry to disappoint Tom, but this is quite likely a no-can-do.
The problem is that we are repeatedly tight on disk space which makes downloading everything first a bit of a problem.
I'm not sure what you mean? Originally the upgrade function forced a core upgrade first, then retrieved info about pak updates and requested confirmation to install them. I changed this into first retrieving all pak and core update info (not the paks or core themselves), presenting the info to the user and asking confirmation. After that the core is downloaded and installed, then the paks are downloaded and installed. So in terms of disk space usage, nothing should have changed except that pak metadata is now downloaded before the core update is performed. But those few text files should not be the problem I assume?
Oh okay. I read this differently then. The text files do not matter when it comes to disk space, but:
We sometimes change the tree in a core update (2.27 -> 2.29 or something), which this will break. Pakfire will then not find the correct new packages. The meta data needs to be updated after the core update is being installed and then pakfire can decide what packages to install. Otherwise this would become a two-step update now.
We do not have any mechanism that checks whether enough space for either the downloads or for extracting the update is available, which is why the old way was more of a step-by-step system.
I don’t like the old system at all, but I would propose to add a function that checks if enough disk space is available before it asks the user whether they want to continue.
That should consider:
- The download size of the updates
- The download size of all add-ons
- The extracted size (for simplicity probably assuming that the core
update is only adding new files)
- The extracted size of all add-ons
Great minds think alike, I suppose :-) I was already in the middle of trying to implement size checking. But I didn't want the current patchset submission to be postponed for that. (The last patch was already some kind of 'extra' and not really that related to the purpose of that patchset (the cleanup of dblist and using extra metadata))
Yes, we should approach things one by one.
I have a massive work load at the moment and so reviewing large changes becomes a little bit difficult for me.
I already did want to check some things about the size calculation here on the mailing list, but I figured that this patchset should first need to be accepted, as the size calculation would depend on it.
We can think about it and decide to implement it later...
But now that we are on this topic.. I wanted to verify here if the size recorded in the meta-files, is the size of the tar-files?
This is the download size.
And since everything is tarred without compression (or so I think?) this should more or less be equal to the installed size ? Or am I mistaken?
No, we compress the data. There are two tarballs inside each other.
The outer tarball has the scripts and the payload and is not compressed. The payload is compressed using XZ.
If we ever decide to actually compress those we will need to record uncompressed size in the metadata.
So, the download size is usually quite far away from the installed size.
ms@rice-oxley ~ % curl https://mirror1.ipfire.org/pakfire2/2.27/paks/samba-4.14.6-82.ipfire | gpg --decrypt | tar xO files.tar.xz | xz -d | wc -c % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11.4M 100 11.4M 0 0 11.5M 0 --:--:-- --:--:-- --:--:-- 11.8M gpg: Signature made Tue 21 Dec 11:21:18 2021 GMT gpg: using RSA key 3ECA8AA4478208B924BB96206FEF7A8ED713594B gpg: Can't check signature: No public key 67164160
Samba is about 64MiB extracted (as tar) and 11 MiB downloaded.
We would have to add this to the metadata so that you can use the installed size in your calculations.
Then for calculation, I was thinking about separating temporary space and installed space:
- core update:
-- Required tempspace: size of new core (tar-file) -- required installspace: size of new core
Agreed.
- new dependencies:
-- required tempspace: sum of size of all required deps (tar files) -- required installspace: sum of size of all required deps
Agreed.
- pak updates:
-- required tempspace: sum of size of all required paks (tar files) -- required installspace: for each pak: size of installed pak version - size of new pak version
Technically you are correct. I am just unsure how much margin of error we should add to this.
in the end total required space is tempspace + installspace, if installspace is positive. It can in theory also be negative (no core update and size of updated paks is less than previous versions), then required space = tempspace..
True. Again, rather be safe than sorry.
I'm not sure if downloaded pakfiles/core-updates are deleted after install..? Or after some time ? I did not immediately find it in the code. We could implement some cache pruning ('pakfire clear' or 'pakfire clear-cache' or so?)
Update.sh removes the downloaded core update before it starts extracting everything. So technically, it is on disk multiple times:
1) the downloaded file in /var/cache/pakfire 2) The extracted download file in /opt/pakfire/tmp 3) Then we extract the payload
Worst case is that we need the downloaded space twice + the installed size.
Pruning the cache is a bit difficult. Pakfire does not store the uninstall script which means that we need the package file when we uninstall a package.
That is why we usually leave everything in the cache. An extra command would be helpful and pakfire should ideally delete the downloaded core update as soon as it got extracted (before calling update.sh).
OMG this is complicated :)
this size diff at least for pak updates should be quite accurate, as previous pak is uninstalled and new pak is installed during update.
Any opened files will still remain on disk. Sometimes we replace things while they are running which won’t free disk space immediately.
That is why I am suggestion some margin of error here of maybe 20%? I wouldn’t calculate this to the last byte.
I have been trying to calculate the actual size of a core update.. but only just now I figured that a core update file is probably not a full ipfire fs, but only the diff in files against previous core update :-)
Yes it is.
For the actual size of a core update, we would need to have a diff of the size of a clean ipfire on previous core and a clean ipfire on next core..
I would just assume that all files are new files and will need extra space.
We can’t easily compute the diff here.
But I don't think that is data we have already available or could easily have available ? So assuming core update only adds files is probably indeed the safest straight-forward method. Other method could be to assume a percentage of new files-size in a core update..?
We could, but what would that be? Sometimes we might extract 100M and only replace existing stuff. The we might add a new kernel which will 100M of modules on its own. I don’t think there is an easy formula. However, many systems have a / partition of only 2G. We need to be able to install updates to those systems cannot overshoot too much and hope for a gigabyte of space that we can use.
My gut tells me that maybe taking the install size of the core update by 3/4 might be a good number?
-Michael
Robin
Then, we can even drop some last checks in the update scripts that aborted the update process if disk space was running low.
How does that sound?
-Michael
Signed-off-by: Robin Roevens robin.roevens@disroot.org
src/pakfire/pakfire | 79 +++++++++++++++++++++++++++++-------------
1 file changed, 51 insertions(+), 28 deletions(-)
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 9935481a5..0a144c517 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -258,51 +258,76 @@ &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::message("CORE INFO: Checking for Core
updates...");
### Make sure that the core db is not outdated. &Pakfire::getcoredb("noforce");
my %coredb = &Pakfire::coredbinfo();
if (defined $coredb{'AvailableRelease'}) {
&Pakfire::upgradecore();
} else {
&Pakfire::message("CORE WARN: No new Core
upgrades available. You are on release ".$coredb{'Release'});
}
my %coredb = &Pakfire::coredbinfo();
&Pakfire::message("CORE WARN: No new Core upgrades
available. You are on release ".$coredb{'Release'}) unless (defined $coredb{'AvailableRelease'});
&Pakfire::message("PAKFIRE INFO: Checking for
package updates..."); ### Make sure that the package list is not outdated. &Pakfire::dbgetlist("noforce");
my @deps = ();
if (my %upgradepaks = &Pakfire::dblist("upgrade"))
{
# Resolve the dependencies of the to be
upgraded packages
@deps =
&Pakfire::resolvedeps_recursive(keys %upgradepaks);
my %upgradepaks = &Pakfire::dblist("upgrade");
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";
}
# Resolve the dependencies of the to be upgraded
packages
@deps = &Pakfire::resolvedeps_recursive(keys
%upgradepaks) if (%upgradepaks);
&Pakfire::message("PAKFIRE WARN: No new package
upgrades available.") unless (@deps);
if (defined $coredb{'AvailableRelease'} ||
%upgradepaks) {
&Pakfire::message(""); &Pakfire::message("");
&Pakfire::message("PAKFIRE UPGR: We are
going to install all packages listed above.");
&Pakfire::message("PAKFIRE INFO: Upgrade
summary:");
&Pakfire::message("");
if (defined $coredb{'AvailableRelease'}) {
&Pakfire::message("CORE INFO: Core-
Update $coredb{'CoreVersion'} to install:");
&Pakfire::message("CORE UPGR:
Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}");
&Pakfire::message("");
}
if (@deps) {
&Pakfire::message("PAKFIRE INFO:
New dependencies to install:");
my $totalsize = 0;
foreach $pak (@deps) {
unless (defined
$upgradepaks{$pak} || &Pakfire::isinstalled($pak) == 0) {
my $size =
&Pakfire::getsize("$pak");
$totalsize +=
$size;
$size =
&Pakfire::beautifysize($size);
&Pakfire::message("
PAKFIRE INFO: $pak \t - $size");
}
}
$totalsize =
&Pakfire::beautifysize($totalsize);
&Pakfire::message("");
&Pakfire::message("PAKFIRE INFO:
Total size: \t ~ $totalsize");
&Pakfire::message("");
}
if (%upgradepaks) {
&Pakfire::message("PAKFIRE INFO:
Packages to upgrade:");
foreach $pak (sort keys
%upgradepaks) {
&Pakfire::message("PAKFIRE
UPGR: $pak\t$upgradepaks{$pak}{'ProgVersion'}- $upgradepaks{$pak}{'Release'} -> $upgradepaks{$pak}{'AvailableProgVersion'}- $upgradepaks{$pak}{'AvailableRelease'}");
}
&Pakfire::message("");
}
if ($interactive) {
&Pakfire::message("PAKFIRE INFO: Is this
okay? [y/N]");
&Pakfire::message("PAKFIRE INFO: Is
this okay? [y/N]"); my $ret = <STDIN>; chomp($ret); &Pakfire::logger("PAKFIRE INFO: Answer: $ret");need if ( $ret ne "y" ) {
&Pakfire::message("PAKFIRE ERROR:
Installation aborted.");
exit 1;
&Pakfire::message("PAKFIRE
ERROR: Installation aborted.");
exit 1; } }
# Perform core update
if (defined $coredb{'AvailableRelease'}) {
&Pakfire::upgradecore();
} # Download packages foreach $pak (sort keys %upgradepaks) {
@@ -323,8 +348,6 @@ foreach $pak (sort keys %upgradepaks) { &Pakfire::upgradepak("$pak"); }
} else {
&Pakfire::message("PAKFIRE WARN: No new
package upgrades available."); }
} elsif ("$ARGV[0]" eq "list") {
-- 2.34.1
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.
On 03/09/2022 5:56 PM, Robin Roevens wrote:
[snip]
Now all upgrade info is gathered first and an upgrade summary is presented to the user (more in the style of the output when a pak is installed or removed) and confirmation is requested. Only after the user confirming the upgrade the core and the paks are upgraded in one go (except ofcourse when -y is used, then no confirmation is asked).
[snip]
BRAVO!!! This behavior has always bothered me, too. Combined with the fact that "pakfire update" didn't tell you whether an update was available, it was quite frustrating, requiring a "pakfire status" to know if an update was available, first.
I also frequently ended up coming back to a console/terminal and finding a partially completed upgrade process waiting for me to press "Y".
Tom
On 3/9/22 17:46, Tom Rymes wrote:
On 03/09/2022 5:56 PM, Robin Roevens wrote:
[snip]
Now all upgrade info is gathered first and an upgrade summary is presented to the user (more in the style of the output when a pak is installed or removed) and confirmation is requested. Only after the user confirming the upgrade the core and the paks are upgraded in one go (except ofcourse when -y is used, then no confirmation is asked).
[snip]
BRAVO!!! This behavior has always bothered me, too. Combined with the fact that "pakfire update" didn't tell you whether an update was available, it was quite frustrating, requiring a "pakfire status" to know if an update was available, first.
I also frequently ended up coming back to a console/terminal and finding a partially completed upgrade process waiting for me to press "Y".
Tom
Double Plus Good.
Paul