Browse Source

🚀

master
Jan Koppe 5 months ago
parent
commit
a036275ce4
Signed by: j <post@jankoppe.de> GPG Key ID: BE935B0735A2129B
1 changed files with 21 additions and 0 deletions
  1. +21
    -0
      do-dyndns.sh

+ 21
- 0
do-dyndns.sh View File

@@ -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

Loading…
Cancel
Save