first version for delegated zones

This commit is contained in:
Alexander Gabriel 2026-03-24 22:45:23 +01:00
commit 689a915c19
3 changed files with 57 additions and 0 deletions

4
.env.example Normal file
View File

@ -0,0 +1,4 @@
token=
api_url=https://dynv6.com/api/v2/zones/xxx/records/yyy
hostname=zzz
device=ensxx

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

52
dynv6_delegated.sh Normal file
View File

@ -0,0 +1,52 @@
#!/bin/sh -e
set -a
source .env
set +a
file=$HOME/.dynv6.addr6
[ -e $file ] && old=`cat $file`
if [ -z "$hostname" -o -z "$token" ]; then
echo "Usage: token=<your-authentication-token> [netmask=64] $0 your-name.dynv6.net [device]"
exit 1
fi
if [ -z "$netmask" ]; then
netmask=128
fi
if [ -n "$device" ]; then
device="dev $device"
fi
address=$(ip -6 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)
if [ -e /usr/bin/curl ]; then
bin="curl -fsS"
elif [ -e /usr/bin/wget ]; then
bin="wget -O-"
else
echo "neither curl nor wget found"
exit 1
fi
if [ -z "$address" ]; then
echo "no IPv6 address found"
exit 1
fi
# address with netmask
current=$address/$netmask
if [ "$old" = "$current" ]; then
#echo "IPv6 address unchanged"
exit
fi
# send addresses to dynv6
curl --silent -H "Authorization: Bearer $token" -H "Accept: application/json" -H "Content-Type: application/json" -X PATCH \
-d '{"name":"'$hostname'","data":"'$address'","type":"AAAA"}' \
$api_url | jq
# save current address
echo $current > $file