1
0
Fork 0
mirror of https://github.com/tunix/digitalocean-dyndns synced 2024-12-22 21:09:52 +00:00

Compare commits

...

5 commits

Author SHA1 Message Date
Alper Kanat
a21767ee62
Merge pull request #19 from ringvold/create-non-existant-record
Create sub domain if it does not exist
2021-03-24 01:06:21 +03:00
Alper Kanat
0c4833645b
Update dyndns.sh 2021-03-24 01:03:31 +03:00
Harald Ringvold
928616e9e0 Fix IP check for the case where all services fail
Last commit would still not fix the problem if all services fails
because of the check on line 38.
2021-03-20 21:14:24 +01:00
Harald Ringvold
9b59388a58 Adding check for valid ip address
In some cases the return body from ifconfig.co is an HTML error page.
This change makes sure the response is a valid IP address.
2021-03-20 21:09:58 +01:00
Harald Ringvold
8c940d5bd2 Create sub domain if it does not exist 2021-03-20 20:37:31 +01:00

View file

@ -29,7 +29,7 @@ while ( true ); do
for service in ${services[@]}; do for service in ${services[@]}; do
echo "Trying with $service..." echo "Trying with $service..."
ip="$(curl -s $service)" ip="$(curl -s $service | grep '[0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{3\}')"
test -n "$ip" && break test -n "$ip" && break
done done
@ -46,12 +46,22 @@ while ( true ); do
# re-enable glob expansion # re-enable glob expansion
set +f set +f
test -z $record_id && echo "No record found with '$sub' domain name!" && continue data="{\"type\": \"A\", \"name\": \"$sub\", \"data\": \"$ip\"}"
url="$dns_list/$record_id"
if [[ -z $record_id ]]; then
echo "No record found with '$sub' domain name. Creating record, sending data=$data to url=$url"
new_record=$(curl -s -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
-d "$data" \
"$url")
record_data=$(echo $new_record| jq -r ".data")
fi
if [[ "$ip" != "$record_data" ]]; then if [[ "$ip" != "$record_data" ]]; then
data="{\"type\": \"A\", \"name\": \"$sub\", \"data\": \"$ip\"}"
url="$dns_list/$record_id"
echo "existing DNS record address ($record_data) doesn't match current IP ($ip), sending data=$data to url=$url" 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 \