ddns-start.sh
#!/bin/sh | |
# Digital Ocean Dynamic DNS Script | |
# | |
# Updates an A record using Digital Oceans DNS Managment API | |
# | |
# Args: | |
# $1 - WAN IP | |
# Generate token at https://cloud.digitalocean.com/settings/api/tokens | |
TOKEN=<INSERT TOKEN HERE> | |
# The domain to be updating | |
DOMAIN=luqman.ca | |
# The record to be updating (i.e. the subdomain on $DOMAIN) | |
RECORD=hitoret.home | |
# Location of jq binary | |
JQ=/jffs/scripts/jq | |
# Now to grab the record id | |
RID=$(curl -s -X GET -H "Authorization: Bearer $TOKEN" "https://api.digitalocean.com/v2/domains/$DOMAIN/records" | $JQ ".[\"domain_records\"] | .[] | select(.name==\"$RECORD\") | .id") | |
if [ "$?" -ne "0" ]; then | |
/sbin/ddns_custom_updated 0 | |
exit 1 | |
fi | |
# And update the record | |
curl -s -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" -d "{\"data\":\"$1\"}" "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RID" | |
if [ "$?" -ne "0" ]; then | |
/sbin/ddns_custom_updated 0 | |
exit 2 | |
fi | |
# And we're done! | |
/sbin/ddns_custom_updated 1 |