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"
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."