mirror of
https://github.com/tunix/digitalocean-dyndns
synced 2024-12-22 04:49:52 +00:00
Create sub domain if it does not exist
This commit is contained in:
parent
7b38d97e38
commit
8c940d5bd2
1 changed files with 12 additions and 4 deletions
16
dyndns.sh
16
dyndns.sh
|
@ -46,12 +46,20 @@ while ( true ); do
|
|||
# re-enable glob expansion
|
||||
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
|
||||
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"
|
||||
|
||||
curl -s -X PUT \
|
||||
|
|
Loading…
Reference in a new issue