Bugfix: Clownfischserver HomeIP Updater – Fehlerbehandlung & Fallbacks

Fixes:
- dnsutils-Paket (dig) zu install.sh hinzugefügt
- DNS-Fallbacks: dig → nslookup → getent
- Log-File Auto-Create bei Cron-Ausführung
- Zeilenumbrüche in .env-Variable entfernen (tr -d)
- UFW delete mit 'y' Auto-Bestätigung (für Cron nicht-interaktiv)
- Root-Crontab statt sudo-Crontab (install.sh läuft als root)
- ufw status numbered für bessere Regel-Erkennung

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-05-01 23:38:23 +02:00
co-authored by Claude Haiku 4.5
parent eff7d0d98b
commit 4758ee4306
3 changed files with 34 additions and 12 deletions
+9 -1
View File
@@ -5,7 +5,15 @@
"Bash(git config *)",
"Bash(git remote *)",
"Bash(git checkout *)",
"Bash(git add *)"
"Bash(git add *)",
"Bash(git commit -m 'v0.5.0 – Clownfischserver HomeIP Auto-Update: myfritz Automatik für SSH \\(5-Min Cron\\) *)",
"Bash(git push *)",
"Bash(bash -n install.sh)",
"Bash(bash -n scripts/clownfischserver-homeip-updater.sh)",
"Bash(python3 -m py_compile bot/*.py)",
"Bash(awk '{print \"Datei: \" $1 \" Größe: \" $5 \" Bytes\"}')",
"Bash(grep -oE '\\\\b\\([0-9]{1,3}\\\\.\\){3}[0-9]{1,3}\\\\b')",
"Bash(git commit -m 'Bugfix: Clownfischserver HomeIP Updater – Fehlerbehandlung & Fallbacks *)"
]
}
}
+4 -4
View File
@@ -168,7 +168,7 @@ step_packages() {
case "$PKG_MANAGER" in
apt)
run_with_spinner "Paketliste aktualisieren" apt-get update -qq || fail "apt update fehlgeschlagen"
run_with_spinner "Pakete installieren" apt-get install -y -qq curl wget git ufw python3 python3-pip python3-venv sudo htop net-tools lsof rsync openssl knockd || warn "Einige Pakete konnten nicht installiert werden – siehe Log"
run_with_spinner "Pakete installieren" apt-get install -y -qq curl wget git ufw python3 python3-pip python3-venv sudo htop net-tools lsof rsync openssl knockd dnsutils || warn "Einige Pakete konnten nicht installiert werden – siehe Log"
;;
dnf)
run_with_spinner "Pakete aktualisieren" dnf update -y -q
@@ -804,11 +804,11 @@ BOOTEOF
# Cron-Job für root (da ufw sudo braucht)
CRON_JOB="*/5 * * * * $INSTALL_DIR/scripts/clownfischserver-homeip-updater.sh >> /var/log/clownfischserver-homeip.log 2>&1"
# Bestehende clownfischserver Cron-Jobs entfernen
sudo crontab -l 2>/dev/null | grep -v clownfischserver-homeip-updater | sudo crontab - 2>/dev/null || true
# Bestehende clownfischserver Cron-Jobs entfernen (install.sh läuft als root)
crontab -l 2>/dev/null | grep -v clownfischserver-homeip-updater | crontab - 2>/dev/null || true
# Neuen Job hinzufügen
(sudo crontab -l 2>/dev/null; echo "$CRON_JOB") | sudo crontab - >> "$LOG_FILE" 2>&1
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab - >> "$LOG_FILE" 2>&1
ok "Cron-Job aktiviert: alle 5 Min HomeIP prüfen"
info "Log: /var/log/clownfischserver-homeip.log"
+20 -6
View File
@@ -28,16 +28,28 @@ if [[ ! -f "$ENV_FILE" ]]; then
exit 1
fi
# Lade myfritz-Adresse aus .env
MYFRITZ_DOMAIN=$(grep "^CLOWNFISCHSERVER_HOME_IP_DOMAIN=" "$ENV_FILE" | cut -d= -f2)
# Erstelle Log-File wenn nicht existiert
touch "$LOG_FILE" 2>/dev/null || true
# Lade myfritz-Adresse aus .env (Zeilenumbrüche entfernen)
MYFRITZ_DOMAIN=$(grep "^CLOWNFISCHSERVER_HOME_IP_DOMAIN=" "$ENV_FILE" | cut -d= -f2 | tr -d '\r\n')
if [[ -z "$MYFRITZ_DOMAIN" ]]; then
log "Clownfischserver HomeIP: Deaktiviert (keine myfritz-Adresse)"
exit 0
fi
# Versuche IP aufzulösen
# Versuche IP aufzulösen (mit Fallback)
if command -v dig &>/dev/null; then
NEW_IP=$(dig +short "$MYFRITZ_DOMAIN" A 2>/dev/null | tail -1 | grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b')
elif command -v nslookup &>/dev/null; then
NEW_IP=$(nslookup "$MYFRITZ_DOMAIN" 2>/dev/null | grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' | tail -1)
elif command -v getent &>/dev/null; then
NEW_IP=$(getent hosts "$MYFRITZ_DOMAIN" 2>/dev/null | awk '{print $1}')
else
log_error "Kein DNS-Tool verfügbar (dig/nslookup/getent)"
exit 1
fi
if [[ -z "$NEW_IP" ]]; then
log_error "DNS-Auflösung fehlgeschlagen: $MYFRITZ_DOMAIN"
@@ -61,10 +73,12 @@ fi
# IP hat sich geändert oder ist neue Installation
log "IP-Änderung erkannt! Updating ufw rules..."
# Entferne alte Regel falls vorhanden
# Entferne alte Regel falls vorhanden (mit y bestätigen für Cron)
if [[ -n "$OLD_IP" ]]; then
if ufw status | grep -q "22/tcp.*ALLOW.*$OLD_IP"; then
ufw delete allow from "$OLD_IP" to any port 22 >> "$LOG_FILE" 2>&1
# Prüfe ob Regel existiert
if ufw status numbered | grep -qE "22.*ALLOW.*FROM\s+$OLD_IP"; then
# Löschen mit 'y' autom. bestätigen
echo "y" | ufw delete allow from "$OLD_IP" to any port 22 >> "$LOG_FILE" 2>&1
log "Alte Regel entfernt: allow from $OLD_IP to port 22"
fi
fi