From 3075a5304195542619bb97b13483397320bbbae6 Mon Sep 17 00:00:00 2001 From: Joe Lanford Date: Thu, 30 Nov 2017 21:34:38 -0500 Subject: [PATCH] Select only the A record when figuring out the record ID and refresh on every interval in case it changes --- dyndns.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dyndns.sh b/dyndns.sh index 5610bad..a6dd4ee 100755 --- a/dyndns.sh +++ b/dyndns.sh @@ -13,15 +13,16 @@ test -z $DOMAIN && die "DOMAIN not set!" test -z $NAME && die "NAME not set!" dns_list="$api_host/domains/$DOMAIN/records" -domain_records=$(curl -s -X GET \ - -H "Content-Type: application/json" \ - -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ - $dns_list) -record_id=$(echo $domain_records| jq ".domain_records[] | select(.name == \"$NAME\") | .id") - -test -z $record_id && die "No record found with given domain name!" while ( true ); do + domain_records=$(curl -s -X GET \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ + $dns_list) + record_id=$(echo $domain_records| jq ".domain_records[] | select(.type == \"A\" and .name == \"$NAME\") | .id") + + test -z $record_id && die "No record found with given domain name!" + ip="$(curl -s ipinfo.io/ip)" data="{\"type\": \"A\", \"name\": \"$NAME\", \"data\": \"$ip\"}" url="$dns_list/$record_id"