From da8fdfcde851bbb17295ad9215ce1c634a1fa0a8 Mon Sep 17 00:00:00 2001 From: "Ramón M. Gómez" Date: Thu, 27 Feb 2020 14:16:16 +0100 Subject: #955: `addtodhcp` script checks if all routers are defined in DHCP configuration file. --- server/bin/addtodhcp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/bin/addtodhcp b/server/bin/addtodhcp index 039de34d..f39c97b6 100755 --- a/server/bin/addtodhcp +++ b/server/bin/addtodhcp @@ -21,8 +21,9 @@ DHCPCONFBCK="$DHCPCONF-$(date +"%Y%m%d")" source $OPENGNSYS/lib/ogfunctions.sh || exit 1 -# Show help +# Show help or version number. [ "$*" == "help" ] && help +[ "$*" == "version" ] && version # Error control. [ "$USER" != "root" ] && raiseError access "Need to be root" source $SERVERCONF 2>/dev/null || raiseError access "Cannot read OpenGnsys Server configuration file" @@ -61,9 +62,13 @@ while read -pe NAME IP MAC ROUTER LAB; do IP="${IP/10.1./192.168.}" ROUTER="${ROUTER/10.1./192.168.}" fi + # Check if router is defined. + if ! grep -Eq "routers[[:space:]]+$ROUTER" $DHCPCONF; then + raiseError notfound "Router \"$ROUTER\" not defined in DHCP configuration file" + fi # Find any "host" clause. SEDEXPR+="/\bhost $NAME\b/" - if ! grep -q "host $NAME.*}" $DHCPCONF; then + if ! grep -Eq "host[[:space:]]+$NAME[[:space:]]*}" $DHCPCONF; then SEDEXPR+=",/}/" fi if [ "$LAB" != "$LABBCK" ]; then -- cgit v1.2.3-18-g5258