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

start() {
	config_load "xunlei"
	
	config_get enable config enable 0
	config_get device config device
	config_get up config up 0
	config_get file config file

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

	rm -f /tmp/etc/thunder_mounts.cfg
	rm -f /tmp/etc/etm.cfg
	rm -f /tmp/etc/download.cfg

	path1="$file/xunlei/cfg/thunder_mounts.cfg"
	path2="$file/xunlei/cfg/etm.cfg"
	path3="$file/xunlei/cfg/download.cfg"
	
	[ "$up" -eq 1 ] && /etc/xware/xlup && /etc/xware/cfg
	[ "$vod" -eq 1 ] && rm -f $file/xunlei/lib/vod_httpserver
	[ "$vod" -eq 1 ] && rm -f $file/xunlei/vod_httpserver

	[ "$enable" -eq 0 ] &&	exit 0

	ln -s "$path1" /tmp/etc/thunder_mounts.cfg
	ln -s "$path2" /tmp/etc/etm.cfg
	ln -s "$path3" /tmp/etc/download.cfg

	$file/xunlei/portal
	sleep 3
    renice -n 19 $(pidof EmbedThunderManager)
}

stop() {
	file=$(uci get xunlei.config.file)
	$file/xunlei/portal -s
}

restart() {
	stop
	sleep 1
	start
}
