all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api 3/4] report: skip irrelevant files in /etc/pmg/templates
Date: Fri,  7 Jul 2023 18:54:27 +0200	[thread overview]
Message-ID: <20230707165428.94777-4-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20230707165428.94777-1-s.ivanov@proxmox.com>

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>
---
 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





  parent reply	other threads:[~2023-07-07 16:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07 16:54 [pmg-devel] [PATCH pmg-api 0/4] add notification about unmodified template-overrides Stoiko Ivanov
2023-07-07 16:54 ` [pmg-devel] [PATCH pmg-api 1/4] utils: add helper for unmodified templates Stoiko Ivanov
2023-07-10 10:02   ` Thomas Lamprecht
2023-07-07 16:54 ` [pmg-devel] [PATCH pmg-api 2/4] pmg7to8: notify about " Stoiko Ivanov
2023-07-11 15:20   ` [pmg-devel] applied: " Thomas Lamprecht
2023-07-07 16:54 ` Stoiko Ivanov [this message]
2023-07-11 15:20   ` [pmg-devel] applied: [PATCH pmg-api 3/4] report: skip irrelevant files in /etc/pmg/templates Thomas Lamprecht
2023-07-07 16:54 ` [pmg-devel] [PATCH pmg-api 4/4] report: group use statements Stoiko Ivanov
2023-07-11 15:19   ` [pmg-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230707165428.94777-4-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal