Last active
December 29, 2017 08:02
-
-
Save luqmana/7f96a10e56428ddb0e20cb6acdf475e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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