32 lines
1.2 KiB
Bash
Executable File
32 lines
1.2 KiB
Bash
Executable File
#! /bin/bash
|
|
|
|
PASSWORD=""
|
|
DOMAIN=nextia.cloud
|
|
|
|
addresses=$(/usr/sbin/ifconfig eth0 | grep 'inet6.*global>' | awk '{ print $2 }');
|
|
GREAT=0
|
|
add=""
|
|
for address in $addresses;
|
|
do
|
|
echo $address
|
|
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 ) ]] || [[ $1 == "-f" ]] ; 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
|
|
/root/.local/bin/ansible-playbook /root/ansible-notebooks/update-ip.yaml -i /root/ansible-notebooks/hosts.ini -e old_ip6="${hadd::-4}" -e new_ip6="$add"
|
|
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
|
|
#curl --user "nextia365:$PASSWORD" -XPOST http://freedns.afraid.org/nic/update?hostname=$DOMAIN\&myip=$add
|
|
fi
|