This patch adds full support for btpd command line options that are 
automatically pulled from /etc/config ( if there ) otherwise will default 
to daemon defaults.

Signed-off-by: Eric Warnke <[email protected]>
---
 net/btpd/files/btpd.init |   71 ++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/net/btpd/files/btpd.init b/net/btpd/files/btpd.init
index f897c6c..0d12390 100644
--- a/net/btpd/files/btpd.init
+++ b/net/btpd/files/btpd.init
@@ -1,16 +1,65 @@
-#!/bin/sh  /etc/rc.common
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006 OpenWrt.org
+START=99
 
-RUN_D=/var/btpd
+append_bool() {
+       local section="$1"
+       local option="$2"
+       local value="$3"
+       local _loctmp
+       config_get_bool _loctmp "$section" "$option"
+       [ "$_loctmp" -gt 0 ] && append args "$value"
+}
+
+append_parm() {
+       local section="$1"
+       local option="$2"
+       local switch="$3"
+       local _loctmp
+       config_get _loctmp "$section" "$option"
+       [ -z "$_loctmp" ] && return 0
+       append args "$switch $_loctmp"
+}
+
+directory=""
 
-start () {
-    btpd -d $RUN_D
+btpd() {
+       local cfg="$1"
+       append_bool "$cfg" emptystart "--empty-start"
+       append_parm "$cfg" port "-p"
+       append_parm "$cfg" directory "-d"
+       append_parm "$cfg" maxpeers "--max-peers"
+       append_parm "$cfg" maxuploads "--max-uploads"
+       append_parm "$cfg" maxkbin "--bw-in"
+       append_parm "$cfg" maxkbout "--bw-out"
+       config_get directory "$cfg" directory
 }
 
-stop () {
-    echo -n "stop btpd "
-    while btcli -d $RUN_D kill ; do
-        echo -n .
-        sleep 3
-    done 2>/dev/null
-    echo " done"
+start() {
+       include /lib/network
+       config_load btpd
+       args=""
+       config_foreach btpd btpd
+       /usr/bin/btpd $args
 }
+
+stop() {
+       include /lib/network
+       config_load btpd
+       args=""
+       config_foreach btpd btpd
+       
+       [ -d $direcotry ] && args="-d $directory "
+       echo -n "stop btpd "
+       
+       while btcli $args kill ; do
+               echo -n .
+               sleep 3
+       done 2>/dev/null
+       
+       killall /usr/bin/btpd > /dev/null 2>&1
+       
+       echo " done"
+       return 0
+}
+
-- 
1.5.5.6

_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to