olsrd: hotplug-script: bugfix: move function calls down, otherwise the functions...
[feed/routing.git] / olsrd / files / olsrd.hotplug.sh
1 #!/bin/sh
2
3 olsrd_list_configured_interfaces()
4 {
5 local i=0
6 local interface
7
8 while interface="$( uci -q get olsrd.@Interface[$i].interface )"; do {
9 case "$( uci -q get olsrd.@Interface[$i].ignore )" in
10 1|on|true|enabled|yes)
11 # is disabled
12 ;;
13 *)
14 echo "$interface"
15 ;;
16 esac
17
18 i=$(( $i + 1 ))
19 } done
20 }
21
22 olsrd_interface_needs_adding()
23 {
24 local interface="$1" # e.g. wlanadhocRADIO1
25 local device="$2" # e.g. wlan1-1
26 local myif
27 local config="/var/etc/olsrd.conf"
28
29 for myif in $(olsrd_list_configured_interfaces); do {
30 [ "$myif" = "$interface" ] && {
31 if grep -s ^'Interface ' "$config" | grep -q "\"$device\""; then
32 logger -t olsrd_hotplug -p daemon.debug "[OK] already_active: $INTERFACE => $DEVICE"
33 return 1
34 else
35 logger -t olsrd_hotplug -p daemon.info "[OK] ifup: $INTERFACE => $DEVICE"
36 return 0
37 fi
38 }
39 } done
40
41 logger -t olsrd_hotplug -p daemon.debug "[OK] interface $INTERFACE not used for olsrd"
42 return 1
43 }
44
45 case "$ACTION" in
46 ifup)
47 /etc/init.d/olsrd enabled && {
48 olsrd_interface_needs_adding "$INTERFACE" "$DEVICE" && {
49 /etc/init.d/olsrd restart
50 }
51 }
52 ;;
53 esac