From 944fd1a28b07f273bc5e828d0e69724697d4db55 Mon Sep 17 00:00:00 2001 From: Simon Marsh Date: Sat, 2 Dec 2023 11:10:24 +0000 Subject: [PATCH] update virtual script --- scripts/virtual.sh | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/scripts/virtual.sh b/scripts/virtual.sh index 322ffda..2b85282 100755 --- a/scripts/virtual.sh +++ b/scripts/virtual.sh @@ -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 " - exit 1 -fi - name="$1" ipv6="$2" ipv4="$3" +if [ -z "$name" ] || [ -z "$ipv6" ] +then + echo "Usage: $0 name ipv6 " + 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