Add script for freedns dynamic dns
This commit is contained in:
75
update-ipv6.sh
Executable file
75
update-ipv6.sh
Executable file
@@ -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
|
||||||
Reference in New Issue
Block a user