]> git.proxmox.com Git - pmg-api.git/commitdiff
system report: skip irrelevant files in /etc/pmg/templates
authorStoiko Ivanov <s.ivanov@proxmox.com>
Fri, 7 Jul 2023 16:54:27 +0000 (18:54 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 11 Jul 2023 15:50:53 +0000 (17:50 +0200)
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@proxmox.com>
 [T: merge in helper method for getting the unmodified templates ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PMG/Report.pm

index 027c882f88ef7be2184f94100ee68ba412cb8dc5..4973dc528f9866e9d93e406a2f06c588c4c6d7cd 100644 (file)
@@ -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,25 @@ sub check_dns_resolution {
     $report .= $answertext . "\n";
 }
 
+sub dump_templates {
+    my ($template_dir, $base_dir) = ('/etc/pmg/templates/', '/var/lib/pmg/templates');
+    PVE::Tools::dir_glob_foreach($template_dir, '[^.].*', sub {
+       my ($file) = @_;
+       my $override_but_unmodified = 0;
+       if ($file =~ /.*\.(?:tt|in).*/ && -e "$base_dir/$file") {
+           my $shipped = PVE::Tools::file_get_contents("$base_dir/$file", 1024*1024);
+           my $override = PVE::Tools::file_get_contents("$template_dir/$file", 1024*1024);
+           $override_but_unmodified = $shipped eq $override;
+       }
+       if ($file =~ /\.ucf-(?:dist|new|old)/) {
+           $report .= "\n# SKIP $file\n";
+       } elsif ($override_but_unmodified) {
+           $report .= "\n# NOTE, found a unmodified template-override: $file\n";
+       } else {
+           $report .=  "\n# cat $template_dir$file\n";
+           $report .= PVE::Tools::file_get_contents($template_dir.$file)."\n";
+       }
+    });
+}
+
 1;