[package] add startup script and sample uci configuration file (#5329)
[openwrt/svn-archive/archive.git] / net / btpd / files / btpd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
3 START=99
4
5 append_bool() {
6 local section="$1"
7 local option="$2"
8 local value="$3"
9 local _loctmp
10 config_get_bool _loctmp "$section" "$option"
11 [ "$_loctmp" -gt 0 ] && append args "$value"
12 }
13
14 append_parm() {
15 local section="$1"
16 local option="$2"
17 local switch="$3"
18 local _loctmp
19 config_get _loctmp "$section" "$option"
20 [ -z "$_loctmp" ] && return 0
21 append args "$switch $_loctmp"
22 }
23
24 directory=""
25
26 btpd() {
27 local cfg="$1"
28 append_bool "$cfg" emptystart "--empty-start"
29 append_parm "$cfg" port "-p"
30 append_parm "$cfg" directory "-d"
31 append_parm "$cfg" maxpeers "--max-peers"
32 append_parm "$cfg" maxuploads "--max-uploads"
33 append_parm "$cfg" maxkbin "--bw-in"
34 append_parm "$cfg" maxkbout "--bw-out"
35 config_get directory "$cfg" directory
36 }
37
38 start() {
39 include /lib/network
40 config_load btpd
41 args=""
42 config_foreach btpd btpd
43 /usr/bin/btpd $args
44 }
45
46 stop() {
47 include /lib/network
48 config_load btpd
49 args=""
50 config_foreach btpd btpd
51
52 [ -d $direcotry ] && args="-d $directory "
53 echo -n "stop btpd "
54
55 while btcli $args kill ; do
56 echo -n .
57 sleep 3
58 done 2>/dev/null
59
60 killall /usr/bin/btpd > /dev/null 2>&1
61
62 echo " done"
63 return 0
64 }
65