[pve-devel] [PATCH pve-manager 17/27] debian: postinst: create notifications.cfg if it does not exist

Lukas Wagner l.wagner at proxmox.com
Tue Nov 7 11:18:17 CET 2023


We only warn on failure so that the postinst script does not fail
in case pmxcfs is not running.

Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 debian/postinst | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/debian/postinst b/debian/postinst
index 4c9a1f25..7dad2b1a 100755
--- a/debian/postinst
+++ b/debian/postinst
@@ -93,6 +93,32 @@ migrate_apt_auth_conf() {
     fi
 }
 
+write_notification_cfg() {
+        # Create default config:
+        # A sendmail-target that sends to root at pam, and a
+        # matcher that sends all notifications to this target
+        cat >> /etc/pve/notifications.cfg <<EOF
+sendmail: default-target
+        mailto-user root at pam
+        comment Send mails to root at pam's email address
+
+matcher: default-matcher
+        target default-target
+        comment Send all notifications to 'default-target'
+EOF
+}
+
+create_default_notification_cfg() {
+    if ! test -f /etc/pve/notifications.cfg ; then
+        echo "Creating default 'notifications.cfg' file"
+
+        # Only warn in case we cannot write to pmxcfs
+        if ! write_notification_cfg ; then
+            echo "Could not create default 'notifications.cfg' file"
+        fi
+    fi
+}
+
 case "$1" in
   triggered)
     # We don't print a status message here, as dpkg already said
@@ -167,6 +193,8 @@ case "$1" in
 
     set_lvm_conf
 
+    create_default_notification_cfg
+
     if test ! -e /proxmox_install_mode; then
         # modeled after code generated by dh_start
         for unit in ${UNITS}; do
-- 
2.39.2






More information about the pve-devel mailing list