setup-email.sh aktualisiert

This commit is contained in:
2026-01-28 00:08:01 +01:00
parent 47ed7dd514
commit 7fecad7b62

View File

@@ -1,51 +1,67 @@
#!/bin/bash #!/bin/bash
# ==========================================
# Proxmox / PBS SMTP Notification Setup
# ==========================================
# Autor: Manuel Maier Style 😎
# Ausgabe: SMTP Notification Konfiguration
# ==========================================
# ---- Farben / Layout ----
BOLD="\033[1m"
GREEN="\033[32m"
CYAN="\033[36m"
YELLOW="\033[33m"
RED="\033[31m"
RESET="\033[0m"
INDENT=" "
set -euo pipefail set -euo pipefail
# ----------------------------- # ---- Root Check ----
# Auswahl: PVE oder PBS if [[ $EUID -ne 0 ]]; then
# ----------------------------- echo -e "${BOLD}${RED}${INDENT}Bitte als Root ausführen (sudo)${RESET}"
echo "Welche Proxmox-Installation möchtest du konfigurieren?" exit 1
echo "1) Proxmox VE" fi
echo "2) Proxmox Backup Server"
read -rp "Bitte auswählen (1 oder 2): " choice
case "$choice" in # ---- Auswahl PVE / PBS ----
echo -e "${CYAN}${BOLD}${INDENT}Welche Proxmox-Installation möchtest du konfigurieren?${RESET}"
echo -e "${INDENT}1) Proxmox VE"
echo -e "${INDENT}2) Proxmox Backup Server"
while true; do
read -rp "${INDENT}Bitte auswählen (1 oder 2): " choice
case "$choice" in
1) 1)
TYPE="PVE" TYPE="PVE"
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"
USER_DEFAULT="mailout" USER_DEFAULT="mailout"
break
;; ;;
2) 2)
TYPE="PBS" TYPE="PBS"
NOTIF_CFG="/etc/proxmox-backup/notifications.cfg" NOTIF_CFG="/etc/proxmox-backup/notifications.cfg"
PRIV_NOTIF_CFG="/etc/proxmox-backup/notifications-priv.cfg" PRIV_NOTIF_CFG="/etc/proxmox-backup/notifications-priv.cfg"
USER_DEFAULT="mailout" USER_DEFAULT="mailout"
break
;; ;;
*) *)
echo "Ungültige Auswahl. Abbruch." echo -e "${RED}${INDENT}Ungültige Auswahl! Bitte 1 oder 2 eingeben.${RESET}"
exit 1
;; ;;
esac esac
done
# ----------------------------- # ---- Backup-Funktion ----
# Backup-Funktion
# -----------------------------
backup_file() { backup_file() {
local file=$1 local file=$1
if [ -f "$file" ]; then 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 -e "${YELLOW}${INDENT}Backup erstellt: ${CYAN}$bak${RESET}"
fi fi
} }
# ----------------------------- # ---- Pflichtfeld-Reader ----
# Pflichtfeld-Reader
# $1 = Prompt
# $2 = Variablenname
# $3 = Optionaler Default
# -----------------------------
read_required() { read_required() {
local prompt="$1" local prompt="$1"
local varname="$2" local varname="$2"
@@ -54,35 +70,29 @@ read_required() {
while true; do while true; do
if [[ -n "$default" ]]; then if [[ -n "$default" ]]; then
read -rp "$prompt [$default]: " input read -rp "${INDENT}${prompt} [$default]: " input
input=${input:-$default} input=${input:-$default}
else else
read -rp "$prompt: " input read -rp "${INDENT}${prompt}: " input
fi fi
if [[ -n "$input" ]]; then if [[ -n "$input" ]]; then
printf -v "$varname" '%s' "$input" printf -v "$varname" '%s' "$input"
break break
fi fi
echo -e "${RED}${INDENT}❌ Eingabe darf nicht leer sein!${RESET}"
echo "❌ Eingabe darf nicht leer sein!"
done done
} }
# ----------------------------- # ---- Backups erstellen ----
# Backups
# -----------------------------
backup_file "$NOTIF_CFG" backup_file "$NOTIF_CFG"
backup_file "$PRIV_NOTIF_CFG" backup_file "$PRIV_NOTIF_CFG"
echo echo
echo "Bitte die SMTP Notification Konfiguration für $TYPE eingeben:" echo -e "${CYAN}${BOLD}${INDENT}Bitte die SMTP Notification Konfiguration für $TYPE eingeben:${RESET}"
echo "(Alle Felder sind Pflicht Enter übernimmt ggf. den Default)" echo -e "${INDENT}(Alle Felder sind Pflicht Enter übernimmt ggf. den Default)"
echo echo
# ----------------------------- # ---- Eingaben ----
# Eingaben mit Vorlagen
# -----------------------------
read_required "Author (MH-PVE02 | MAIERHOME H33)" AUTHOR read_required "Author (MH-PVE02 | MAIERHOME H33)" AUTHOR
read_required "From-Address (MH-PVE02@vmd55888.de)" FROMADDR read_required "From-Address (MH-PVE02@vmd55888.de)" FROMADDR
read_required "Empfänger-Mailadresse" MAILTO "pbs-dashboard@vmd55888.de" read_required "Empfänger-Mailadresse" MAILTO "pbs-dashboard@vmd55888.de"
@@ -91,17 +101,15 @@ read_required "SMTP Port (25/465/587)" PORT "587"
read_required "Modus (starttls/ssl/none)" MODE "starttls" read_required "Modus (starttls/ssl/none)" MODE "starttls"
read_required "SMTP Benutzername" USERNAME "$USER_DEFAULT" read_required "SMTP Benutzername" USERNAME "$USER_DEFAULT"
# Passwort (Pflichtfeld, versteckt) # ---- Passwort (versteckt) ----
while true; do while true; do
read -rsp "SMTP Passwort: " SMTP_PASS read -rsp "${INDENT}SMTP Passwort: " SMTP_PASS
echo echo
[[ -n "$SMTP_PASS" ]] && break [[ -n "$SMTP_PASS" ]] && break
echo "❌ Passwort darf nicht leer sein!" echo -e "${RED}${INDENT}❌ Passwort darf nicht leer sein!${RESET}"
done done
# ----------------------------- # ---- notifications.cfg schreiben ----
# notifications.cfg schreiben
# -----------------------------
cat > "$NOTIF_CFG" << EOF cat > "$NOTIF_CFG" << EOF
sendmail: mail-to-root sendmail: mail-to-root
comment Send mails to root@pam's email address comment Send mails to root@pam's email address
@@ -124,13 +132,12 @@ smtp: mailout
username $USERNAME username $USERNAME
EOF EOF
# ----------------------------- # ---- priv/notifications-priv.cfg schreiben ----
# priv/notifications-priv.cfg schreiben
# -----------------------------
cat > "$PRIV_NOTIF_CFG" << EOF cat > "$PRIV_NOTIF_CFG" << EOF
smtp: mailout smtp: mailout
password $SMTP_PASS password $SMTP_PASS
EOF EOF
echo echo
echo "$TYPE Notification Konfiguration neu geschrieben. Bitte WebUI prüfen." echo -e "${GREEN}${BOLD}${INDENT}$TYPE Notification Konfiguration neu geschrieben!${RESET}"
echo -e "${INDENT}Bitte WebUI prüfen."