Switch to a multihost/home-manager setup
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#!@bash@/bin/bash
|
||||
|
||||
source /run/secrets/main.env
|
||||
|
||||
cache=/var/lib/cloudflare-ddns/old_ip
|
||||
IP=$(@curl@/bin/curl -s 'https://api.ipify.org')
|
||||
arr=("" "git." "www." "acs.")
|
||||
|
||||
if [[ -f "$cache" ]]; then
|
||||
old_ip=$(cat "$cache")
|
||||
else
|
||||
old_ip=""
|
||||
fi
|
||||
|
||||
if [[ "$IP" != "$old_ip" ]]; then
|
||||
for sub in "${arr[@]}"; do
|
||||
RECORD_ID=$(@curl@/bin/curl -s -X GET \
|
||||
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \
|
||||
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
| @jq@/bin/jq -r ".result[] | select(.name==\"${sub}syedm.dev\" and .type==\"A\") | .id")
|
||||
|
||||
if [ -n "$RECORD_ID" ]; then
|
||||
@curl@/bin/curl -s -X PUT \
|
||||
"https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
|
||||
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{\"type\":\"A\",\"name\":\"${sub}syedm.dev\",\"content\":\"$IP\",\"ttl\":3600,\"proxied\":false}"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$IP" > "$cache"
|
||||
fi
|
||||
Reference in New Issue
Block a user