Added update-dns-do for DigitalOcean

This commit is contained in:
Eric Renfro 2021-01-30 19:29:25 -05:00
parent 402420472e
commit 4aa7d9c560
Signed by untrusted user who does not match committer: psi-jack
GPG key ID: 14977F3A50D9A5BF

View file

@ -0,0 +1,44 @@
#!/bin/bash
# Internal Initialization
source "${DIP_FUNCTIONS}"
if [[ -r "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_NAME}.conf" ]]; then
source "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_NAME}.conf"
fi
if [[ -r "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_EXEC}.conf" ]]; then
source "${DIP_BASE_DIR}/conf.d/${DIP_AGENT_EXEC}.conf"
fi
if [[ -z "$agent_update_dns_do_token" ]]; then
logerr "ERROR: Need 'agent_update_dns_do_token' to be defined to your DigitalOcean API Access Token"
exit 99
fi
if [[ -z "$agent_update_dns_do_domain" ]]; then
logerr "ERROR: Need 'agent_update_dns_do_domain' to be defined to your DigitalOcean Domain Name"
exit 99
fi
# Main
if valid_ipv4 "$DIP_CUR_IP"; then
log "Updating DigitalOcean DNS IPv4 Record: ${DIP_RECORD} to ${DIP_CUR_IP}"
record_id4=$(curl --silent --request GET --header "Content-Type: application/json" --header "Authorization: Bearer $agent_update_dns_do_token" "https://api.digitalocean.com/v2/domains/$agent_update_dns_do_domain/records" | jq ".domain_records[] | select(.name==\"${DIP_RECORD}\" and .type==\"A\") | .id")
if [[ -n "$record_id4" ]]; then
curl --silent -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $agent_update_dns_do_token" -d '{"data":"'$DIP_CUR_IP'"}' "https://api.digitalocean.com/v2/domains/$agent_update_dns_do_domain/records/$record_id4" > /dev/null;
fi
fi
if valid_ipv6 "$DIP_CUR_IP"; then
log "Updating DigitalOcean DNS IPv6 Record: ${DIP_RECORD} to ${DIP_CUR_IP}"
record_id6=$(curl --silent --request GET --header "Content-Type: application/json" --header "Authorization: Bearer $agent_update_dns_do_token" "https://api.digitalocean.com/v2/domains/$agent_update_dns_do_domain/records" | jq ".domain_records[] | select(.name==\"${DIP_RECORD}\" and .type==\"AAAA\") | .id")
if [[ -n "$record_id6" ]]; then
curl --silent -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $agent_update_dns_do_token" -d '{"data":"'$DIP_CUR_IP'"}' "https://api.digitalocean.com/v2/domains/$agent_update_dns_do_domain/records/$record_id6" > /dev/null;
fi
fi