Files
mxmehl a7d2b6cf4e feat!: adapt to v2 server (#1)
Great simplification as more logic is on server now

Reviewed-on: #1
Co-authored-by: Max Mehl <mail@mehl.mx>
2026-10-22 15:37:01 +02:00

50 lines
1.6 KiB
Bash
Executable File

#!/bin/sh
# SPDX-FileCopyrightText: 2016 Max Mehl <mail@mehl.mx>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Client for Snap DynDNS Server: asks the server to point each configured
# hostname to the address this machine connects from. The server detects
# whether anything changed, so running this every minute from cron is fine.
config="$(dirname "$0")/config.cfg"
while getopts c: opt; do
case $opt in
c) config=$OPTARG ;;
*) echo "Usage: $0 [-c configfile]" >&2; exit 2 ;;
esac
done
# shellcheck source=/dev/null
. "$config" || exit 1
families=""
[ "${IPV4:-true}" = true ] && families="4"
[ "${IPV6:-false}" = true ] && families="$families 6"
date '+[%Y-%m-%d %H:%M:%S]'
status=0
for entry in $HOSTS; do
host=${entry%%:*}
token=${entry#*:}
for family in $families; do
# Credentials go through stdin, so they do not show up in the process list.
# --fail-with-body keeps the server's answer (badauth, nohost, 911, ...) on errors.
if out=$(printf 'user = "%s:%s"\n' "$host" "$token" |
curl "-$family" --fail-with-body -sS --max-time 10 -K - "$SERVER?hostname=$host"); then
# curl -6 can silently fall back to IPv4 (mapped address) without IPv6 connectivity
case $family:$out in
6:*:*:*) echo "$host IPv$family: $out" ;;
6:*)
echo "$host IPv6: server saw an IPv4 address ($out), no IPv6 connectivity?" >&2
status=1
;;
*) echo "$host IPv$family: $out" ;;
esac
else
echo "$host IPv$family: update failed${out:+: $out}" >&2
status=1
fi
done
done
exit $status