setup-email-pbs.sh aktualisiert

This commit is contained in:
2025-05-20 23:14:04 +02:00
parent 5b06e39047
commit 76ca50f97c

View File

@@ -1,40 +1,58 @@
#!/bin/bash
set -euo pipefail
echo "=== Proxmox Backup Server Benachrichtigungssystem konfigurieren ==="
NOTIF_CFG="/etc/proxmox-backup/notifications.cfg"
PRIV_NOTIF_CFG="/etc/proxmox-backup/notifications-priv.cfg"
read -p "SMTP Server: " SMTP_SERVER
read -p "SMTP Port [587]: " SMTP_PORT
SMTP_PORT=${SMTP_PORT:-587}
backup_file() {
local file=$1
if [ -f "$file" ]; then
local bak="${file}.bak.$(date +%Y%m%d%H%M%S)"
cp "$file" "$bak"
echo "Backup erstellt: $bak"
fi
}
read -p "SMTP Benutzer: " SMTP_USER
read -s -p "SMTP Passwort: " SMTP_PASS
backup_file "$NOTIF_CFG"
backup_file "$PRIV_NOTIF_CFG"
echo "Bitte die SMTP Notification Konfiguration für PBS eingeben:"
read -rp "Author (z.B. MH-PBS01 | MAIERHOME): " AUTHOR
read -rp "From-Address (z.B. MH-PBS01@vmd55888.de): " FROMADDR
read -rp "Empfänger-Mailadresse (mailto): " MAILTO
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
read -p "Absender-Adresse: " MAIL_FROM
read -p "Empfänger-Adresse: " MAIL_TO
cat > "$NOTIF_CFG" << EOF
sendmail: mail-to-root
comment Send mails to root@pam's email address
disable true
mailto-user root@pam
# Sender anlegen
proxmox-notify sender update smtp-default \
--type smtp \
--mailfrom "$MAIL_FROM" \
--smarthost "$SMTP_SERVER:$SMTP_PORT" \
--authuser "$SMTP_USER" \
--password "$SMTP_PASS" \
--mailname "$(hostname -f)"
matcher: default-matcher
comment Route all notifications to mail-to-root
mode all
target mailout
# Ziel anlegen
proxmox-notify target update mail-admin \
--type sendmail \
--mailto "$MAIL_TO"
smtp: mailout
author $AUTHOR
from-address $FROMADDR
mailto $MAILTO
mailto-user root@pam
mode $MODE
port $PORT
server $SERVER
username $USERNAME
EOF
# Policy zuweisen (optional)
proxmox-notify policy update default \
--targets mail-admin \
--sender smtp-default
cat > "$PRIV_NOTIF_CFG" << EOF
smtp: mailout
password $SMTP_PASS
EOF
# Test
echo
echo "==> Sende Testmail..."
proxmox-notify test --target mail-admin --subject "Testmail von PBS $(hostname)" --body "Dies ist eine Testbenachrichtigung vom neuen PBS-System."
echo "==> Konfiguration abgeschlossen. Sichtbar in der PBS Web-GUI unter: Verwaltung → Benachrichtigungen"
echo "PBS Notification Konfiguration neu geschrieben. Bitte WebUI prüfen."