update virtual script

This commit is contained in:
Simon Marsh 2023-12-02 11:10:24 +00:00
parent b9e050f810
commit 944fd1a28b
Signed by: burble
GPG Key ID: E9B4156C1659C079

View File

@ -1,24 +1,26 @@
#!/bin/bash
#!/bin/bash -e
##########################################################################
# where am I ?
SCRIPTPATH="$(cd "$(dirname "$0")" ; pwd -P)"
DYNAMICPATH="$(cd ${SCRIPTPATH}/../dynamic; pwd -P)"
SCRIPTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}")" && pwd)"
DYNAMICPATH="$(dirname "$SCRIPTPATH")/dynamic"
##########################################################################
if [ $# -lt 2 ]
then
echo "Usage: $0 name ipv6 <ipv4>"
exit 1
fi
name="$1"
ipv6="$2"
ipv4="$3"
if [ -z "$name" ] || [ -z "$ipv6" ]
then
echo "Usage: $0 name ipv6 <ipv4>"
exit 1
fi
# strip .burble.dn42 from name if it was included
name=${name%.burble.dn42}
##########################################################################
# the IPv4 arg is optional
if [ -z "$ipv4" ]
then
@ -29,11 +31,12 @@ else
line=$(printf " [ '%s', '%s', '%s' ]," "$name" "$ipv6" "$ipv4")
fi
pushd "$DYNAMICPATH" > /dev/null
##########################################################################
pushd "$DYNAMICPATH" >/dev/null
# don't update if the line already exists
grep -Fx "$line" virtual.js > /dev/null 2>&1
if [ $? -eq 0 ]
if grep -Fx "$line" virtual.js >/dev/null 2>&1
then
echo "DNS: Already exists, no change"
exit 0