Update cloudflare-template.sh

pull/54/head
MohairVomNipa 3 years ago committed by GitHub
parent 88c73e30f8
commit 7fb8a4607a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      cloudflare-template.sh

@ -46,6 +46,12 @@ fi
## Seek for the A record ## Seek for the A record
########################################### ###########################################
logger "DDNS Updater: Check Initiated"
record=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?type=A&name=$record_name" \
-H "X-Auth-Email: $auth_email" \
-H "$auth_header $auth_key" \
-H "Content-Type: application/json")
logger "DDNS Updater: Check Initiated" logger "DDNS Updater: Check Initiated"
record=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?type=A&name=$record_name" \ record=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?type=A&name=$record_name" \
-H "X-Auth-Email: $auth_email" \ -H "X-Auth-Email: $auth_email" \
@ -60,6 +66,11 @@ if [[ $record == *"\"count\":0"* ]]; then
exit 1 exit 1
fi fi
if [[ $record == *"\"count\":0"* ]]; then
logger -s "DDNS Updater: Record does not exist, perhaps create one first? (${ip} for ${record_name})"
exit 1
fi
########################################### ###########################################
## Get existing IP ## Get existing IP
########################################### ###########################################
@ -70,6 +81,13 @@ if [[ $ip == $old_ip ]]; then
exit 0 exit 0
fi fi
old_ip=$(echo "$record" | sed -E 's/.*"content":"(([0-9]{1,3}\.){3}[0-9]{1,3})".*/\1/')
# Compare if they're the same
if [[ $ip == $old_ip ]]; then
logger "DDNS Updater: IP ($ip) for ${record_name} has not changed."
exit 0
fi
########################################### ###########################################
## Set the record identifier from result ## Set the record identifier from result
########################################### ###########################################

Loading…
Cancel
Save