From 5b06e3904720d8b0532be0387ab27c66335afb74 Mon Sep 17 00:00:00 2001 From: "manuel.maier" Date: Tue, 20 May 2025 23:06:19 +0200 Subject: [PATCH] setup-email-pve.sh aktualisiert --- setup-email-pve.sh | 64 ++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/setup-email-pve.sh b/setup-email-pve.sh index 9ce9974..affd3fc 100644 --- a/setup-email-pve.sh +++ b/setup-email-pve.sh @@ -4,22 +4,14 @@ set -euo pipefail NOTIF_CFG="/etc/pve/notifications.cfg" PRIV_NOTIF_CFG="/etc/pve/priv/notifications.cfg" -if [ ! -f "$NOTIF_CFG" ]; then - echo "Fehler: $NOTIF_CFG nicht gefunden!" - exit 1 -fi - -if [ ! -f "$PRIV_NOTIF_CFG" ]; then - echo "Fehler: $PRIV_NOTIF_CFG nicht gefunden!" - exit 1 -fi - -# Backup anlegen +# Backup-Funktion backup_file() { local file=$1 - local bak="${file}.bak.$(date +%Y%m%d%H%M%S)" - cp "$file" "$bak" - echo "Backup erstellt: $bak" + if [ -f "$file" ]; then + local bak="${file}.bak.$(date +%Y%m%d%H%M%S)" + cp "$file" "$bak" + echo "Backup erstellt: $bak" + fi } backup_file "$NOTIF_CFG" @@ -37,21 +29,33 @@ read -rp "SMTP Benutzername: " USERNAME read -rsp "SMTP Passwort: " SMTP_PASS echo -# notifications.cfg anpassen -sed -i "/^smtp:/,/^$/ { - s/^[[:space:]]*author .*/ author $AUTHOR/ - s/^[[:space:]]*from-address .*/ from-address $FROMADDR/ - s/^[[:space:]]*mailto .*/ mailto $MAILTO/ - s/^[[:space:]]*server .*/ server $SERVER/ - s/^[[:space:]]*port .*/ port $PORT/ - s/^[[:space:]]*mode .*/ mode $MODE/ - s/^[[:space:]]*username .*/ username $USERNAME/ -}" "$NOTIF_CFG" +# notifications.cfg komplett neu schreiben +cat > "$NOTIF_CFG" << EOF +sendmail: mail-to-root + comment Send mails to root@pam's email address + disable true + mailto-user root@pam -# priv/notifications.cfg anpassen -sed -i "/^smtp:/,/^$/ { - s/^[[:space:]]*password .*/ password $SMTP_PASS/ -}" "$PRIV_NOTIF_CFG" +matcher: default-matcher + comment Route all notifications to mail-to-root + mode all + target mailout -echo "Konfiguration wurde aktualisiert." -echo "Bitte überprüfe in der WebUI, ob alles korrekt übernommen wurde." +smtp: mailout + author $AUTHOR + from-address $FROMADDR + mailto $MAILTO + mailto-user root@pam + mode $MODE + port $PORT + server $SERVER + username $USERNAME +EOF + +# priv/notifications.cfg komplett neu schreiben +cat > "$PRIV_NOTIF_CFG" << EOF +smtp: mailout + password $SMTP_PASS +EOF + +echo "Konfiguration neu geschrieben. Bitte WebUI prüfen."