Only send an ipv6 address when one exists.

This commit is contained in:
Timothy Allen 2021-09-17 09:58:18 +02:00
parent 783baf723f
commit ea56d2e85e

View File

@ -5,9 +5,10 @@ server=ns1.example.com
zone=dyn.example.com zone=dyn.example.com
host=desktop host=desktop
secret="" secret=""
iface=eth0
new_ip4=$( wget -4 -q -O - https://treehouse.org.za/ip ) new_ip4=$( wget -4 -q -O - https://treehouse.org.za/ip )
new_ip6=$( ip -6 addr show eth0 | grep global | grep -oP '(?<=inet6\s)[\da-f:]+' ) new_ip6=$( ip -6 addr show ${iface} | grep global | grep -oP '(?<=inet6\s)[\da-f:]+' )
cur_ip4=$( nslookup -type=a ${host}.${zone} | grep -oP '(?<=^Address:\ )\d+(\.\d+){3}$' ) cur_ip4=$( nslookup -type=a ${host}.${zone} | grep -oP '(?<=^Address:\ )\d+(\.\d+){3}$' )
cur_ip6=$( nslookup -type=aaaa ${host}.${zone} | grep -oP '(?<=^Address:\ )[\da-f:]+$' ) cur_ip6=$( nslookup -type=aaaa ${host}.${zone} | grep -oP '(?<=^Address:\ )[\da-f:]+$' )
@ -44,13 +45,18 @@ else
rm -f "${HOME}/${cache}" rm -f "${HOME}/${cache}"
fi fi
ipv6_line=""
if [ -n "${new_ip6}" ]; then
ipv6_line="update add ${host}.${zone}. 60 AAAA ${new_ip6}"
fi
update=$( cat <<-EOF update=$( cat <<-EOF
server ${server} server ${server}
zone ${zone}. zone ${zone}.
key ${host}.${zone} ${secret} key ${host}.${zone} ${secret}
update delete ${host}.${zone}. update delete ${host}.${zone}.
update add ${host}.${zone}. 60 A ${new_ip4} update add ${host}.${zone}. 60 A ${new_ip4}
update add ${host}.${zone}. 60 AAAA ${new_ip6} ${ipv6_line}
update add ${host}.${zone}. 60 TXT "Updated on $( date )" update add ${host}.${zone}. 60 TXT "Updated on $( date )"
send send
EOF EOF