|
|
@@ -0,0 +1,21 @@ |
|
|
|
#!/bin/bash |
|
|
|
|
|
|
|
DOMAIN=${1} |
|
|
|
RECORD=${2} |
|
|
|
API_TOKEN=${3} |
|
|
|
|
|
|
|
[[ ! -z $DOMAIN ]] || exit 1; |
|
|
|
[[ ! -z $RECORD ]] || exit 1; |
|
|
|
[[ ! -z $API_TOKEN ]] || exit 1; |
|
|
|
|
|
|
|
IPV4=$(curl -s https://ip4.seeip.org) |
|
|
|
IPV6=$(curl -s https://ip6.seeip.org) |
|
|
|
|
|
|
|
[[ $IPV4 =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] || exit 1; |
|
|
|
# TODO: validate ipv6 response |
|
|
|
|
|
|
|
ID_IPV4=$(doctl -t ${API_TOKEN} compute domain records list --no-header --format ID,Type,Name ${DOMAIN} | grep ${RECORD} | grep " A " | cut -d' ' -f 1) |
|
|
|
ID_IPV6=$(doctl -t ${API_TOKEN} compute domain records list --no-header --format ID,Type,Name ${DOMAIN} | grep ${RECORD} | grep " AAAA " | cut -d' ' -f 1) |
|
|
|
|
|
|
|
doctl -t ${API_TOKEN} compute domain records update ${DOMAIN} --record-id ${ID_IPV4} --record-data ${IPV4} --record-ttl 60 |
|
|
|
doctl -t ${API_TOKEN} compute domain records update ${DOMAIN} --record-id ${ID_IPV6} --record-data ${IPV6} --record-ttl 60 |