diff --git a/setup-email.sh b/setup-email.sh index 40c5f4f..673f58e 100644 --- a/setup-email.sh +++ b/setup-email.sh @@ -1,88 +1,98 @@ #!/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 -# ----------------------------- -# 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 +# ---- Root Check ---- +if [[ $EUID -ne 0 ]]; then + echo -e "${BOLD}${RED}${INDENT}Bitte als Root ausfĂŒhren (sudo)${RESET}" + exit 1 +fi -case "$choice" in - 1) - TYPE="PVE" - NOTIF_CFG="/etc/pve/notifications.cfg" - PRIV_NOTIF_CFG="/etc/pve/priv/notifications.cfg" - USER_DEFAULT="mailout" - ;; - 2) - TYPE="PBS" - NOTIF_CFG="/etc/proxmox-backup/notifications.cfg" - PRIV_NOTIF_CFG="/etc/proxmox-backup/notifications-priv.cfg" - USER_DEFAULT="mailout" - ;; - *) - echo "UngĂŒltige Auswahl. Abbruch." - exit 1 - ;; -esac +# ---- 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" -# ----------------------------- -# Backup-Funktion -# ----------------------------- +while true; do + read -rp "${INDENT}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="mailout" + break + ;; + 2) + TYPE="PBS" + NOTIF_CFG="/etc/proxmox-backup/notifications.cfg" + PRIV_NOTIF_CFG="/etc/proxmox-backup/notifications-priv.cfg" + USER_DEFAULT="mailout" + break + ;; + *) + echo -e "${RED}${INDENT}UngĂŒltige Auswahl! Bitte 1 oder 2 eingeben.${RESET}" + ;; + esac +done + +# ---- 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 + local file=$1 + if [[ -f "$file" ]]; then + local bak="${file}.bak.$(date +%Y%m%d%H%M%S)" + cp "$file" "$bak" + echo -e "${YELLOW}${INDENT}Backup erstellt: ${CYAN}$bak${RESET}" + fi } -# ----------------------------- -# Pflichtfeld-Reader -# $1 = Prompt -# $2 = Variablenname -# $3 = Optionaler Default -# ----------------------------- +# ---- Pflichtfeld-Reader ---- read_required() { - local prompt="$1" - local varname="$2" - local default="${3:-}" - local input + 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 + while true; do + if [[ -n "$default" ]]; then + read -rp "${INDENT}${prompt} [$default]: " input + input=${input:-$default} + else + read -rp "${INDENT}${prompt}: " input + fi + if [[ -n "$input" ]]; then + printf -v "$varname" '%s' "$input" + break + fi + echo -e "${RED}${INDENT}❌ Eingabe darf nicht leer sein!${RESET}" + done } -# ----------------------------- -# Backups -# ----------------------------- +# ---- Backups erstellen ---- 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 -e "${CYAN}${BOLD}${INDENT}Bitte die SMTP Notification Konfiguration fĂŒr $TYPE eingeben:${RESET}" +echo -e "${INDENT}(Alle Felder sind Pflicht – Enter ĂŒbernimmt ggf. den Default)" echo -# ----------------------------- -# Eingaben mit Vorlagen -# ----------------------------- +# ---- Eingaben ---- read_required "Author (MH-PVE02 | MAIERHOME H33)" AUTHOR read_required "From-Address (MH-PVE02@vmd55888.de)" FROMADDR 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 "SMTP Benutzername" USERNAME "$USER_DEFAULT" -# Passwort (Pflichtfeld, versteckt) +# ---- Passwort (versteckt) ---- while true; do - read -rsp "SMTP Passwort: " SMTP_PASS - echo - [[ -n "$SMTP_PASS" ]] && break - echo "❌ Passwort darf nicht leer sein!" + read -rsp "${INDENT}SMTP Passwort: " SMTP_PASS + echo + [[ -n "$SMTP_PASS" ]] && break + echo -e "${RED}${INDENT}❌ Passwort darf nicht leer sein!${RESET}" done -# ----------------------------- -# notifications.cfg schreiben -# ----------------------------- +# ---- notifications.cfg schreiben ---- cat > "$NOTIF_CFG" << EOF sendmail: mail-to-root comment Send mails to root@pam's email address @@ -124,13 +132,12 @@ smtp: mailout username $USERNAME EOF -# ----------------------------- -# priv/notifications-priv.cfg schreiben -# ----------------------------- +# ---- 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." +echo -e "${GREEN}${BOLD}${INDENT}✅ $TYPE Notification Konfiguration neu geschrieben!${RESET}" +echo -e "${INDENT}Bitte WebUI prĂŒfen."