From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
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 3C4319CAE
 for <pmg-devel@lists.proxmox.com>; Mon, 26 Jun 2023 15:43:21 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 23DFE293AF
 for <pmg-devel@lists.proxmox.com>; Mon, 26 Jun 2023 15:42:51 +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))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pmg-devel@lists.proxmox.com>; Mon, 26 Jun 2023 15:42:50 +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 7395343D6F
 for <pmg-devel@lists.proxmox.com>; Mon, 26 Jun 2023 15:42:50 +0200 (CEST)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pmg-devel@lists.proxmox.com
Date: Mon, 26 Jun 2023 15:42:49 +0200
Message-Id: <20230626134249.525079-1-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.134 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
 POISEN_SPAM_PILL          0.1 Meta: its spam
 POISEN_SPAM_PILL_1        0.1 random spam to be learned in bayes
 POISEN_SPAM_PILL_3        0.1 random spam to be learned in bayes
 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 -
Subject: [pmg-devel] [PATCH pmg-api] debian/postinst: add old default values
 on upgrade to 8.x
X-BeenThere: pmg-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Mail Gateway development discussion
 <pmg-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pmg-devel/>
List-Post: <mailto:pmg-devel@lists.proxmox.com>
List-Help: <mailto:pmg-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel>, 
 <mailto:pmg-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 26 Jun 2023 13:43:21 -0000

in /etc/pmg/pmg.conf for
advfilter
use_bayes
use_awl

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
we could use a little helper script, but the grep/sed lines look
harmless and easy enough to keep it here imho

 debian/postinst | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/debian/postinst b/debian/postinst
index d4d434a..6ee7a24 100644
--- a/debian/postinst
+++ b/debian/postinst
@@ -87,8 +87,37 @@ case "$1" in
             fi
         fi
 
+        # on upgrade add pre 8.0 default values for advfilter, use_awl and use_bayes
+        # TODO: remove with 9.0
         if test ! -e /proxmox_install_mode ; then
 
+            pmgconf="/etc/pmg/pmg.conf"
+
+            if test -n "$2" && dpkg --compare-versions "$2" 'lt' '8.0.0'; then
+                if test ! -e $pmgconf ; then
+                    # if the config does not exist at all, fill with previous default configs
+                    printf "section: admin\n\tadvfilter 1\n" > $pmgconf
+                    printf "\nsection: spam\n\tuse_bayes 1\n\tuse_awl 1\n" >> $pmgconf
+                else
+                    if ! grep -q 'section: admin' $pmgconf ; then
+                        printf "\nsection: admin" >> $pmgconf
+                    fi
+                    if ! grep -q 'advfilter' $pmgconf ; then
+                        sed -i '/section: admin/a\\tadvfilter 1' $pmgconf
+                    fi
+
+                    if ! grep -q 'section: spam' $pmgconf ; then
+                        printf "\nsection: spam" >> $pmgconf
+                    fi
+                    if ! grep -q 'use_bayes' $pmgconf ; then
+                        sed -i '/section: spam/a\\tuse_bayes 1' $pmgconf
+                    fi
+                    if ! grep -q 'use_awl' $pmgconf ; then
+                        sed -i '/section: spam/a\\tuse_awl 1' $pmgconf
+                    fi
+                fi
+            fi
+
             pmgconfig init || true
             pmgdb init || true
 
-- 
2.30.2