#!/bin/sh
[ "x$1" = "xcheck" ] || exit 1
NAME=bypass
T_FILE=/etc/bypass
log(){
	 echo "$(date +'%Y-%m-%d %H:%M:%S') By Check Network  :$*" >> /tmp/log/$NAME.log
}

B=0
while ! curl -so /dev/null -m 3 www.taobao.com;do
   [ $B -ge 5 ]&& log "服务重启中...";/etc/init.d/$NAME stop;/etc/init.d/$NAME start
   log "请检查网络,服务重启倒计时：$((5-B))"
   let B++
   sleep 1
done
if [ -z "$(uci -q get $NAME.@global[0].global_server)" ];then
/etc/init.d/$NAME start &
elif [ ! -s $T_FILE/china.txt ] || [ ! -s $T_FILE/china_v6.txt ] || [ ! -s $T_FILE/gfw.list ] ;then
	log "Update IP/GFW files."
	/usr/share/$NAME/update --First &
else
	/etc/init.d/$NAME start &
fi
