#!/bin/bash # This script is meant to be called automatically by dnsmasq's dhcp-script directive # but it can also be used to manage the manual insertion and deletion of nodes. # Make sure dnsmasq doesn't come an play against you though. %%MODULESPATH BEEPS=%%BEEPS run_modules(){ for I in ${MODULESPATH}/*-${COMMAND} do $I $@ done eval \$BEEP_$COMMAND } # Yes, it's crude but we'll elaborate later on something more functionnal # ...say something based on Avahi with live beakons node_is_alive(){ ping -c 1 -w 1 $HNAME return $? } # Nodes can either be added or removed. For a thorough description of the mechanism, see # dnsmasq's manpage section concerning dhcp-script old_node(){ if [[ ! node_is_alive ]]; then shift $0 del $* fi } usage(){ echo "$0 is called as follows:" echo "$0 " } (( $# != 3 )) && { usage; exit 1 }; ##### Variables ####### COMMAND=$1 MACADDR=$2 IP=$3 HNAME=$4 ### Beeps: PAUSE=20 START=200 STOP=2000 STEP=200 BEEP_add="$(for I in `seq $START $STEP $STOP`; do echo -n " -f $I -l $PAUSE -r 1 -n"; done)" BEEP_del="$(for I in `seq $STOP -$STEP $START`; do echo -n " -f $I -l $PAUSE -r 1 -n"; done)" BEEP_add="beep ${BEEPS_add%%-n}" BEEP_del="beep ${BEEPS_del%%-n}" ##### Variables END ### if [[ $COMMAND == "old" ]] then old_node $@ else run_modules $@ fi exit 0