-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudflare-ddns.sh
26 lines (26 loc) · 996 Bytes
/
cloudflare-ddns.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env bash
set -euo pipefail
echo "updating"
if [ -n "${CLOUDFLARE_A_RECORD_IDS:-}" ]; then
addr=$(curl -sS 'https://1.1.1.1/cdn-cgi/trace' | grep 'ip=' | cut -d '=' -f 2)
for rid in $CLOUDFLARE_A_RECORD_IDS; do
echo "${rid} A ${addr}"
curl -sS \
-X PATCH "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/dns_records/${rid}" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H 'Content-Type: application/json' \
--data "{\"content\": \"${addr}\"}"
done
fi
if [ -n "${CLOUDFLARE_AAAA_RECORD_IDS:-}" ]; then
addr=$(curl -sS 'https://[2606:4700:4700::1111]/cdn-cgi/trace' | grep 'ip=' | cut -d '=' -f 2)
for rid in $CLOUDFLARE_AAAA_RECORD_IDS; do
echo "${rid} AAAA ${addr}"
curl -sS \
-X PATCH "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/dns_records/${rid}" \
-H "Authorization: Bearer ${CLOUDFLARE_API_TOKEN}" \
-H 'Content-Type: application/json' \
--data "{\"content\": \"${addr}\"}"
done
fi
echo "done"