fix creating msmtprc
All checks were successful
Docker Build Smart Logic / Build amd64 & arm64 (push) Successful in 16s

This commit is contained in:
2026-02-07 00:05:32 +01:00
parent e208f30559
commit 72675a40d8

View File

@@ -12,7 +12,7 @@ if [ ! -f "$STATE_FILE" ] || ! jq -e . "$STATE_FILE" >/dev/null 2>&1; then
fi fi
while true; do while true; do
# 1. Config laden
if [ -f "$CONFIG_FILE" ]; then if [ -f "$CONFIG_FILE" ]; then
source "$CONFIG_FILE" source "$CONFIG_FILE"
else else
@@ -20,6 +20,23 @@ while true; do
sleep 60; continue sleep 60; continue
fi fi
# 2. HIER NEU: msmtp Konfiguration IMMER neu schreiben
# Damit ist sie immer verfügbar für Tests und Updates
cat <<EOF > /etc/msmtprc
defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /var/log/msmtp.log
account default
host $SMTP_HOST
port $SMTP_PORT
from $EMAIL_FROM
user $SMTP_USER
password $SMTP_PASS
EOF
chmod 600 /etc/msmtprc
INTERVAL=${CHECK_INTERVAL:-3600} INTERVAL=${CHECK_INTERVAL:-3600}
UPDATES_FOUND="" UPDATES_FOUND=""
echo "--- Starte Check: $(date) ---" echo "--- Starte Check: $(date) ---"
@@ -92,22 +109,12 @@ while true; do
# E-Mail Versand # E-Mail Versand
if [ -n "$UPDATES_FOUND" ]; then if [ -n "$UPDATES_FOUND" ]; then
# Dynamische msmtp config (wie vorher) echo " 📧 Versuche E-Mail zu senden an $EMAIL_TO..."
cat <<EOF > /etc/msmtprc if echo -e "Subject: Watchdog Alert\n\n$UPDATES_FOUND" | timeout 20s msmtp --debug "$EMAIL_TO" 2>&1; then
defaults echo " ✅ E-Mail erfolgreich versendet."
auth on else
tls on echo " ❌ FEHLER beim E-Mail Versand (siehe oben)."
tls_trust_file /etc/ssl/certs/ca-certificates.crt fi
account default
host $SMTP_HOST
port $SMTP_PORT
from $EMAIL_FROM
user $SMTP_USER
password $SMTP_PASS
EOF
chmod 600 /etc/msmtprc
echo -e "Subject: Watchdog Alert\n\n$UPDATES_FOUND" | msmtp "$EMAIL_TO"
echo " 📧 E-Mail gesendet."
fi fi
echo "Nächster Scan in $INTERVAL s." echo "Nächster Scan in $INTERVAL s."