From 2080d15c2701a8e808fe3b40300f191657b38ba3 Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Fri, 15 Jan 2021 02:35:13 +0800 Subject: [PATCH] [feature] use cloudflare dns as ddns --- devops/renew-cf-dns-record.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 devops/renew-cf-dns-record.sh 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