mirror of
https://github.com/kremalicious/dotfiles.git
synced 2024-11-22 01:37:14 +01:00
script tweaks
This commit is contained in:
parent
599dc8ab40
commit
371b9f1749
@ -1,5 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Update Cloudflare DNS record with current detected public IP
|
||||||
|
# https://api.cloudflare.com/#dns-records-for-a-zone-patch-dns-record
|
||||||
|
#
|
||||||
# Required env vars
|
# Required env vars
|
||||||
# CLOUDFLARE_ZONE="xxx"
|
# CLOUDFLARE_ZONE="xxx"
|
||||||
# CLOUDFLARE_DNS_RECORD_ID_A="xxx"
|
# CLOUDFLARE_DNS_RECORD_ID_A="xxx"
|
||||||
@ -7,24 +10,27 @@
|
|||||||
# CLOUDFLARE_EMAIL="xxx"
|
# CLOUDFLARE_EMAIL="xxx"
|
||||||
# CLOUDFLARE_KEY="xxx"
|
# CLOUDFLARE_KEY="xxx"
|
||||||
|
|
||||||
# Update Cloudflare DNS record with current detected public IP
|
function updateIpv4 {
|
||||||
# https://api.cloudflare.com/#dns-records-for-a-zone-patch-dns-record
|
|
||||||
function updateIp {
|
|
||||||
|
|
||||||
# IPv4 A record
|
# IPv4 A record
|
||||||
# https://unix.stackexchange.com/a/81699/125382
|
# https://unix.stackexchange.com/a/81699/125382
|
||||||
IPADDRv4=$(dig @resolver4.opendns.com myip.opendns.com +short)
|
IPADDRv4=$(dig @resolver4.opendns.com myip.opendns.com +short)
|
||||||
|
echo "-----------------------------------------"
|
||||||
echo "Public IPv4: $IPADDRv4"
|
echo "Public IPv4: $IPADDRv4"
|
||||||
|
echo "-----------------------------------------"
|
||||||
|
|
||||||
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/dns_records/$CLOUDFLARE_DNS_RECORD_ID_A" \
|
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/dns_records/$CLOUDFLARE_DNS_RECORD_ID_A" \
|
||||||
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
|
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
|
||||||
-H "X-Auth-Key: $CLOUDFLARE_KEY" \
|
-H "X-Auth-Key: $CLOUDFLARE_KEY" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
--data "{\"content\":\"$IPADDRv4\"}"
|
--data "{\"content\":\"$IPADDRv4\"}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateIpv6 {
|
||||||
# IPv6 AAAA record
|
# IPv6 AAAA record
|
||||||
IPADDRv6=$(dig @resolver1.ipv6-sandbox.opendns.com AAAA myip.opendns.com +short -6)
|
IPADDRv6=$(dig @resolver1.ipv6-sandbox.opendns.com AAAA myip.opendns.com +short -6)
|
||||||
|
echo "-----------------------------------------"
|
||||||
echo "Public IPv6: $IPADDRv6"
|
echo "Public IPv6: $IPADDRv6"
|
||||||
|
echo "-----------------------------------------"
|
||||||
|
|
||||||
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/dns_records/$CLOUDFLARE_DNS_RECORD_ID_AAAA" \
|
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/dns_records/$CLOUDFLARE_DNS_RECORD_ID_AAAA" \
|
||||||
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
|
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
|
||||||
@ -33,4 +39,6 @@
|
|||||||
--data "{\"content\":\"$IPADDRv6\"}"
|
--data "{\"content\":\"$IPADDRv6\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
updateIp
|
# Let's roll
|
||||||
|
updateIpv4
|
||||||
|
updateIpv6
|
Loading…
Reference in New Issue
Block a user