From 013faee4bfdf6890840cbd6969b4a814729be229 Mon Sep 17 00:00:00 2001 From: "manuel.maier" Date: Tue, 27 Jan 2026 22:57:41 +0100 Subject: [PATCH] =?UTF-8?q?setup-email.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup-email.sh | 134 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 setup-email.sh diff --git a/setup-email.sh b/setup-email.sh new file mode 100644 index 0000000..cf2de00 --- /dev/null +++ b/setup-email.sh @@ -0,0 +1,134 @@ +#!/bin/bash +set -euo pipefail + +# ----------------------------- +# Auswahl: PVE oder PBS +# ----------------------------- +echo "Welche Proxmox-Installation möchtest du konfigurieren?" +echo "1) Proxmox VE" +echo "2) Proxmox Backup Server" +read -rp "Bitte auswählen (1 oder 2): " choice + +case "$choice" in + 1) + TYPE="PVE" + NOTIF_CFG="/etc/pve/notifications.cfg" + PRIV_NOTIF_CFG="/etc/pve/priv/notifications.cfg" + USER_DEFAULT="MH-PVE02@vmd55888.de" + ;; + 2) + TYPE="PBS" + NOTIF_CFG="/etc/proxmox-backup/notifications.cfg" + PRIV_NOTIF_CFG="/etc/proxmox-backup/notifications-priv.cfg" + USER_DEFAULT="MH-PBS01@vmd55888.de" + ;; + *) + echo "Ungültige Auswahl. Abbruch." + exit 1 + ;; +esac + +# ----------------------------- +# Backup-Funktion +# ----------------------------- +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 +} + +# ----------------------------- +# Pflichtfeld-Reader +# ----------------------------- +read_required() { + local prompt="$1" + local varname="$2" + local default="${3:-}" + local input + + while true; do + if [[ -n "$default" ]]; then + read -rp "$prompt [$default]: " input + input=${input:-$default} + else + read -rp "$prompt: " input + fi + + if [[ -n "$input" ]]; then + printf -v "$varname" '%s' "$input" + break + fi + + echo "❌ Eingabe darf nicht leer sein!" + done +} + +# ----------------------------- +# Backups +# ----------------------------- +backup_file "$NOTIF_CFG" +backup_file "$PRIV_NOTIF_CFG" + +echo +echo "Bitte die SMTP Notification Konfiguration für $TYPE eingeben:" +echo "(Alle Felder sind Pflicht – Enter übernimmt ggf. den Default)" +echo + +# ----------------------------- +# Eingaben +# ----------------------------- +read_required "Author" AUTHOR +read_required "From-Address" FROMADDR + +read_required "Empfänger-Mailadresse (mailto)" MAILTO "admin@vmd55888.de" +read_required "SMTP Server" SERVER "mail.vmd55888.de" +read_required "SMTP Port" PORT "587" +read_required "Modus (starttls/ssl/none)" MODE "starttls" +read_required "SMTP Benutzername" USERNAME "$USER_DEFAULT" + +# Passwort (Pflichtfeld, versteckt) +while true; do + read -rsp "SMTP Passwort: " SMTP_PASS + echo + [[ -n "$SMTP_PASS" ]] && break + echo "❌ Passwort darf nicht leer sein!" +done + +# ----------------------------- +# notifications.cfg schreiben +# ----------------------------- +cat > "$NOTIF_CFG" << EOF +sendmail: mail-to-root + comment Send mails to root@pam's email address + disable true + mailto-user root@pam + +matcher: default-matcher + comment Route all notifications to mail-to-root + mode all + target mailout + +smtp: mailout + author $AUTHOR + from-address $FROMADDR + mailto $MAILTO + mailto-user root@pam + mode $MODE + port $PORT + server $SERVER + username $USERNAME +EOF + +# ----------------------------- +# priv/notifications-priv.cfg schreiben +# ----------------------------- +cat > "$PRIV_NOTIF_CFG" << EOF +smtp: mailout + password $SMTP_PASS +EOF + +echo +echo "✅ $TYPE Notification Konfiguration neu geschrieben. Bitte WebUI prüfen." \ No newline at end of file