Add interface and filename to ddns script
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
PASSWORD=""
|
||||
DOMAIN=""
|
||||
INTERFACE="eth0"
|
||||
FILENAME="/etc/haproxy/haproxy.cfg"
|
||||
|
||||
usage(){
|
||||
cat << EOF
|
||||
@@ -11,6 +13,8 @@ Dynamic DNS script helper that updates records in freedns.afraid.org if the IPV6
|
||||
Options:
|
||||
-f Force update in record even if IP hasn't change
|
||||
--dry Shows if the IP addres has changed without updating it
|
||||
-i Interface name default: eth0
|
||||
-F Filename where to compare previous address default= /etc/haproxy/haproxy.cfg
|
||||
|
||||
EOF
|
||||
exit 1
|
||||
@@ -22,8 +26,8 @@ then
|
||||
usage
|
||||
fi
|
||||
|
||||
for option in $@; do
|
||||
case $option in
|
||||
while [[ ! -z "$1" ]]; do
|
||||
case $1 in
|
||||
-p)
|
||||
PASSWORD=$2
|
||||
shift 2;;
|
||||
@@ -31,28 +35,26 @@ for option in $@; do
|
||||
DOMAIN=$2
|
||||
shift 2;;
|
||||
-f)
|
||||
FORCE=true;;
|
||||
FORCE=true
|
||||
shift 1;;
|
||||
--dry)
|
||||
DRY=true;;
|
||||
DRY=true
|
||||
shift 1;;
|
||||
-i)
|
||||
INTERFACE=$2
|
||||
shift 2;;
|
||||
*)
|
||||
echo $option
|
||||
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 }');
|
||||
addresses=$(/usr/sbin/ifconfig $INTERFACE | 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}')
|
||||
secs=$(/usr/sbin/ip addr show dev $INTERFACE | grep -A1 $address | grep -v $address | awk '{ print $2}')
|
||||
if [ $GREAT -gt ${secs/sec/} ] || [ $GREAT == 0 ];
|
||||
then
|
||||
GREAT=${secs/sec/}
|
||||
@@ -60,16 +62,23 @@ do
|
||||
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 $address
|
||||
if [[ $add ]] && [[ -z $(grep $add $FILENAME ) ]] ; then
|
||||
hadd=$(grep -o -m 1 'NAT1TO1=[^"]*' $FILENAME | awk 'BEGIN {FS = "=" } ; { print $2 }');
|
||||
if [[ $DRY ]]; then
|
||||
echo "Address would change from $add to $hadd"
|
||||
exit 1;
|
||||
fi
|
||||
sed -i s/${hadd}/$add/ $FILENAME
|
||||
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
|
||||
if [[ $DRY ]]; then
|
||||
echo "Address didn't change from $add"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user