summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamón M. Gómez <ramongomez@us.es>2020-02-27 14:16:16 +0100
committerRamón M. Gómez <ramongomez@us.es>2020-02-27 14:16:16 +0100
commitda8fdfcde851bbb17295ad9215ce1c634a1fa0a8 (patch)
treea1b0d93a1296d13bb4dfbd40822395046175280a
parentff019d56b104ca42cad4e0993b4f2e7b7b730bb9 (diff)
#955: `addtodhcp` script checks if all routers are defined in DHCP configuration file.
-rwxr-xr-xserver/bin/addtodhcp9
1 files 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