[package] fix btpd init script typo
[packages.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_boot "$cfg" useipv4 "-4"
29         append_bool "$cfg" useipv6 "-6"
30         append_bool "$cfg" emptystart "--empty-start"
31         append_parm "$cfg" port "-p"
32         append_parm "$cfg" directory "-d"
33         append_parm "$cfg" maxpeers "--max-peers"
34         append_parm "$cfg" maxuploads "--max-uploads"
35         append_parm "$cfg" maxkbin "--bw-in"
36         append_parm "$cfg" maxkbout "--bw-out"
37         config_get directory "$cfg" directory
38 }
39
40 start() {
41         include /lib/network
42         config_load btpd
43         args=""
44         config_foreach btpd btpd
45         /usr/bin/btpd $args
46 }
47
48 stop() {
49         include /lib/network
50         config_load btpd
51         args=""
52         config_foreach btpd btpd
53         
54         [ -d $directory ] && args="-d $directory "
55         echo -n "stop btpd "
56         
57         while btcli $args kill ; do
58                 echo -n .
59                 sleep 3
60         done 2>/dev/null
61         
62         killall /usr/bin/btpd > /dev/null 2>&1
63         
64         echo " done"
65         return 0
66 }
67