make ipv6only plugin option boolean. Without this, the value will be written as ...
[feed/routing.git] / oonf-dlep-proxy / files / dlep_proxy.init
1 #!/bin/sh /etc/rc.common
2
3 START=82
4
5 daemon=dlep_proxy
6
7 . /usr/share/libubox/jshn.sh
8
9 oonf_log()
10 {
11 logger -s -t ${daemon} -p daemon.info "$1"
12 }
13
14 oonf_get_layer3_device()
15 {
16 local interface="$1" # e.g. 'mywifi'
17 local status dev proto
18 local query="{ \"interface\" : \"$interface\" }"
19
20 status="$( ubus -S call network.interface status "$query" )" && {
21 json_load "$status"
22 json_get_var 'dev' l3_device
23 json_get_var 'proto' proto
24 case "$proto" in
25 pppoe)
26 # TODO: otherwise it segfaults
27 oonf_log "refusing to add '$interface', because of proto '$proto'"
28 ;;
29 *)
30 echo "$dev" # e.g. 'wlan0-1'
31 ;;
32 esac
33 }
34 }
35
36 oonf_add_devices_to_configuration()
37 {
38 local i=0
39 local device_name= section= interface= single_interface=
40
41 # make a copy of configuration and
42 # add a 'name' (physical name) for all
43 # 'interface-names' (e.g. mywifi)
44 #
45 # olsrd2.@interface[2]=interface
46 # olsrd2.@interface[2].ifname='wan lan wlanadhoc wlanadhocRADIO1'
47
48 # /var is in ramdisc/tmpfs
49 cp /etc/config/${daemon} /var/etc/${daemon}_dev
50
51 while section="$( uci -q -c /etc/config get "${daemon}.@[$i]" )"; do {
52 echo "section: $section"
53
54 interface="$( uci -q -c /etc/config get "${daemon}.@[$i].ifname" )" || {
55 i=$(( $i + 1 ))
56 continue
57 }
58
59 case "$( uci -q get "${daemon}.@[$i].ignore" )" in
60 1|on|true|enabled|yes)
61 oonf_log "removing/ignore section '$section'"
62 uci -q -c /var/etc delete "${daemon}_dev.@[$j]"
63 i=$(( $i + 1 ))
64
65 continue
66 ;;
67 esac
68
69 for single_interface in $interface; do {
70 device_name="$( oonf_get_layer3_device "$single_interface" )"
71
72 echo "Interface: $single_interface = $device_name"
73
74 if [ ! -z "$device_name" ]
75 then
76 # add option 'name' for 'ifname' (e.g. 'mywifi')
77 uci -q -c /var/etc add_list "${daemon}_dev.@[$i].name=$device_name"
78 fi
79 } done
80 i=$(( $i + 1 ))
81 } done
82
83 uci -q -c /var/etc commit ${daemon}_dev
84
85 oonf_log "wrote '/var/etc/${daemon}_dev'"
86 }
87
88 oonf_reread_config()
89 {
90 local pid
91 local pidfile='/var/run/${daemon}.pid'
92
93 if [ -e "$pidfile" ]; then
94 read pid <"$pidfile"
95 elif pidfile="$( uci -q get '${daemon}.@global[0].pidfile' )"; then
96 read pid <"$pidfile"
97 fi
98
99 # if empty, ask kernel
100 pid="${pid:-$( pidof ${daemon} )}"
101
102 [ -n "$pid" ] && kill -SIGHUP $pid
103 }
104
105 start()
106 {
107 oonf_add_devices_to_configuration
108
109 # produce coredumps
110 ulimit -c unlimited
111
112 service_start /usr/sbin/${daemon} --set global.fork=true --load uci:///var/etc/${daemon}_dev
113 }
114
115 stop()
116 {
117 service_stop /usr/sbin/${daemon}
118 }
119
120 reload()
121 {
122 oonf_add_devices_to_configuration
123 oonf_reread_config
124 }