blob: 4b6c9b05f9f3b33bafd02ebe79895cdc973e31cf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/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 <add|del|old> <MAC address> <IP address> <hostname>"
}
(( $# != 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
|