diff --git a/devops/renew-cf-dns-record.sh b/devops/renew-cf-dns-record.sh new file mode 100644 index 0000000..f714c47 --- /dev/null +++ b/devops/renew-cf-dns-record.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +if [ "$#" -lt 5 ] ;then + echo "Renew Cloudflare DNS Record" + echo + echo " Usage: $0 " + exit +fi + +EMAIL=$1 +API_KEY=$2 +ZONE_ID=$3 +RECORD_ID=$4 +DOMAIN=$5 + +IP=$(curl -s https://myip.ipip.net | awk -F':' '{print $2}' | awk -F' ' '{print $1}') +grep -qF "$IP" /tmp/myip && echo "Unchanged since last renewal, do nothing" && exit + +curl -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \ + -H "X-Auth-Email: $EMAIL" \ + -H "X-Auth-Key: $API_KEY" \ + -H "Content-Type: application/json" \ + --data '{"type": "A", "name": "'"$DOMAIN"'", "content": "'"$IP"'"}' + +echo "$IP" > /tmp/myip \ No newline at end of file