p910nd: map bind (-i) option to uci
[openwrt/svn-archive/archive.git] / net / p910nd / files / p910nd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2007 OpenWrt.org
3 START=50
4
5 append_bool() {
6 local section="$1"
7 local option="$2"
8 local value="$3"
9 local _val
10 config_get_bool _val "$section" "$option" '0'
11 [ "$_val" -gt 0 ] && append args "$3"
12 }
13
14 append_string() {
15 local section="$1"
16 local option="$2"
17 local value="$3"
18 local _val
19 config_get _val "$section" "$option"
20 [ -n "$_val" ] && append args "$3$_val"
21 }
22
23 start_service() {
24 local section="$1"
25 args=""
26
27 append_bool "$section" bidirectional "-b"
28 append_string "$section" device "-f "
29 append_string "$section" bind "-i "
30 append_string "$section" port ""
31 config_get_bool "enabled" "$section" "enabled" '1'
32 [ "$enabled" -gt 0 ] && /usr/sbin/p910nd $args
33 }
34
35 stop_service() {
36 local section="$1"
37 config_get port "$section" port
38
39 PID_F=/var/run/p910${port}d.pid
40 [ -f $PID_F ] && kill $(cat $PID_F)
41 }
42
43 start() {
44 config_load "p910nd"
45 config_foreach start_service p910nd
46 }
47
48 stop() {
49 config_load "p910nd"
50 config_foreach stop_service p910nd
51 }