Updated Njalla OpenWRT DDNS script to minimize duplicate code

This commit is contained in:
Logan G 2024-02-17 13:17:52 -07:00
parent 2e92dbeb72
commit ff8c6c3c01
Signed by: logan
GPG key ID: E328528C921E7A7A

View file

@ -13,19 +13,18 @@ network_find_wan6 NET_IF6
network_get_ipaddr NET_ADDR "${NET_IF}"
network_get_ipaddr6 NET_ADDR6 "${NET_IF6}"
if [ "$1" = "--query" ]; then
if [ "$1" = "--query" ] || [ ! -f ${IP_TEMPFILE} ]; then
echo "Querying IP from DNS server"
NET_ADDR_OLD="$(nslookup -type=a ${NJALLA_SUBDOMAIN} | awk '/^Address: / { print $2 }')"
NET_ADDR6_OLD="$(nslookup -type=aaaa ${NJALLA_SUBDOMAIN} | awk '/^Address: / { print $2 }')"
else
if [ -f ${IP_TEMPFILE} ]; then
. ${IP_TEMPFILE}
else
NET_ADDR_OLD="$(nslookup -type=a ${NJALLA_SUBDOMAIN} | awk '/^Address: / { print $2 }')"
NET_ADDR6_OLD="$(nslookup -type=aaaa ${NJALLA_SUBDOMAIN} | awk '/^Address: / { print $2 }')"
echo "NET_ADDR_OLD=${NET_ADDR}" > $IP_TEMPFILE
echo "NET_ADDR6_OLD=${NET_ADDR6}" >> $IP_TEMPFILE
if [ ! -f ${IP_TEMPFILE} ]; then
touch ${IP_TEMPFILE} || exit 1
echo "NET_ADDR_OLD=${NET_ADDR_OLD}" > $IP_TEMPFILE
echo "NET_ADDR6_OLD=${NET_ADDR6_OLD}" >> $IP_TEMPFILE
fi
else
. ${IP_TEMPFILE}
fi
if [ "$NET_ADDR" != "$NET_ADDR_OLD" ] || [ "$NET_ADDR6" != "$NET_ADDR6_OLD" ] || [ "$1" = "--force" ]; then