Hi all
As promised a revision of this patchset by the end of July. Also fixing bug #12868, both in patch 01 (installed: yes/no output) and patch 06 (don't trow error on valid '--no-color' option).
This is quite a large patchset on delicate code which was discussed upon previous submission, but that was almost half a year ago. So I will try to link references to discussions on my previous submission where appropriate to refresh some memories :-).
What was changed since last submission; implementing/fixing Michael's remarks/concerns: - Patch 01: Added translations as requested here: https://lists.ipfire.org/pipermail/development/2022-March/012782.html - Patch 02: New patch translating WUI header/footer text - Patch 03: (previously patch 02) was not changed - Patch 04: (previously patch 03) replaced a forgotten fetchfile/move combo by new getmetafile function - Previous patch 04 was removed as the function coreupdate_available turned out no longer used. See: https://lists.ipfire.org/pipermail/development/2022-March/012884.html - Patch 05: Replaced seq shell command by perl seq-method, consistent use of 'Core-Update' as requested here: https://lists.ipfire.org/pipermail/development/2022-March/012787.html - Patch 06: Added exitcode to pakfire list as requested here: https://lists.ipfire.org/pipermail/development/2022-March/012787.html Also exit with error when an unknown parameter is passed to pakfire list Added a small fix (in my opinion): log termination of pakfire inside END block - Patch 07: Removed function coreupdate_available as it was concluded that it was no longer needed (see again: https://lists.ipfire.org/pipermail/development/2022-March/012884.html) Added meaningfull status exit code as remarked here: https://lists.ipfire.org/pipermail/development/2022-March/012788.html Split previous patch 07 pakfire.cgi changes in new patch 08: - Patch 08: New patch, previously part of patch 07 Fixed localization as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012788.html - Patch 09: (previously patch 08) Split previous patch 08 into patch 09 adding 'getmetadata' function and 'pakfire info' and patch 10 implementing the new 'getmetadata' in service.cgi. Show clean warning message when no packages are found with requested pakfire list filter - Patch 10: (previously part of patch 08) Removed hardcoded exclusions in services.cgi as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012789.html Previous patch 09 was dropped from this patchset as there turned out to be major problems with it and should be rethinked as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012856.html
I think I have tested this all throughly but as these are quite interusive changes to the pakfire core workings; Please do not trust my testing and test these patches yourselves during review. I would not want to carry the responibilities of breaking pakfire alone :-)
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: - Translations for 'Core-Update', 'Release', 'Update' and 'Version' - 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. (Partly fixes Bug #12868) - 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 | 23 ++++- langs/de/cgi-bin/de.pl | 4 + langs/en/cgi-bin/en.pl | 4 + langs/fr/cgi-bin/fr.pl | 4 + langs/nl/cgi-bin/nl.pl | 4 + src/pakfire/lib/functions.pl | 165 ++++++++++++++++++----------------- src/pakfire/pakfire | 99 ++++++++++++++++----- 8 files changed, 202 insertions(+), 107 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 3e8dc5460..cb1272c63 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -403,7 +403,16 @@ 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">$Lang::tr{'core update'} -- $coredb{'CoreVersion'} -- $Lang::tr{'release'}: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n"; + } + + my %upgradelist = &Pakfire::dblist("upgrade"); + foreach my $pak (sort keys %upgradelist) { + print "<option value="$pak">$Lang::tr{'pak update'}: $pak -- $Lang::tr{'version'}: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- $Lang::tr{'release'}: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n"; + } + print <<END; </select> <input type='hidden' name='ACTION' value='upgrade' /> @@ -419,7 +428,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' /> @@ -431,7 +444,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/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl index 49c582a1e..179980716 100644 --- a/langs/de/cgi-bin/de.pl +++ b/langs/de/cgi-bin/de.pl @@ -653,6 +653,7 @@ 'core notice 1' => '<strong>Hinweis:</strong> Es steht eine Aktualisierung von Core-Update', 'core notice 2' => 'auf', 'core notice 3' => 'zur Verfügung.', +'core update' => 'Core-Update', 'could not be opened' => 'konnte nicht geöffnet werden', 'could not connect to' => 'Konnte keine Verbindung herstellen mit', 'could not connect to www ipcop org' => 'Keine Verbindung zu www.ipcop.org möglich', @@ -2012,6 +2013,7 @@ 'ovpnsys log' => 'OVPN-System-Protokoll', 'package failed to install' => 'Programmpaket konnte nicht installiert werden.', 'pagerefresh' => 'Seite wird aktualisiert. Bitte warten.', +'pak update' => 'Paketupdate', 'pakfire accept all' => 'Möchten Sie der Installation aller Pakete zustimmen?', 'pakfire ago' => 'her.', 'pakfire already busy' => 'Pakfire führt bereits eine Aufgabe aus. Bitte versuchen Sie es später erneut.', @@ -2157,6 +2159,7 @@ 'refresh index page while connected' => 'Aktualisiere index.cgi Seite während der Verbindung', 'refresh update list' => 'Aktualisiere Update-Liste', 'registered user rules' => 'Talos VRT-Regelsatz für registrierte Benutzer', +'release' => 'Release', 'released' => 'Freigegeben', 'reload' => 'neu laden', 'remark' => 'Anmerkung', @@ -2868,6 +2871,7 @@ 'valid till' => 'Gültig bis', 'vci number' => 'VCI-Nummer:', 'vendor' => 'Hersteller', +'version' => 'Version', 'view log' => 'Protokoll anzeigen', 'virtual address' => 'Virtuelle Addresse', 'virtual private networking' => 'Virtuelles Privates Netzwerk', diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index ae233de8e..b51823177 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -684,6 +684,7 @@ 'core notice 1' => '<strong>Notice:</strong> There is a core-update from', 'core notice 2' => 'to', 'core notice 3' => 'available.', +'core update' => 'Core-Update', 'could not be opened' => 'could not be opened.', 'could not connect to' => 'Could not connect to', 'could not connect to www ipcop org' => 'Could not connect to www.ipfire.org', @@ -2065,6 +2066,7 @@ 'ovpnsys log' => 'OVPN-System-Log', 'package failed to install' => 'Package failed to install.', 'pagerefresh' => 'Page is beeing refreshed, please wait.', +'pak update' => 'Update', 'pakfire accept all' => 'Do you want to install all packages?', 'pakfire ago' => 'ago.', 'pakfire already busy' => 'Pakfire is already performing a task. Please try again later.', @@ -2211,6 +2213,7 @@ 'refresh index page while connected' => 'Refresh index.cgi page while connected', 'refresh update list' => 'Refresh update list', 'registered user rules' => 'Talos VRT rules for registered users', +'release' => 'Release', 'released' => 'Released', 'reload' => 'reload', 'remark' => 'Remark', @@ -2935,6 +2938,7 @@ 'valid till' => 'Valid till', 'vci number' => 'VCI number:', 'vendor' => 'Vendor', +'version' => 'Version', 'view log' => 'view log', 'virtual address' => 'Virtual Address', 'virtual private networking' => 'Virtual Private Networking', diff --git a/langs/fr/cgi-bin/fr.pl b/langs/fr/cgi-bin/fr.pl index 245ec62b6..560b4aa54 100644 --- a/langs/fr/cgi-bin/fr.pl +++ b/langs/fr/cgi-bin/fr.pl @@ -690,6 +690,7 @@ 'core notice 1' => '<strong>Remarque :</strong> Une mise à jour est disponible depuis la version', 'core notice 2' => 'vers', 'core notice 3' => '', +'core update' => 'Mise à jour du coeur', 'could not be opened' => 'ne peut pas être ouvert', 'could not connect to' => 'Impossible de se connecter à', 'could not connect to www ipcop org' => 'Impossible de se connecter à www.ipcop.org', @@ -2074,6 +2075,7 @@ 'ovpnsys log' => 'Journal système OVPN', 'package failed to install' => 'L'installation du paquet a échoué.', 'pagerefresh' => 'La page est en cours d'actualisation, veuillez patienter.', +'pak update' => 'Mise à jour', 'pakfire accept all' => 'Voulez-vous installer ce(s) paquet(s) ?', 'pakfire ago' => '', 'pakfire already busy' => 'Pakfire est déjà en train d'effectuer une tâche. Veuillez réessayer plus tard.', @@ -2221,6 +2223,7 @@ 'refresh index page while connected' => 'Actualiser la page index.cgi pendant la connexion', 'refresh update list' => 'Actualiser la liste des mises à jour', 'registered user rules' => 'Règles Sourcefire VRT pour les utilisateurs enregistrés', +'release' => 'Révision', 'released' => 'Disponible', 'reload' => 'Recharger', 'remark' => 'Remarque ', @@ -2946,6 +2949,7 @@ 'valid till' => 'Valide jusqu'au', 'vci number' => 'Nombre VCI :', 'vendor' => 'Vendeur', +'version' => 'Version', 'view log' => 'Afficher log', 'virtual address' => 'Adresse virtuelle', 'virtual private networking' => 'Réseau privé virtuel (VPN)', diff --git a/langs/nl/cgi-bin/nl.pl b/langs/nl/cgi-bin/nl.pl index 5979873bb..e50a95578 100644 --- a/langs/nl/cgi-bin/nl.pl +++ b/langs/nl/cgi-bin/nl.pl @@ -577,6 +577,7 @@ 'core notice 1' => '<strong>Let op:</strong> Er is een core-update van', 'core notice 2' => 'naar', 'core notice 3' => 'beschikbaar.', +'core update' => 'Core-Update', 'could not be opened' => 'kan niet worden geopend.', 'could not connect to' => 'Kan niet verbinden', 'could not connect to www ipcop org' => 'Kan niet verbinden met www.ipfire.org', @@ -1690,6 +1691,7 @@ 'ovpnsys log' => 'OVPN-Systeem-Log', 'package failed to install' => 'Pakket kon niet worden geïnstalleerd.', 'pagerefresh' => 'Pagina wordt ververst, wacht even a.u.b.', +'pak update' => 'Opwaardering', 'pakfire accept all' => 'Wilt u alle pakketten installeren?', 'pakfire ago' => 'geleden.', 'pakfire available addons' => 'Beschikbare extensies:', @@ -1817,6 +1819,7 @@ 'refresh index page while connected' => 'Ververs de index.cgi pagina terwijl verbonden', 'refresh update list' => 'Ververs update-lijst', 'registered user rules' => 'Talos VRT regels voor geregistreerde gebruikers', +'release' => 'Uitgave', 'released' => 'Released', 'reload' => 'herlaad', 'remark' => 'Opmerking', @@ -2484,6 +2487,7 @@ 'valid root certificate already exists' => 'Er bestaat al een geldig root certificaat.', 'valid till' => 'Geldig tot', 'vci number' => 'VCI nummer:', +'version' => 'Versie', 'view log' => 'bekijk log', 'virtual address' => 'Virtueel adres', 'virtual private networking' => 'Virtual Private Networking', diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 505988af9..19160503e 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -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"; @@ -434,108 +434,113 @@ 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": list all known paks, + # - "notinstalled": list only not installed paks, + # - "installed": list only installed paks + # - "upgrade": list only upgradable paks + # + # Returned hash format: + # ( "<pak name>" => ( + # "Installed" => "Yes" or "No" wether the pak is installed, + # "ProgVersion" => Installed program version when "Installed" => "Yes" or + # Available version when "Installed" => No, + # "Release" => Installed pak release number when "Installed" => "Yes" or + # Available pak release number when "Installed" => No, + # "AvailableProgVersion" => Available program version. + # Only defined if an upgrade to a higher version is available, + # "AvailableRelease" => Available pak release version. + # Only defined if an upgrade to a higher version is available + # ), + # ... + # ) + 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]")) { + # 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 { @@ -910,10 +915,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");
Add en/nl/fr/de translations for: - Traffic: In XXX bit/s Out XXX bit/s - IPFire X.XX (xxx) - Core Update XXX ...
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- html/html/themes/ipfire/include/functions.pl | 8 ++++---- langs/de/cgi-bin/de.pl | 3 +++ langs/en/cgi-bin/en.pl | 3 +++ langs/fr/cgi-bin/fr.pl | 3 +++ langs/nl/cgi-bin/nl.pl | 3 +++ 5 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/html/html/themes/ipfire/include/functions.pl b/html/html/themes/ipfire/include/functions.pl index cc976e812..cbd05d109 100644 --- a/html/html/themes/ipfire/include/functions.pl +++ b/html/html/themes/ipfire/include/functions.pl @@ -67,9 +67,9 @@ sub showmenu() { if ($settings{'SPEED'} ne 'off') { print <<EOF; <div id='traffic'> - <strong>Traffic:</strong> - In <span id='rx_kbs'>--.-- bit/s</span> - Out <span id='tx_kbs'>--.-- bit/s</span> + <strong>$Lang::tr{'traffic stat title'}:</strong> + $Lang::tr{'traffic stat in'} <span id='rx_kbs'>--.-- bit/s</span> + $Lang::tr{'traffic stat out'} <span id='tx_kbs'>--.-- bit/s</span> </div> EOF } @@ -202,7 +202,7 @@ sub openpagewithoutmenu { sub closepage () { open(FILE, "</etc/system-release"); my $system_release = <FILE>; - $system_release =~ s/core/Core Update /; + $system_release =~ s/core/$Lang::tr{'core update'} /; close(FILE);
print <<END; diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl index 179980716..6a5ce1117 100644 --- a/langs/de/cgi-bin/de.pl +++ b/langs/de/cgi-bin/de.pl @@ -2503,6 +2503,9 @@ 'traffic on' => 'Verkehr auf', 'traffic shaping' => 'Traffic Shaping', 'traffic shaping settings' => 'Einstellungen der Datenflußkontrolle', +'traffic stat title' => 'ROTER Traffic', +'traffic stat in' => 'Ein', +'traffic stat out' => 'Aus', 'traffic warn level bad' => 'Warnlevel ist nicht gültig', 'trafficblue' => 'WLAN', 'trafficdate' => 'Datum', diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index b51823177..73aa4d04a 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -2567,6 +2567,9 @@ 'traffic on' => 'Traffic on', 'traffic shaping' => 'Traffic Shaping', 'traffic shaping settings' => 'Traffic Shaping Settings', +'traffic stat title' => 'RED Traffic', +'traffic stat in' => 'In', +'traffic stat out' => 'Out', 'traffic warn level bad' => 'Warnlevel is not correct', 'trafficblue' => 'WLAN', 'trafficdate' => 'Date', diff --git a/langs/fr/cgi-bin/fr.pl b/langs/fr/cgi-bin/fr.pl index 560b4aa54..9e0bd3449 100644 --- a/langs/fr/cgi-bin/fr.pl +++ b/langs/fr/cgi-bin/fr.pl @@ -2579,6 +2579,9 @@ 'traffic on' => 'Trafic en cours', 'traffic shaping' => 'Arrangement du trafic', 'traffic shaping settings' => 'Réglages de l'arrangement du trafic', +'traffic stat title' => 'Trafic ROUGE', +'traffic stat in' => 'Entrée', +'traffic stat out' => 'Sortie', 'traffic warn level bad' => 'Le niveau d'alerte n'est pas correct', 'trafficblue' => 'WLAN', 'trafficdate' => 'Date', diff --git a/langs/nl/cgi-bin/nl.pl b/langs/nl/cgi-bin/nl.pl index e50a95578..7229a86ae 100644 --- a/langs/nl/cgi-bin/nl.pl +++ b/langs/nl/cgi-bin/nl.pl @@ -2131,6 +2131,9 @@ 'traffic on' => 'Verkeer op', 'traffic shaping' => 'Verkeersregeling', 'traffic shaping settings' => 'Verkeersregeling instellingen', +'traffic stat title' => 'ROOD Verkeer', +'traffic stat in' => 'In', +'traffic stat out' => 'Uit', 'traffic warn level bad' => 'Waarschuwingsniveau is onjuist', 'trafficblue' => 'WLAN', 'trafficdate' => 'Datum',
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"."); }
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 | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 19160503e..971aa2d59 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -410,9 +410,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); @@ -424,12 +422,12 @@ 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'}"); - getmetafile($metadata{'Name'}); - } + if ((defined $paklist{"$metadata{'Name'}"}) && ( + ("$paklist{"$metadata{'Name'}"}{'Release'}" ne "$metadata{'Release'}") || + (defined $paklist{"$metadata{'Name'}"}{'AvailableRelease'})) + ) { + move("$Conf::dbdir/meta/meta-$metadata{'Name'}","$Conf::dbdir/meta/old_meta-$metadata{'Name'}"); + getmetafile($metadata{'Name'}); } } }
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 971aa2d59..4f0515f62 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -773,35 +773,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 INFO: 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 = ($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..351d71216 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 INFO: No new Core-Updates 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")) {
- Added possibility to list available upgrades from commandline using 'pakfire list upgrade'. - Added exitcode to 'pakfire list' - Moved 'Pakfire has finished' log message inside END block to always log when pakfire exited. - Fix: allow [options] between 'list' and [installed/notinstalled/ upgrade] parameters (Partly fixes Bug #12868)
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- src/pakfire/lib/functions.pl | 2 +- src/pakfire/pakfire | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index 4f0515f62..d8b5c5a26 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 351d71216..766d91b81 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -329,14 +329,18 @@
} elsif ("$ARGV[0]" eq "list") { my $count; + my $coreupdate = 0; my $use_color = ""; 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]); + } elsif ($ARGV[1]) { + &Pakfire::message("PAKFIRE ERROR: Not a known option $ARGV[1]"); + exit 1; }
my $pak; @@ -347,6 +351,17 @@ $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"; + $coreupdate = 1; + } + } + foreach $pak (sort keys %paklist) { if ("$Pakfire::enable_colors" eq "1") { if ("$paklist{$pak}{'Installed'}" eq "yes") { @@ -373,7 +388,10 @@ if ($count > 0) { print "$count packages total.\n"; } else { - &Pakfire::message("PAKFIRE WARN: No packages where found using filter $filter."); + if (! $coreupdate) { + &Pakfire::message("PAKFIRE WARN: No packages where found using filter $filter."); + exit 1; + } } } elsif ("$ARGV[0]" eq "resolvedeps") { foreach (@ARGV) { @@ -399,9 +417,9 @@ &Pakfire::usage; }
- &Pakfire::logger("PAKFIRE INFO: Pakfire has finished. Closing."); - END { + &Pakfire::logger("PAKFIRE INFO: Pakfire has finished. Closing."); + # Check if pakfire has been locked in this session. if ($locked) { # Remove lockfile.
- Removed UI code from status function now returning hash with status properties. - Removed function coreupdate_available as it is now not used anymore - Added UI code to pakfire status routine - Added meaningfull exitcode to status: - 2: Core update available - 3: Pak update available - 4: Reboot required - Error codes can be added together: 2+3 = 5 means both core update and pak update is available
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- src/pakfire/lib/functions.pl | 50 +++++++++++++++--------------------- src/pakfire/pakfire | 19 +++++++++++++- 2 files changed, 38 insertions(+), 31 deletions(-)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index d8b5c5a26..f87589bc4 100644 --- a/src/pakfire/lib/functions.pl +++ b/src/pakfire/lib/functions.pl @@ -914,16 +914,6 @@ sub updates_available { return "$updatecount"; }
-sub coreupdate_available { - eval(`grep "core_" $Conf::dbdir/lists/core-list.db`); - if ("$core_release" > "$Conf::core_mine") { - return "yes ($core_release)"; - } - else { - return "no"; - } -} - sub reboot_required { if ( -e "/var/run/need_reboot" ) { return "yes"; @@ -934,26 +924,26 @@ sub reboot_required { }
sub status { - # General info - my $return = "Core-Version: $Conf::version\n"; - $return .= "Core-Update-Level: $Conf::core_mine\n"; - $return .= "Last update: " . &General::age("/opt/pakfire/db/core/mine") . " ago\n"; - $return .= "Last core-list update: " . &General::age("/opt/pakfire/db/lists/core-list.db") . " ago\n"; - $return .= "Last server-list update: " . &General::age("/opt/pakfire/db/lists/server-list.db") . " ago\n"; - $return .= "Last packages-list update: " . &General::age("/opt/pakfire/db/lists/packages_list.db") . " ago\n"; - - # Get availability of core updates - $return .= "Core-Update available: " . &Pakfire::coreupdate_available() . "\n"; - - # Get availability of package updates - $return .= "Package-Updates available: " . &Pakfire::updates_available() . "\n"; - - # Test if reboot is required - $return .= "Reboot required: " . &Pakfire::reboot_required() . "\n"; - - # Return status text - print "$return"; - exit 1; + ### This subroutine returns pakfire status information in a hash. + # Usage is without arguments + + # Add core version info + my %status = &Pakfire::coredbinfo(); + + # Add last update info + $status{'LastUpdate'} = &General::age("/opt/pakfire/db/core/mine"); + $status{'LastCoreListUpdate'} = &General::age("/opt/pakfire/db/lists/core-list.db"); + $status{'LastServerListUpdate'} = &General::age("/opt/pakfire/db/lists/server-list.db"); + $status{'LastPakListUpdate'} = &General::age("/opt/pakfire/db/lists/packages_list.db"); + + # Add number of available package updates + $status{'CoreUpdateAvailable'} = (defined $status{'AvailableRelease'}) ? "yes" : "no"; + $status{'PakUpdatesAvailable'} = &Pakfire::updates_available(); + + # Add if reboot is required + $status{'RebootRequired'} = &Pakfire::reboot_required(); + + return %status; }
sub get_arch() { diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire index 766d91b81..331204a00 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -412,7 +412,24 @@ system("rm -f /etc/fcron.daily/pakfire-upgrade"); } } elsif ("$ARGV[0]" eq "status") { - &Pakfire::status; + my $exitcode = 0; + my %status = &Pakfire::status; + + print "Core-Version: $status{'CoreVersion'}\n"; + print "Core-Update-Level: $status{'Release'}\n"; + print "Last update: $status{'LastUpdate'} ago\n"; + print "Last core-list update: $status{'LastCoreListUpdate'} ago\n"; + print "Last server-list update: $status{'LastServerListUpdate'} ago\n"; + print "Last packages-list update: $status{'LastPakListUpdate'} ago\n"; + print "Core-Update available: $status{'CoreUpdateAvailable'}"; + print " ($status{'AvailableRelease'})" if ("$status{'CoreUpdateAvailable'}" eq "yes"); + print "\nPackage-Updates available: $status{'PakUpdatesAvailable'}\n"; + print "Reboot required: $status{'RebootRequired'}\n"; + + $exitcode += 2 if ($status{'CoreUpdateAvailable'} eq "yes"); + $exitcode += 3 if ($status{'PakUpdatesAvailable'} eq "yes"); + $exitcode += 4 if ($status{'RebootRequired'} eq "yes"); + exit $exitcode; } else { &Pakfire::usage; }
- Make use of renewed status function in pakfire.cgi removing duplicate code
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- html/cgi-bin/pakfire.cgi | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index cb1272c63..42c603c61 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -43,6 +43,9 @@ my $PM_DEFAULT = 'default'; # Default user interface with command processing my $PM_LOGREAD = 'logread'; # Log messages viewer (ignores all commands) my $pagemode = $PM_DEFAULT;
+# Get Pakfire status +my %pakfire_status = &Pakfire::status(); + # Load general settings &General::readhash("${General::swroot}/main/settings", %mainsettings); &General::readhash("${General::swroot}/pakfire/settings", %pakfiresettings); @@ -84,7 +87,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" );
@@ -366,32 +369,26 @@ $selected{"TREE"}{"testing"} = ""; $selected{"TREE"}{"unstable"} = ""; $selected{"TREE"}{$pakfiresettings{"TREE"}} = "selected";
-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' /> @@ -403,14 +400,15 @@ print <<END; <select name="UPDPAKS" class="pflist" size="5" disabled> END
- my %coredb = &Pakfire::coredbinfo(); - if (defined $coredb{'AvailableRelease'}) { - print "<option value="core">$Lang::tr{'core update'} -- $coredb{'CoreVersion'} -- $Lang::tr{'release'}: $coredb{'Release'} -> $coredb{'AvailableRelease'}</option>\n"; + if ("$pakfire_status{'CoreUpdateAvailable'}" eq "yes") { + print "<option value="core">$Lang::tr{'core update'} -- $pakfire_status{'CoreVersion'} -- $Lang::tr{'release'}: $pakfire_status{'Release'} -> $pakfire_status{'AvailableRelease'}</option>\n"; }
- my %upgradelist = &Pakfire::dblist("upgrade"); - foreach my $pak (sort keys %upgradelist) { - print "<option value="$pak">$Lang::tr{'pak update'}: $pak -- $Lang::tr{'version'}: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- $Lang::tr{'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">$Lang::tr{'pak update'}: $pak -- $Lang::tr{'version'}: $upgradelist{$pak}{'ProgVersion'} -> $upgradelist{$pak}{'AvailableProgVersion'} -- $Lang::tr{'release'}: $upgradelist{$pak}{'Release'} -> $upgradelist{$pak}{'AvailableRelease'}</option>\n"; + } }
print <<END;
- 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.
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- src/pakfire/lib/functions.pl | 55 ++++++++++++++++++++++++++++++++++ src/pakfire/pakfire | 58 ++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+)
diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl index f87589bc4..1ebf98775 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:"); @@ -706,6 +707,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 331204a00..389c1399d 100644 --- a/src/pakfire/pakfire +++ b/src/pakfire/pakfire @@ -393,6 +393,64 @@ exit 1; } } + } 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");
- 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. - Removed hardcoded exclusions: - squid should show up correctly using the new metadata info - mdadm is part of core and will never show up here - alsa, unknown if this problem still exists, but if it is, this should be handled somewhere else.
Signed-off-by: Robin Roevens robin.roevens@disroot.org --- html/cgi-bin/services.cgi | 74 ++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 40 deletions(-)
diff --git a/html/cgi-bin/services.cgi b/html/cgi-bin/services.cgi index a1dcfd57e..29926ecc3 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,44 @@ 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; + + # Generate list of installed addon pak services + my %paklist = &Pakfire::dblist("installed");
- 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>"; + 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 "; + 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();
Hello Robin,
thanks for your mail, the second version of this patchset, and marking the first version as "superseded" in Patchwork. :-)
I just merged the patchset into "next", so everyone running on the "unstable" tree can see the changes and test them. Commit 3543c24f41027c6e4437b8d1b3d3ca75d47ed3c9 should ship all the files you changed, please let me know in case I forgot anything.
All the best, Peter Müller
Hi all
As promised a revision of this patchset by the end of July. Also fixing bug #12868, both in patch 01 (installed: yes/no output) and patch 06 (don't trow error on valid '--no-color' option).
This is quite a large patchset on delicate code which was discussed upon previous submission, but that was almost half a year ago. So I will try to link references to discussions on my previous submission where appropriate to refresh some memories :-).
What was changed since last submission; implementing/fixing Michael's remarks/concerns:
- Patch 01: Added translations as requested here: https://lists.ipfire.org/pipermail/development/2022-March/012782.html
- Patch 02: New patch translating WUI header/footer text
- Patch 03: (previously patch 02) was not changed
- Patch 04: (previously patch 03) replaced a forgotten fetchfile/move combo by new getmetafile function
- Previous patch 04 was removed as the function coreupdate_available turned out no longer used. See: https://lists.ipfire.org/pipermail/development/2022-March/012884.html
- Patch 05: Replaced seq shell command by perl seq-method, consistent use of 'Core-Update' as requested here: https://lists.ipfire.org/pipermail/development/2022-March/012787.html
- Patch 06: Added exitcode to pakfire list as requested here: https://lists.ipfire.org/pipermail/development/2022-March/012787.html Also exit with error when an unknown parameter is passed to pakfire list Added a small fix (in my opinion): log termination of pakfire inside END block
- Patch 07: Removed function coreupdate_available as it was concluded that it was no longer needed (see again: https://lists.ipfire.org/pipermail/development/2022-March/012884.html) Added meaningfull status exit code as remarked here: https://lists.ipfire.org/pipermail/development/2022-March/012788.html Split previous patch 07 pakfire.cgi changes in new patch 08:
- Patch 08: New patch, previously part of patch 07 Fixed localization as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012788.html
- Patch 09: (previously patch 08) Split previous patch 08 into patch 09 adding 'getmetadata' function and 'pakfire info' and patch 10 implementing the new 'getmetadata' in service.cgi. Show clean warning message when no packages are found with requested pakfire list filter
- Patch 10: (previously part of patch 08) Removed hardcoded exclusions in services.cgi as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012789.html
Previous patch 09 was dropped from this patchset as there turned out to be major problems with it and should be rethinked as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012856.html
I think I have tested this all throughly but as these are quite interusive changes to the pakfire core workings; Please do not trust my testing and test these patches yourselves during review. I would not want to carry the responibilities of breaking pakfire alone :-)
Regards Robin
Hi Peter
Peter Müller schreef op do 28-07-2022 om 13:51 [+0000]:
Hello Robin,
thanks for your mail, the second version of this patchset, and marking the first version as "superseded" in Patchwork. :-)
I just merged the patchset into "next", so everyone running on the "unstable" tree can see the changes and test them. Commit 3543c24f41027c6e4437b8d1b3d3ca75d47ed3c9 should ship all the files you changed, please let me know in case I forgot anything.
I think, aside from de localization files, you have them all. I'm not completely sure what this rootfile is you modified here? Are those all files that differ since last core update ? But I asume lang files are then handled somewhere else ?
Robin
All the best, Peter Müller
Hi all
As promised a revision of this patchset by the end of July. Also fixing bug #12868, both in patch 01 (installed: yes/no output) and patch 06 (don't trow error on valid '--no-color' option).
This is quite a large patchset on delicate code which was discussed upon previous submission, but that was almost half a year ago. So I will try to link references to discussions on my previous submission where appropriate to refresh some memories :-).
What was changed since last submission; implementing/fixing Michael's remarks/concerns:
- Patch 01: Added translations as requested here:
https://lists.ipfire.org/pipermail/development/2022-March/012782.html
- Patch 02: New patch translating WUI header/footer text
- Patch 03: (previously patch 02) was not changed
- Patch 04: (previously patch 03) replaced a forgotten
fetchfile/move combo by new getmetafile function
- Previous patch 04 was removed as the function
coreupdate_available turned out no longer used. See: https://lists.ipfire.org/pipermail/development/2022-March/012884.html
- Patch 05: Replaced seq shell command by perl seq-method,
consistent use of 'Core-Update' as requested here: https://lists.ipfire.org/pipermail/development/2022-March/012787.html
- Patch 06: Added exitcode to pakfire list as requested here:
https://lists.ipfire.org/pipermail/development/2022-March/012787.html Also exit with error when an unknown parameter is passed to pakfire list Added a small fix (in my opinion): log termination of pakfire inside END block
- Patch 07: Removed function coreupdate_available as it was
concluded that it was no longer needed (see again: https://lists.ipfire.org/pipermail/development/2022-March/012884.html ) Added meaningfull status exit code as remarked here: https://lists.ipfire.org/pipermail/development/2022-March/012788.html Split previous patch 07 pakfire.cgi changes in new patch 08:
- Patch 08: New patch, previously part of patch 07
Fixed localization as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012788.html
- Patch 09: (previously patch 08) Split previous patch 08 into
patch 09 adding 'getmetadata' function and 'pakfire info' and patch 10 implementing the new 'getmetadata' in service.cgi. Show clean warning message when no packages are found with requested pakfire list filter
- Patch 10: (previously part of patch 08) Removed hardcoded
exclusions in services.cgi as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012789.html Previous patch 09 was dropped from this patchset as there turned out to be major problems with it and should be rethinked as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012856.html
I think I have tested this all throughly but as these are quite interusive changes to the pakfire core workings; Please do not trust my testing and test these patches yourselves during review. I would not want to carry the responibilities of breaking pakfire alone :-)
Regards Robin
Hello,
Yay. *Throws confetti*
On 28 Jul 2022, at 12:21, Robin Roevens robin.roevens@disroot.org wrote:
Hi all
As promised a revision of this patchset by the end of July. Also fixing bug #12868, both in patch 01 (installed: yes/no output) and patch 06 (don't trow error on valid '--no-color' option).
This is quite a large patchset on delicate code which was discussed upon previous submission, but that was almost half a year ago. So I will try to link references to discussions on my previous submission where appropriate to refresh some memories :-).
What was changed since last submission; implementing/fixing Michael's remarks/concerns:
- Patch 01: Added translations as requested here: https://lists.ipfire.org/pipermail/development/2022-March/012782.html
- Patch 02: New patch translating WUI header/footer text
- Patch 03: (previously patch 02) was not changed
- Patch 04: (previously patch 03) replaced a forgotten fetchfile/move combo by new getmetafile function
- Previous patch 04 was removed as the function coreupdate_available turned out no longer used. See: https://lists.ipfire.org/pipermail/development/2022-March/012884.html
- Patch 05: Replaced seq shell command by perl seq-method, consistent use of 'Core-Update' as requested here: https://lists.ipfire.org/pipermail/development/2022-March/012787.html
- Patch 06: Added exitcode to pakfire list as requested here: https://lists.ipfire.org/pipermail/development/2022-March/012787.html Also exit with error when an unknown parameter is passed to pakfire list Added a small fix (in my opinion): log termination of pakfire inside END block
- Patch 07: Removed function coreupdate_available as it was concluded that it was no longer needed (see again: https://lists.ipfire.org/pipermail/development/2022-March/012884.html) Added meaningfull status exit code as remarked here: https://lists.ipfire.org/pipermail/development/2022-March/012788.html Split previous patch 07 pakfire.cgi changes in new patch 08:
- Patch 08: New patch, previously part of patch 07 Fixed localization as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012788.html
- Patch 09: (previously patch 08) Split previous patch 08 into patch 09 adding 'getmetadata' function and 'pakfire info' and patch 10 implementing the new 'getmetadata' in service.cgi. Show clean warning message when no packages are found with requested pakfire list filter
- Patch 10: (previously part of patch 08) Removed hardcoded exclusions in services.cgi as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012789.html
Previous patch 09 was dropped from this patchset as there turned out to be major problems with it and should be rethinked as pointed out here: https://lists.ipfire.org/pipermail/development/2022-March/012856.html
I think I have tested this all throughly but as these are quite interusive changes to the pakfire core workings; Please do not trust my testing and test these patches yourselves during review. I would not want to carry the responibilities of breaking pakfire alone :-)
Indeed. We will need to test this *very* thoroughly. Not because I don’t trust you, but because we won’t be able to patch user’s systems if this thing properly breaks. So all give it a very good test so that we can all sleep better again.
However, I am not panicking about this, since the code looked good and clean. Great job!
-Michael
Regards Robin
-- Dit bericht is gescanned op virussen en andere gevaarlijke inhoud door MailScanner en lijkt schoon te zijn.