mirror of
https://github.com/tunix/digitalocean-dyndns
synced 2024-12-22 04:49:52 +00:00
commit
85ee2538ff
1 changed files with 9 additions and 6 deletions
15
dyndns.sh
15
dyndns.sh
|
@ -20,6 +20,7 @@ while ( true ); do
|
||||||
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||||
$dns_list)
|
$dns_list)
|
||||||
record_id=$(echo $domain_records| jq ".domain_records[] | select(.type == \"A\" and .name == \"$NAME\") | .id")
|
record_id=$(echo $domain_records| jq ".domain_records[] | select(.type == \"A\" and .name == \"$NAME\") | .id")
|
||||||
|
record_data=$(echo $domain_records| jq -r ".domain_records[] | select(.type == \"A\" and .name == \"@\") | .data")
|
||||||
|
|
||||||
test -z $record_id && die "No record found with given domain name!"
|
test -z $record_id && die "No record found with given domain name!"
|
||||||
|
|
||||||
|
@ -28,13 +29,15 @@ while ( true ); do
|
||||||
url="$dns_list/$record_id"
|
url="$dns_list/$record_id"
|
||||||
|
|
||||||
if [[ -n $ip ]]; then
|
if [[ -n $ip ]]; then
|
||||||
echo "Sending data=$data to url=$url"
|
if [[ "$ip" != "$record_data" ]]; then
|
||||||
|
echo "existing DNS record address ($record_data) doesn't match current IP ($ip), sending data=$data to url=$url"
|
||||||
|
|
||||||
curl -s -X PUT \
|
curl -s -X PUT \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||||
-d "$data" \
|
-d "$data" \
|
||||||
"$url" &> /dev/null
|
"$url" &> /dev/null
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "IP wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.."
|
echo "IP wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.."
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue