From ea56d2e85e1cae7a7998ccce879d50f574e86e0f Mon Sep 17 00:00:00 2001 From: tim Date: Fri, 17 Sep 2021 09:58:18 +0200 Subject: [PATCH] Only send an ipv6 address when one exists. --- update_ip.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/update_ip.sh b/update_ip.sh index 70c25f4..11befec 100755 --- a/update_ip.sh +++ b/update_ip.sh @@ -5,9 +5,10 @@ server=ns1.example.com zone=dyn.example.com host=desktop secret="" +iface=eth0 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_ip6=$( nslookup -type=aaaa ${host}.${zone} | grep -oP '(?<=^Address:\ )[\da-f:]+$' ) @@ -44,13 +45,18 @@ else rm -f "${HOME}/${cache}" fi +ipv6_line="" +if [ -n "${new_ip6}" ]; then + ipv6_line="update add ${host}.${zone}. 60 AAAA ${new_ip6}" +fi + update=$( cat <<-EOF server ${server} zone ${zone}. key ${host}.${zone} ${secret} update delete ${host}.${zone}. 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 )" send EOF