[pmg-devel] [PATCH pmg-api 3/4] report: skip irrelevant files in /etc/pmg/templates

Stoiko Ivanov s.ivanov at proxmox.com
Fri Jul 7 18:54:27 CEST 2023


This patch removes:
* templates which have no changes to the ones in
  /var/lib/pmg/templates
* files generated by ucf

from the report. Unmodified files are reported, so that the user can
remove them.

This should make providing support a bit easier - as currenlty I'd
copy each template from the report to `diff` it with the version in
the package, for finding out if there is something relevant.

the new dump_template sub was copied from dir_to_text, in order to
explicitly write which files are skipped.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/Report.pm | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/PMG/Report.pm b/src/PMG/Report.pm
index 027c882..b3a554c 100644
--- a/src/PMG/Report.pm
+++ b/src/PMG/Report.pm
@@ -5,6 +5,8 @@ use warnings;
 use PVE::Tools;
 use Mail::SpamAssassin::DnsResolver;
 
+use PMG::Utils;
+
 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
 
 my $cmd_timeout = 10; # generous timeout
@@ -46,7 +48,7 @@ my $report_def = {
 	'pmgconfig dump',
 	sub { dir2text('/etc/pmg/','(?:domains|mynetworks|tls_policy|transport)' ) },
 	sub { dir2text('/etc/postfix/','(?:clientaccess|senderaccess|rcptaccess)' ) },
-	sub { dir2text('/etc/pmg/templates/', '[^.].*' ) },
+	sub { dump_templates() },
 	'pmgdb dump',
     ],
 };
@@ -135,4 +137,26 @@ sub check_dns_resolution {
     $report .= $answertext . "\n";
 }
 
+sub dump_templates {
+
+    my $unmodified = PMG::Utils::find_unmodified_templates();
+    my $unmodified_re;
+    if ($unmodified) {
+	$report .= "\n unmodified templates:\n    ";
+	$report .= join("\n    ", $unmodified->@*);
+	$unmodified_re = '(?:'.join('|', $unmodified->@*) .')';
+    }
+
+    my $template_dir = '/etc/pmg/templates/';
+    PVE::Tools::dir_glob_foreach($template_dir, '[^.].*', sub {
+	my ($file) = @_;
+	if ($file =~ /\.ucf-(?:dist|new|old)/) {
+	    $report .= "\n skipping $file";
+	} elsif (!defined($unmodified_re) || $file !~ qr/$unmodified_re$/) {
+	    $report .=  "\n# cat $template_dir$file\n";
+	    $report .= PVE::Tools::file_get_contents($template_dir.$file)."\n";
+	}
+    });
+}
+
 1;
-- 
2.39.2





More information about the pmg-devel mailing list