From patchwork Wed Mar 9 22:56:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Roevens X-Patchwork-Id: 5329 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KDSJm2wcYz3xj2 for ; Wed, 9 Mar 2022 22:57:44 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4KDSJl3J3pz4jy; Wed, 9 Mar 2022 22:57:43 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KDSJl31Pxz30Hd; Wed, 9 Mar 2022 22:57:43 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4KDSJj3MM5z2xR5 for ; Wed, 9 Mar 2022 22:57:41 +0000 (UTC) Received: from knopi.disroot.org (knopi.disroot.org [178.21.23.139]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4KDSJh6CQDz5V3 for ; Wed, 9 Mar 2022 22:57:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 9E642400A8 for ; Wed, 9 Mar 2022 23:57:40 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id l59XmW-pMauN for ; Wed, 9 Mar 2022 23:57:39 +0100 (CET) Received: from chojin.sicho.home (amaterasu.sicho.home [192.168.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (no client certificate requested) (Authenticated sender) by hachiman (MailScanner Milter) with SMTP id A99511B98C; Wed, 9 Mar 2022 23:57:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1646866657; bh=mh/Oc0fHnFM3uPy+xRdOmlH04+dJDkBiV7sxp/WAWpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iDuiH7dop0b2wa0+RwdQ64z4pW1PH/8HWwvvhwcuUjPi/DtjSq0RGZdQDDQb6QUUe dXHqvUhVwMzLckqEzF05Ur401bFL8pRVrlInY/ldOS8CCOsDqhhH1GkjdUVIWko+rS 2QM8gEXT4wuG0yR6rsl+FyU6BI4POnW7/JUM5a0FDyqzoPQqCZztS4oKig+fuiXHPQ Z6AiDw6+VpKQoq4r9SNhikFXaiOX/5MsLL+fL944QGWKUoxvXyh/gKfKLm8hun+oGZ /u3u4eWUAvM298DGJ8pvDfp8nRaFy1lF+b2RZ3vAQQtNdT1DI5nU9QkyW/dS98Lgvi MJ8qRa9NUnb0w== From: Robin Roevens To: development@lists.ipfire.org Subject: [PATCH 8/9] pakfire: Add getmetadata function Date: Wed, 9 Mar 2022 23:56:54 +0100 Message-Id: <20220309225655.4472-9-robin.roevens@disroot.org> In-Reply-To: <20220309225655.4472-1-robin.roevens@disroot.org> References: <20220309225655.4472-1-robin.roevens@disroot.org> Mime-Version: 1.0 X-sicho-MailScanner-ID: A99511B98C.A8A80 X-sicho-MailScanner: Found to be clean X-sicho-MailScanner-From: robin.roevens@disroot.org X-sicho-MailScanner-Watermark: 1647471431.92834@bnMMtraYUDP2h3j2j60BCQ ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1646866660; a=rsa-sha256; cv=none; b=WU8jmkyWFYG5bSBBGfePZwlf3e71rQ5Nrsl9vS+nBRd8Ps8dpQJcYuAvI8eabdaCT+8W3U hJNQBRcOyqdaDF8BqpFeqXewXEBJOWNS4eR6sGFufpQRmzaHdA9I8GBP0cRXNE0osDKK9C aGmjK8FEo/JVmswk3Pqo6nWCSBpASj7bj6VWxqssOqJSyWDRs1ttUx7Rw30RV2RB4GGhpX uuvpQRT8QUzan0mmbedpByHF9zcjfPU8hoUGOGTjfPWJxPs+HHvFkECxZ/oboz6JRnsMox toMBWA6CTaQLL7jMbtxlTYdFbp3mdoxCvkAdEtEQY+gF77t9VYIUkKAxRVHFfA== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=iDuiH7do; dmarc=pass (policy=quarantine) header.from=disroot.org; spf=pass (mail01.ipfire.org: domain of robin.roevens@disroot.org designates 178.21.23.139 as permitted sender) smtp.mailfrom=robin.roevens@disroot.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1646866660; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UNrwEQlLC7uOrPQ+LWCOzY3/xEJfrZQk76rhQR0k0lc=; b=li8L/byCQcLAX/pwVD+MSU6t93isfg8rC7ZfYyTs+O8ChDc5OuqgHb3qsLBzO/BVPofx2q ShIwB2PMa04gHs107ynENkcjLEw/y1QZhzmyT96ND1fLab08XhTtMzx8SWKYOdD5K8A+qV KSMKtWzfSMZyP6j7xFC2z2xGpG2L7Bbgmk3skh4bCfQ04XtERwA7yGOy2neGJ6VHLSz0YN QB8To9E1KXA1jFW2J5CHDyujNG5xSR6N9w4BBh/Hqea+dWji9+sEZEDYxbao0UQZbzIdDT AUywTOIlGlgJfjkywaw5Z7UvN6XR9lCgL1iHT4lEj99XoKkVfdB3pXGfFY2jcQ== Authentication-Results: mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=iDuiH7do; dmarc=pass (policy=quarantine) header.from=disroot.org; spf=pass (mail01.ipfire.org: domain of robin.roevens@disroot.org designates 178.21.23.139 as permitted sender) smtp.mailfrom=robin.roevens@disroot.org X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [-4.44 / 11.00]; BAYES_HAM(-3.00)[99.99%]; IP_REPUTATION_HAM(-1.15)[asn: 50673(-0.33), country: NL(-0.01), ip: 178.21.23.139(-0.82)]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM(-0.90)[-0.901]; SPF_REPUTATION_HAM(-0.68)[-0.67731760723277]; MV_CASE(0.50)[]; DMARC_POLICY_ALLOW(-0.50)[disroot.org,quarantine]; R_MISSING_CHARSET(0.50)[]; MIME_HTML_ONLY(0.20)[]; R_SPF_ALLOW(-0.20)[+a:c]; R_DKIM_ALLOW(-0.20)[disroot.org:s=mail]; MX_GOOD(-0.01)[]; FROM_EQ_ENVFROM(0.00)[]; ASN(0.00)[asn:50673, ipnet:178.21.23.0/24, country:NL]; RCVD_TLS_LAST(0.00)[]; MIME_TRACE(0.00)[0:~]; ARC_NA(0.00)[]; DKIM_TRACE(0.00)[disroot.org:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; TO_DN_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; PREVIOUSLY_DELIVERED(0.00)[development@lists.ipfire.org]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1] X-Rspamd-Queue-Id: 4KDSJh6CQDz5V3 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" - 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 --- 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 ""; - $col="bgcolor='$color{'color22'}'"; - }else{ - print ""; - $col="bgcolor='$color{'color20'}'"; - } + my @paks; + my @addon_services; - print "$_ "; - my $status = isautorun($_,$col); - print "$status "; - print "$Lang::tr{"; - print "$Lang::tr{ "; - my $status = &isrunningaddon($_,$col); - $status =~ s/\\[[0-1]\;[0-9]+m//g; - - chomp($status); - print "$status"; - print ""; + # 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 ""; + $col="bgcolor='$color{'color22'}'"; + }else{ + print ""; + $col="bgcolor='$color{'color20'}'"; + } + print "$_ "; + 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 ""; + print " "; + } else { + print "$Lang::tr{"; + print "$Lang::tr{ "; + } + my $status = isrunningaddon($_,$col); + $status =~ s/\\[[0-1]\;[0-9]+m//g; + + chomp($status); + print "$status"; + print ""; + } + print "\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(" - Contacts the servers for new lists of paks."); &Pakfire::message(" - Installs the latest version of all paks."); &Pakfire::message(" [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks."); + &Pakfire::message(" [ ...] - Output pak metadata."); &Pakfire::message(" - 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");