#!/bin/sh /etc/rc.common
# /init.d/xunlei
START=99

PID='/tmp/run/xunlei.pid'

start() {

	device=$(uci get xunlei.config.device)
	mountpoint="`mount | grep "$device" | awk '{print $3}'`"

	rm -f /tmp/etc/thunder_mounts.cfg
	path="$mountpoint/xunlei/cfg/thunder_mounts.cfg"
	ln -s "$path" /tmp/etc/thunder_mounts.cfg

	[ -f "$PID" ] && stop
	xunlei_config=$(uci get xunlei.config.enable)
	[ $xunlei_config -eq 0 ] &&	exit 0
	/"$mountpoint"/xunlei/portal >> /dev/null 2>&1 &
	sleep 1
	echo $(pgrep -f 'xunlei') > "$PID"
	while [ $(cat "$PID" | wc -w) -eq 0 ]
	do
		echo $(pgrep -f 'xunlei') > "$PID"
		sleep 15
	done
}

stop() {
		[ -e "$PID" ] && {
		kill $(cat "$PID") >> /dev/null 2>&1
		rm -f "$PID"
		}
}

restart() {
	stop
	sleep 1
	start
}


