Fix init script for bandwidthd. Thanks lubek
[openwrt/svn-archive/archive.git] / utils / bandwidthd / files / bandwidthd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 OpenWrt.org
3 START=99
4
5 config_cb() {
6 local cfg_type="$1"
7 local cfg_name="$2"
8
9 case "$cfg_type" in
10 bandwidthd)
11 append cfgs "$cfg_name"
12 ;;
13 esac
14 }
15
16 export_bool() {
17 local option="$1"
18 local section="$2"
19 local _loctmp
20 config_get_bool _loctmp "$section" "$option"
21 if [ -n "$_loctmp" ]; then
22 conffile="${conffile}$option "
23 if [ 1 -eq "$_loctmp" ]; then
24 conffile="${conffile}true"
25 else
26 conffile="${conffile}false"
27 fi
28 conffile="${conffile}\n"
29 fi
30 }
31
32 export_number() {
33 local option="$1"
34 local section="$2"
35 local _loctmp
36 config_get _loctmp "$section" "$option"
37 if [ -n "$_loctmp" ]; then
38 conffile="${conffile}$option ${_loctmp}\n"
39 fi
40 }
41
42 export_string() {
43 local option="$1"
44 local section="$2"
45 local _loctmp
46 config_get _loctmp "$section" "$option"
47 if [ -n "$_loctmp" ]; then
48 conffile="${conffile}$option \"${_loctmp}\"\n"
49 fi
50 }
51
52 start() {
53 local subnet conffile
54
55 [ -d /tmp/bandwidthd ] || mkdir -p /tmp/bandwidthd && cp /www/legend.gif /tmp/bandwidthd/
56 [ -e /htdocs ] || ln -s /tmp/bandwidthd /htdocs
57 [ -e /www/bandwidthd ] || ln -s /tmp/bandwidthd /www/bandwidthd
58 rm -f /tmp/bandwidthd.conf
59 touch /tmp/bandwidthd.conf
60 [ -e /etc/bandwidthd.conf ] || ln -s /tmp/bandwidthd.conf /etc/bandwidthd.conf
61
62
63 config_load bandwidthd
64 for cfg in $cfgs; do
65 config_get subnets $cfg subnets
66 for subnet in $subnets; do
67 conffile="${conffile}subnet ${subnet}\n"
68 done
69 export_string dev $cfg
70 export_number skip_intervals $cfg
71 export_number graph_cutoff $cfg
72 export_bool promiscuous $cfg
73 export_bool output_cdf $cfg
74 export_bool recover_cdf $cfg
75 export_string filter $cfg
76 export_bool graph $cfg
77 export_number meta_refresh $cfg
78 [ -n "$conffile" ] && echo -e "$conffile" >>/tmp/bandwidthd.conf
79 unset conffile
80 done
81 cd /
82 bandwidthd
83 }
84
85 stop() {
86 killall bandwidthd
87 }