From 29154a258e47acfcca836893dabf6c590cfb866a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Badillo?= Date: Mon, 30 Oct 2023 22:21:48 -0600 Subject: [PATCH] Add script for freedns dynamic dns --- update-ipv6.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 update-ipv6.sh diff --git a/update-ipv6.sh b/update-ipv6.sh new file mode 100755 index 0000000..5261fa5 --- /dev/null +++ b/update-ipv6.sh @@ -0,0 +1,75 @@ +#! /bin/bash + +PASSWORD="" +DOMAIN="" + +usage(){ +cat << EOF +usage: update-ipv6 [OPTIONS] -p [PASSWORD] -d [DOMAIN_NAME] +Dynamic DNS script helper that updates records in freedns.afraid.org if the IPV6 address has been changed. + +Options: + -f Force update in record even if IP hasn't change + --dry Shows if the IP addres has changed without updating it + +EOF +exit 1 + +} + +if [[ $# -lt 4 ]] ; +then + usage +fi + +for option in $@; do + case $option in + -p) + PASSWORD=$2 + shift 2;; + -d) + DOMAIN=$2 + shift 2;; + -f) + FORCE=true;; + --dry) + DRY=true;; + *) + usage;; + esac +done + +echo pass $PASSWORD domain $DOMAIN force $FORCE dry $DRY +exit 0 + +echo $address +if [[ $DRY ]]; then + exit 1; +fi + +addresses=$(/usr/sbin/ifconfig eth0 | grep 'inet6.*global>' | awk '{ print $2 }'); +GREAT=0 +add="" +for address in $addresses; +do + secs=$(/usr/sbin/ip addr show dev eth0 | grep -A1 $address | grep -v $address | awk '{ print $2}') + if [ $GREAT -gt ${secs/sec/} ] || [ $GREAT == 0 ]; + then + GREAT=${secs/sec/} + add=$address + fi + +done + if [[ $add ]] && [[ -z $(grep $add /etc/haproxy/haproxy.cfg ) ]] ; then + hadd=$(cat /etc/haproxy/haproxy.cfg | grep -m 1 'bind.*ssl' | awk '{ print $2 }'); + sed -i s/${hadd::-4}/$add/ /etc/haproxy/haproxy.cfg + date + echo curl --user "nextia365:$PASSWORD" -XPOST http://freedns.afraid.org/nic/update?hostname=$DOMAIN\&myip=$add + curl --user "nextia365:$PASSWORD" -XPOST http://freedns.afraid.org/nic/update?hostname=$DOMAIN\&myip=$add + systemctl restart haproxy + else + echo Unchanged + if [[ $FORCE ]]; then + curl --user "nextia365:$PASSWORD" -XPOST http://freedns.afraid.org/nic/update?hostname=$DOMAIN\&myip=$add + fi + fi