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