diff --git a/setup-email-pve.sh b/setup-email-pve.sh index 28b827f..9ce9974 100644 --- a/setup-email-pve.sh +++ b/setup-email-pve.sh @@ -1,19 +1,32 @@ #!/bin/bash -set -e +set -euo pipefail -CFG="/etc/pve/notifications.cfg" +NOTIF_CFG="/etc/pve/notifications.cfg" +PRIV_NOTIF_CFG="/etc/pve/priv/notifications.cfg" -if [ ! -f "$CFG" ]; then - echo "Fehler: $CFG nicht gefunden!" +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="${CFG}.bak.$(date +%Y%m%d%H%M%S)" -cp "$CFG" "$BACKUP" -echo "Backup erstellt: $BACKUP" +backup_file() { + local file=$1 + local bak="${file}.bak.$(date +%Y%m%d%H%M%S)" + cp "$file" "$bak" + echo "Backup erstellt: $bak" +} + +backup_file "$NOTIF_CFG" +backup_file "$PRIV_NOTIF_CFG" + +echo "Bitte die SMTP Notification Konfiguration eingeben:" -# Eingaben abfragen read -rp "Author (z.B. MH-PVE02 | MAIERHOME H33): " AUTHOR read -rp "From-Address (z.B. MH-PVE02@vmd55888.de): " FROMADDR read -rp "Empfänger-Mailadresse (mailto): " MAILTO @@ -21,16 +34,24 @@ read -rp "SMTP Server (z.B. mail.vmd55888.de): " SERVER read -rp "SMTP Port (z.B. 587): " PORT read -rp "Modus (starttls/ssl/none): " MODE read -rp "SMTP Benutzername: " USERNAME +read -rsp "SMTP Passwort: " SMTP_PASS +echo -# sed ersetzt gezielt die Zeilen in der Sektion smtp: mailout -sed -i "/^smtp: mailout/,/^$/ { - s/^ author .*/ author $AUTHOR/ - s/^ from-address .*/ from-address $FROMADDR/ - s/^ mailto .*/ mailto $MAILTO/ - s/^ server .*/ server $SERVER/ - s/^ port .*/ port $PORT/ - s/^ mode .*/ mode $MODE/ - s/^ username .*/ username $USERNAME/ -}" "$CFG" +# 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" -echo "Konfiguration aktualisiert. Bitte Passwort im WebUI setzen!" +# priv/notifications.cfg anpassen +sed -i "/^smtp:/,/^$/ { + s/^[[:space:]]*password .*/ password $SMTP_PASS/ +}" "$PRIV_NOTIF_CFG" + +echo "Konfiguration wurde aktualisiert." +echo "Bitte überprüfe in der WebUI, ob alles korrekt übernommen wurde."