123 lines
5.1 KiB
Bash
123 lines
5.1 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
#copyright by sirpdboy
|
|
|
|
START=95
|
|
STOP=10
|
|
TMP=/etc/autotimeset
|
|
LOG=$TMP/autotimeset.log
|
|
TT=/etc/init.d/autotimesetrun
|
|
CR=/etc/crontabs/root
|
|
[ ! -d $TMP ] && mkdir -p $TMP 2>/dev/null
|
|
[ -s $LOG ] && echo -e '' >> $LOG
|
|
run_autotimeset()
|
|
{
|
|
ssum=$(grep -c stime /etc/config/autotimeset)
|
|
[ `uci -q get autotimeset.@global[0].customscript | wc -l ` > 0 ] && uci -q get autotimeset.@global[0].customscript > /etc/autotimeset/timesetcustomscript
|
|
[ `uci -q get autotimeset.@global[0].customscript2 | wc -l ` > 0 ] && uci -q get autotimeset.@global[0].customscript2 > /etc/autotimeset/timesetcustomscript2
|
|
for i in $(seq 0 $((ssum-1)))
|
|
do
|
|
enable=$(uci -q get autotimeset.@stime[$i].enable )
|
|
if [ "x$enable" = "x1" ]; then
|
|
month=$(uci -q get autotimeset.@stime[$i].month ) || month="*"
|
|
stype=$(uci -q get autotimeset.@stime[$i].stype )
|
|
week=$(uci -q get autotimeset.@stime[$i].week ) || week="*"
|
|
minute=$(uci -q get autotimeset.@stime[$i].minute ) || minute="00"
|
|
hour=$(uci -q get autotimeset.@stime[$i].hour ) || hour="*"
|
|
ttype=$(uci -q get autotimeset.@stime[$i].ttype ) || ttype=0
|
|
delay=$(uci -q get autotimeset.@stime[$i].delay ) || delay=10
|
|
[ "x$hour" = "x0" ] && hour="00"
|
|
[ "x$minute" = "x0" ] && minute="00"
|
|
case "$stype" in
|
|
1)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler reboot Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler reboot Startup_task" >>$TT
|
|
;;
|
|
2)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler poweroff Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler poweroff Startup_task" >>$TT
|
|
;;
|
|
3)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler network Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler network Startup_task" >>$TT
|
|
;;
|
|
4)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler restartsamba Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler restartsamba Startup_task" >>$TT
|
|
;;
|
|
5)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler restartwan Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler restartwan Startup_task" >>$TT
|
|
;;
|
|
6)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler closewan Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler closewan Startup_task" >>$TT
|
|
;;
|
|
7)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler clearmem Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler clearmem Startup_task" >>$TT
|
|
;;
|
|
8)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler sysfree Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler reboot Startup_task" >>$TT
|
|
;;
|
|
9)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler disreconn Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler disreconn Startup_task" >>$TT
|
|
;;
|
|
10)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler disrereboot Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler disrereboot Startup_task" >>$TT
|
|
;;
|
|
11)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler restartmwan3 Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler restartmwan3 Startup_task" >>$TT
|
|
;;
|
|
12)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler customscript Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler customscript Startup_task" >>$TT
|
|
;;
|
|
13)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler upwifi Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler upwifi Startup_task" >>$TT
|
|
;;
|
|
14)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler downwifi Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler downwifi Startup_task" >>$TT
|
|
;;
|
|
15)
|
|
local cmd="$minute $hour * $month $week /usr/bin/timesethandler customscript2 Scheduled_task"
|
|
[ $ttype = '0' ] && echo "$cmd" >> $CR || echo "sleep $delay && /usr/bin/timesethandler customscript2 Startup_task" >>$TT
|
|
;;
|
|
esac
|
|
fi
|
|
done
|
|
}
|
|
|
|
start()
|
|
{
|
|
del_cru
|
|
[ -n "`tail -c1 $CR`" ] && echo >> $CR
|
|
run_autotimeset
|
|
echo '}' >>$TT
|
|
/etc/init.d/cron reload
|
|
}
|
|
|
|
stop()
|
|
{
|
|
del_cru
|
|
echo '}' >>$TT
|
|
/etc/init.d/cron reload
|
|
}
|
|
|
|
restart()
|
|
{
|
|
start
|
|
}
|
|
|
|
del_cru()
|
|
{
|
|
echo -e '#!/bin/sh /etc/rc.common\n\nSTART=99\nstart(){\necho "Service autotimesetrun started! " >> $LOG\n' > $TT
|
|
sed -i '/timesethandler/d' $CR >/dev/null 2>&1
|
|
}
|
|
|