summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Compton <davecompton7@gmail.com>2024-08-12 12:13:31 -0700
committerDave Compton <davecompton7@gmail.com>2024-08-12 12:13:31 -0700
commit5c219e8f9674dfad3f6b106e2125754feb58b902 (patch)
tree754bcd385dcbc75ea933737f4cbea69831e8ce7a
parent3ff9340be1cd9d9fcd76c0f0324f0f39deee7563 (diff)
better error checking when fail to add A record
-rwxr-xr-xdyndns.bash10
1 files changed, 7 insertions, 3 deletions
diff --git a/dyndns.bash b/dyndns.bash
index 91261ec..280e2dc 100755
--- a/dyndns.bash
+++ b/dyndns.bash
@@ -37,7 +37,6 @@ get_a_record_ids() {
}
add_a_record() {
- echo adding new A record for $DIGITALOCEAN_DOMAIN with value : $IP
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
@@ -51,7 +50,7 @@ add_a_record() {
,\"flags\":null \
,\"tag\":null \
}" \
- "https://api.digitalocean.com/v2/domains/$DIGITALOCEAN_DOMAIN/records" > /dev/null 2>&1
+ "https://api.digitalocean.com/v2/domains/$DIGITALOCEAN_DOMAIN/records" 2> /dev/null | jq '.domain_record.id'
}
delete_record_by_id() {
@@ -67,7 +66,12 @@ replace_a_record() {
delete_record_by_id $id
done
- add_a_record
+ new_record_id=`add_a_record`
+ if [ "$new_record_id" == "null" ] ; then
+ echo unable to add new A record for $DIGITALOCEAN_DOMAIN with value : $1
+ return 1
+ fi
+ echo added new A record for $DIGITALOCEAN_DOMAIN with value : $1
}