setup-email-pve.sh aktualisiert

This commit is contained in:
2025-05-20 23:06:19 +02:00
parent 3db895d830
commit 5b06e39047

View File

@@ -4,22 +4,14 @@ set -euo pipefail
NOTIF_CFG="/etc/pve/notifications.cfg" NOTIF_CFG="/etc/pve/notifications.cfg"
PRIV_NOTIF_CFG="/etc/pve/priv/notifications.cfg" PRIV_NOTIF_CFG="/etc/pve/priv/notifications.cfg"
if [ ! -f "$NOTIF_CFG" ]; then # Backup-Funktion
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_file() { backup_file() {
local file=$1 local file=$1
if [ -f "$file" ]; then
local bak="${file}.bak.$(date +%Y%m%d%H%M%S)" local bak="${file}.bak.$(date +%Y%m%d%H%M%S)"
cp "$file" "$bak" cp "$file" "$bak"
echo "Backup erstellt: $bak" echo "Backup erstellt: $bak"
fi
} }
backup_file "$NOTIF_CFG" backup_file "$NOTIF_CFG"
@@ -37,21 +29,33 @@ read -rp "SMTP Benutzername: " USERNAME
read -rsp "SMTP Passwort: " SMTP_PASS read -rsp "SMTP Passwort: " SMTP_PASS
echo echo
# notifications.cfg anpassen # notifications.cfg komplett neu schreiben
sed -i "/^smtp:/,/^$/ { cat > "$NOTIF_CFG" << EOF
s/^[[:space:]]*author .*/ author $AUTHOR/ sendmail: mail-to-root
s/^[[:space:]]*from-address .*/ from-address $FROMADDR/ comment Send mails to root@pam's email address
s/^[[:space:]]*mailto .*/ mailto $MAILTO/ disable true
s/^[[:space:]]*server .*/ server $SERVER/ mailto-user root@pam
s/^[[:space:]]*port .*/ port $PORT/
s/^[[:space:]]*mode .*/ mode $MODE/
s/^[[:space:]]*username .*/ username $USERNAME/
}" "$NOTIF_CFG"
# priv/notifications.cfg anpassen matcher: default-matcher
sed -i "/^smtp:/,/^$/ { comment Route all notifications to mail-to-root
s/^[[:space:]]*password .*/ password $SMTP_PASS/ mode all
}" "$PRIV_NOTIF_CFG" target mailout
echo "Konfiguration wurde aktualisiert." smtp: mailout
echo "Bitte überprüfe in der WebUI, ob alles korrekt übernommen wurde." 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."