Skip to content

Instantly share code, notes, and snippets.

@luqmana
Last active December 29, 2017 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luqmana/7f96a10e56428ddb0e20cb6acdf475e5 to your computer and use it in GitHub Desktop.
Save luqmana/7f96a10e56428ddb0e20cb6acdf475e5 to your computer and use it in GitHub Desktop.
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment