From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id EC21FC69E for ; Fri, 7 Jul 2023 18:55:11 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D05692BB1F for ; Fri, 7 Jul 2023 18:54:41 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 7 Jul 2023 18:54:40 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5F2E840D60 for ; Fri, 7 Jul 2023 18:54:40 +0200 (CEST) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Fri, 7 Jul 2023 18:54:25 +0200 Message-Id: <20230707165428.94777-2-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230707165428.94777-1-s.ivanov@proxmox.com> References: <20230707165428.94777-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.095 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [utils.pm] Subject: [pmg-devel] [PATCH pmg-api 1/4] utils: add helper for unmodified templates X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jul 2023 16:55:12 -0000 find_unmodified_templates yields a list of overridden templates in /etc/pmg/templates, which have no change to the one they replace from /var/lib/pmg/templates. In practice this should only be a cosmetic problem, since the ones in /etc/pmg/templates would get updated to the new version in /var/lib/pmg/templates, by ucf if they have no changes. (There would be a dialog asking what to do if there was a change, as with sshd_config). However it can cause confusion also when providing support, and experience shows that there are quite a few installs, which have all templates copied (only to make a small modification to one). Signed-off-by: Stoiko Ivanov --- src/PMG/Utils.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm index 6405934..f0d31c1 100644 --- a/src/PMG/Utils.pm +++ b/src/PMG/Utils.pm @@ -1573,4 +1573,24 @@ sub try_decode_utf8 { return eval { decode('UTF-8', $data, 1) } // $data; } +sub find_unmodified_templates { + my $res = []; + + my $template_dir = '/var/lib/pmg/templates'; + my $override_dir = '/etc/pmg/templates'; + + PVE::Tools::dir_glob_foreach('/var/lib/pmg/templates', '.*\.(?:tt|in).*', sub { + my ($filename) = @_; + if ( -e "$override_dir/$filename") { + my $shipped = PVE::Tools::file_get_contents("$template_dir/$filename", 1024*1024); + my $override = PVE::Tools::file_get_contents("$override_dir/$filename", 1024*1024); + if ( $shipped eq $override ) { + push (@$res, $filename); + } + } + }); + + return $res; +} + 1; -- 2.39.2