Created
September 10, 2023 20:56
-
-
Save tuupola/bd35132d1ce1b4833abfb4f9d688e089 to your computer and use it in GitHub Desktop.
Update GANDI dynamic DNS
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
#!/usr/bin/bash | |
API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
DOMAIN="example.com" | |
SUBDOMAIN="dynamic" | |
CURRENT_IP=$(curl --silent --header "Authorization: Bearer $API_KEY" https://dns.api.gandi.net/api/v5/domains/$DOMAIN/records/$SUBDOMAIN/A | jq -r ".rrset_values[0]") | |
EXTERNAL_IP=$(curl --silent ifconfig.io) | |
JSON=$(cat <<EOF | |
{ | |
"items":[ | |
{"rrset_type":"A", "rrset_values":["${EXTERNAL_IP}"], "rrset_ttl": 900} | |
] | |
} | |
EOF | |
) | |
if [ $CURRENT_IP == $EXTERNAL_IP ]; then | |
echo "Nothing to do." | |
else | |
curl https://api.gandi.net/v5/livedns/domains/$DOMAIN/records/$SUBDOMAIN \ | |
--request PUT \ | |
--header "Authorization: Bearer $API_KEY" \ | |
--header "Content-type: application/json" \ | |
--data "$JSON" \ | |
--silent | |
echo ""; | |
echo "Updated $SUBDOMAIN.$DOMAIN A record to $EXTERNAL_IP." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment