Add interface and filename to ddns script
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
PASSWORD=""
|
PASSWORD=""
|
||||||
DOMAIN=""
|
DOMAIN=""
|
||||||
|
INTERFACE="eth0"
|
||||||
|
FILENAME="/etc/haproxy/haproxy.cfg"
|
||||||
|
|
||||||
usage(){
|
usage(){
|
||||||
cat << EOF
|
cat << EOF
|
||||||
@@ -11,6 +13,8 @@ Dynamic DNS script helper that updates records in freedns.afraid.org if the IPV6
|
|||||||
Options:
|
Options:
|
||||||
-f Force update in record even if IP hasn't change
|
-f Force update in record even if IP hasn't change
|
||||||
--dry Shows if the IP addres has changed without updating it
|
--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
|
EOF
|
||||||
exit 1
|
exit 1
|
||||||
@@ -22,8 +26,8 @@ then
|
|||||||
usage
|
usage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for option in $@; do
|
while [[ ! -z "$1" ]]; do
|
||||||
case $option in
|
case $1 in
|
||||||
-p)
|
-p)
|
||||||
PASSWORD=$2
|
PASSWORD=$2
|
||||||
shift 2;;
|
shift 2;;
|
||||||
@@ -31,28 +35,26 @@ for option in $@; do
|
|||||||
DOMAIN=$2
|
DOMAIN=$2
|
||||||
shift 2;;
|
shift 2;;
|
||||||
-f)
|
-f)
|
||||||
FORCE=true;;
|
FORCE=true
|
||||||
|
shift 1;;
|
||||||
--dry)
|
--dry)
|
||||||
DRY=true;;
|
DRY=true
|
||||||
|
shift 1;;
|
||||||
|
-i)
|
||||||
|
INTERFACE=$2
|
||||||
|
shift 2;;
|
||||||
*)
|
*)
|
||||||
|
echo $option
|
||||||
usage;;
|
usage;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
echo pass $PASSWORD domain $DOMAIN force $FORCE dry $DRY
|
addresses=$(/usr/sbin/ifconfig $INTERFACE | grep 'inet6.*global>' | awk '{ print $2 }');
|
||||||
exit 0
|
|
||||||
|
|
||||||
echo $address
|
|
||||||
if [[ $DRY ]]; then
|
|
||||||
exit 1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
addresses=$(/usr/sbin/ifconfig eth0 | grep 'inet6.*global>' | awk '{ print $2 }');
|
|
||||||
GREAT=0
|
GREAT=0
|
||||||
add=""
|
add=""
|
||||||
for address in $addresses;
|
for address in $addresses;
|
||||||
do
|
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 ];
|
if [ $GREAT -gt ${secs/sec/} ] || [ $GREAT == 0 ];
|
||||||
then
|
then
|
||||||
GREAT=${secs/sec/}
|
GREAT=${secs/sec/}
|
||||||
@@ -60,16 +62,23 @@ do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
if [[ $add ]] && [[ -z $(grep $add /etc/haproxy/haproxy.cfg ) ]] ; then
|
echo $address
|
||||||
hadd=$(cat /etc/haproxy/haproxy.cfg | grep -m 1 'bind.*ssl' | awk '{ print $2 }');
|
if [[ $add ]] && [[ -z $(grep $add $FILENAME ) ]] ; then
|
||||||
sed -i s/${hadd::-4}/$add/ /etc/haproxy/haproxy.cfg
|
hadd=$(grep -o -m 1 'NAT1TO1=[^"]*' $FILENAME | awk 'BEGIN {FS = "=" } ; { print $2 }');
|
||||||
date
|
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
|
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
|
curl --user "nextia365:$PASSWORD" -XPOST http://freedns.afraid.org/nic/update?hostname=$DOMAIN\&myip=$add
|
||||||
systemctl restart haproxy
|
|
||||||
else
|
else
|
||||||
echo Unchanged
|
echo Unchanged
|
||||||
if [[ $FORCE ]]; then
|
if [[ $FORCE ]]; then
|
||||||
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
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
if [[ $DRY ]]; then
|
||||||
|
echo "Address didn't change from $add"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user