Last active
February 17, 2017 10:28
-
-
Save trnila/fa2375dfdc8a0140ebc9b58cc552553a to your computer and use it in GitHub Desktop.
Create or update AAAA dns record on cloudflare
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/bash | |
[email protected] | |
pass=insert_apikey | |
zone_id=insert_zone_id | |
domain=$(hostname --fqdn) | |
addr=$(ip a | grep 'inet6 2001' | awk '{print $2}' | cut -d '/' -f 1) | |
if [ "$domain" == "arch" ]; then | |
echo "not updating" | |
exit | |
fi | |
if [ "$(dig "$domain" +short AAAA)" == "$addr" ]; then | |
echo "Ip address not need to be updated" | |
exit | |
fi | |
id=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?name=$domain&type=AAAA" \ | |
-H "X-Auth-Email: $user" \ | |
-H "X-Auth-Key: $pass" \ | |
-H "Content-Type: application/json" | jq .result[0].id -r -e) | |
if [ $? -eq 1 ]; then | |
curl -X POST "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records" \ | |
-H "X-Auth-Email: $user" \ | |
-H "X-Auth-Key: $pass" \ | |
-H "Content-Type: application/json" \ | |
--data '{"type":"AAAA","name":"'${domain}'","content":"'${addr}'","ttl":120,"proxied":false}' | |
else | |
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$id" \ | |
-H "X-Auth-Email: $user" \ | |
-H "X-Auth-Key: $pass" \ | |
-H "Content-Type: application/json" \ | |
--data '{"type":"AAAA","name":"'${domain}'","content":"'${addr}'","ttl":120,"proxied":false}' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment