diff options
author | Ramón M. Gómez <ramongomez@us.es> | 2020-02-27 14:16:16 +0100 |
---|---|---|
committer | Ramón M. Gómez <ramongomez@us.es> | 2020-02-27 14:16:16 +0100 |
commit | da8fdfcde851bbb17295ad9215ce1c634a1fa0a8 (patch) | |
tree | a1b0d93a1296d13bb4dfbd40822395046175280a | |
parent | ff019d56b104ca42cad4e0993b4f2e7b7b730bb9 (diff) |
#955: `addtodhcp` script checks if all routers are defined in DHCP configuration file.
-rwxr-xr-x | server/bin/addtodhcp | 9 |
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 |