Files
WPanda/Scripts/bash/ovh_dnsupdate.sh
2025-12-15 10:00:38 +01:00

68 lines
1.5 KiB
Bash

#!/bin/sh
# ovh-dynhost-update.sh - POSIX sh verzió
# ---------- Konfiguráció ----------
DH_USER="meszely.eu-matrix"
DH_PASS="virgI6774#Panda"
HOSTNAME="home.meszely.eu"
LOGFILE="/var/log/ovh-dynhost-update.log"
# ---------- VÉGE konfiguráció ----------
log() {
echo "$(date -Iseconds) - $*" >> "${LOGFILE}" 2>/dev/null || echo "$*"
}
get_public_ip() {
curl -fsS https://api.ipify.org || echo ""
}
get_dns_ip() {
dig +short A "${HOSTNAME}" | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | head -n1 || echo ""
}
update_ovh() {
ip="$1"
curl -fsS --max-time 30 --user "${DH_USER}:${DH_PASS}" \
"https://www.ovh.com/nic/update?system=dyndns&hostname=${HOSTNAME}&myip=${ip}" || echo ""
}
main() {
log "Script indítva — host: ${HOSTNAME}"
public_ip="$(get_public_ip)"
if [ -z "$public_ip" ]; then
log "Hiba: nem sikerült lekérni a publikus IP-t."
exit 1
fi
log "Publikus IP: $public_ip"
dns_ip="$(get_dns_ip)"
if [ -z "$dns_ip" ]; then
log "Nincs A rekord jelenleg vagy nem elérhető (dns_ip üres)."
else
log "DNS-en található A rekord: $dns_ip"
fi
if [ "$public_ip" = "$dns_ip" ]; then
log "IP nem változott (nochg). Nem frissítünk."
exit 0
fi
log "IP eltér — frissítés OVH felé..."
response="$(update_ovh "$public_ip")"
log "OVH válasz: $response"
case "$response" in
good*|nochg*)
log "Sikeres frissítés: $response"
exit 0
;;
*)
log "Frissítés sikertelen: $response"
exit 2
;;
esac
}
main "$@"