selfhost-update.sh aktualisiert
This commit is contained in:
@@ -1,54 +1,45 @@
|
||||
#!/bin/bash
|
||||
# =============================================================================
|
||||
# Selfhost.de DynDNS-Update-Skript für IPv4 + IPv6
|
||||
# Speichere es z. B. als /usr/local/bin/selfhost-update.sh
|
||||
# chmod +x /usr/local/bin/selfhost-update.sh
|
||||
# =============================================================================
|
||||
|
||||
# ────── Deine Daten hier eintragen ───────────────────────────────────────────
|
||||
USERNAME="356205" # Selfhost.de Login
|
||||
PASSWORD="yaytVupov9" # Passwort oder langer Token
|
||||
HOSTNAME="cloud.schoedl.bayern" # z. B. home.selfhost.de
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# cron job
|
||||
# */10 * * * * /usr/local/bin/selfhost-update.sh >> /var/log/selfhost-update.log 2>&1
|
||||
# Konfiguration
|
||||
DYNDNS_ACCOUNT="356205"
|
||||
PASSWORD="yaytVupov9"
|
||||
HOSTNAME="cloud.schoedl.bayern"
|
||||
UPDATE_URL_BASE="https://${DYNDNS_ACCOUNT}:${PASSWORD}@carol.selfhost.de/nic/update?hostname=${HOSTNAME}"
|
||||
|
||||
UPDATE_URL="https://update.selfhost.de/nic/update"
|
||||
# Pfade zu den Dateien, in denen die letzte bekannte IP gespeichert wird
|
||||
LAST_IP4_FILE="./last_ip4.txt"
|
||||
LAST_IP6_FILE="./last_ip6.txt"
|
||||
|
||||
# Cache-Dateien (werden automatisch angelegt)
|
||||
CACHE_IPV4="/var/tmp/last_selfhost_ipv4"
|
||||
CACHE_IPV6="/var/tmp/last_selfhost_ipv6"
|
||||
# --- IPv4 Prüfung und Update ---
|
||||
CURRENT_IP4=$(curl -s -4 icanhazip.com)
|
||||
LAST_IP4=""
|
||||
|
||||
# Aktuelle öffentliche Adressen ermitteln (sehr zuverlässige Services)
|
||||
CURRENT_IPV4=$(curl -s --max-time 10 https://ipv4.icanhazip.com | tr -d '\n')
|
||||
CURRENT_IPV6=$(curl -s --max-time 10 https://ipv6.icanhazip.com | tr -d '\n')
|
||||
|
||||
# Falls IPv6 nicht vorhanden ist → leer lassen (nicht "curl fehlgeschlagen" senden)
|
||||
[ "$CURRENT_IPV6" = "no IPv6" ] && CURRENT_IPV6=""
|
||||
[ "$CURRENT_IPV6" = "curl: (7)" ] && CURRENT_IPV6="" # kein IPv6 am Standort
|
||||
|
||||
# Nur senden, wenn sich mindestens eine der IPs geändert hat
|
||||
SEND=0
|
||||
[ ! -f "$CACHE_IPV4" ] || [ "$CURRENT_IPV4" != "$(cat "$CACHE_IPV4")" ] && SEND=1
|
||||
[ -n "$CURRENT_IPV6" ] && { [ ! -f "$CACHE_IPV6" ] || [ "$CURRENT_IPV6" != "$(cat "$CACHE_IPV6")" ]; } && SEND=1
|
||||
|
||||
if [ "$SEND" -eq 1 ]; then
|
||||
# Parameter zusammensetzen
|
||||
PARAMS="hostname=$HOSTNAME"
|
||||
[ -n "$CURRENT_IPV4" ] && PARAMS="$PARAMS&myip=$CURRENT_IPV4"
|
||||
[ -n "$CURRENT_IPV6" ] && PARAMS="$PARAMS&myipv6=$CURRENT_IPV6"
|
||||
|
||||
RESPONSE=$(curl -s -u "$USERNAME:$PASSWORD" --max-time 20 \
|
||||
"$UPDATE_URL?$PARAMS")
|
||||
|
||||
# Cache aktualisieren
|
||||
echo "$CURRENT_IPV4" > "$CACHE_IPV4"
|
||||
[ -n "$CURRENT_IPV6" ] && echo "$CURRENT_IPV6" > "$CACHE_IPV6" || rm -f "$CACHE_IPV6"
|
||||
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') | Update gesendet | IPv4: $CURRENT_IPV4 | IPv6: $CURRENT_IPV6 | Antwort: $RESPONSE"
|
||||
else
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') | Keine Änderung → nichts gesendet (IPv4: $CURRENT_IPV4 | IPv6: $CURRENT_IPV6)"
|
||||
if [ -f "$LAST_IP4_FILE" ]; then
|
||||
LAST_IP4=$(cat "$LAST_IP4_FILE")
|
||||
fi
|
||||
|
||||
# (optional) komplettes Log in Datei schreiben
|
||||
# echo "$(date '+%Y-%m-%d %H:%M:%S') ..." >> /var/log/selfhost-update.log
|
||||
if [ -n "$CURRENT_IP4" ] && [ "$CURRENT_IP4" != "$LAST_IP4" ]; then
|
||||
echo "IPv4-Adresse hat sich geändert ($LAST_IP4 -> $CURRENT_IP4). Update wird gesendet."
|
||||
curl -s "${UPDATE_URL_BASE}&myip=${CURRENT_IP4}"
|
||||
echo "$CURRENT_IP4" > "$LAST_IP4_FILE"
|
||||
else
|
||||
echo "IPv4-Adresse unverändert oder Fehler bei der Ermittlung. Kein Update nötig."
|
||||
fi
|
||||
|
||||
# --- IPv6 Prüfung und Update ---
|
||||
CURRENT_IP6=$(curl -s -6 icanhazip.com)
|
||||
LAST_IP6=""
|
||||
|
||||
if [ -f "$LAST_IP6_FILE" ]; then
|
||||
LAST_IP6=$(cat "$LAST_IP6_FILE")
|
||||
fi
|
||||
|
||||
if [ -n "$CURRENT_IP6" ] && [ "$CURRENT_IP6" != "$LAST_IP6" ]; then
|
||||
echo "IPv6-Adresse hat sich geändert ($LAST_IP6 -> $CURRENT_IP6). Update wird gesendet."
|
||||
curl -s "${UPDATE_URL_BASE}&myip6=${CURRENT_IP6}"
|
||||
echo "$CURRENT_IP6" > "$LAST_IP6_FILE"
|
||||
else
|
||||
echo "IPv6-Adresse unverändert oder Fehler bei der Ermittlung. Kein Update nötig."
|
||||
fi
|
||||
|
||||
echo "Skriptlauf abgeschlossen."
|
||||
Reference in New Issue
Block a user