aboutsummaryrefslogtreecommitdiff
blob: 9ae348c53f73e75bffe87e1f7a4745178c532853 (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
67
68
69
70
71
72
73
74
75
76
77
#!/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=%%MODULESPATH
BEEPS=%%BEEPS

run_modules(){
	for I in ${MODULESPATH}/*-${COMMAND}
	do
		$I $@
	done
	[ $BEEPS ] && 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(){
	shift
	if [[ node_is_alive  ]]; then
		$0 add $*
	else
		$0 del $*
	fi
}

usage(){
	echo "$0 is called as follows:"
	echo "$0 <add|del|old> <MAC address> <IP address> <hostname>"
}


if [[ $# != 4 ]]; then
#	We just ignore the call without a hostname
#	usage;
#
	exit 0;
fi


##### 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 ${BEEP_add%%-n}"
BEEP_del="beep ${BEEP_del%%-n}"

##### Variables END ###

if [[ $COMMAND == "old" ]]
then
	# we background this since it performs a ping with a 1second timeout
	# on a 256 node system, those seconds add up...
	old_node $@ &
else
	run_modules $@
fi

exit 0