small-package/luci-app-autotimeset/root/etc/init.d/autotimeset

123 lines
5.1 KiB
Plaintext
Raw Normal View History

2021-09-24 23:37:27 +08:00
#!/bin/sh /etc/rc.common
#copyright by sirpdboy
START=95
STOP=10
2023-05-21 23:35:11 +08:00
TMP=/etc/autotimeset
2023-07-15 23:35:34 +08:00
LOG=$TMP/autotimeset.log
2023-05-25 16:21:42 +08:00
TT=/etc/init.d/autotimesetrun
CR=/etc/crontabs/root
2023-05-21 23:35:11 +08:00
[ ! -d $TMP ] && mkdir -p $TMP 2>/dev/null
2024-03-12 00:13:36 +08:00
[ -s $LOG ] && echo -e '' >> $LOG
2021-09-24 23:37:27 +08:00
run_autotimeset()
{
2023-01-15 20:16:49 +08:00
ssum=$(grep -c stime /etc/config/autotimeset)
2024-03-12 00:13:36 +08:00
[ `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
2023-01-15 20:16:49 +08:00
for i in $(seq 0 $((ssum-1)))
do
enable=$(uci -q get autotimeset.@stime[$i].enable )
2023-05-21 23:35:11 +08:00
if [ "x$enable" = "x1" ]; then
month=$(uci -q get autotimeset.@stime[$i].month ) || month="*"
2023-01-15 20:16:49 +08:00
stype=$(uci -q get autotimeset.@stime[$i].stype )
2023-05-21 23:35:11 +08:00
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="*"
2023-05-25 16:21:42 +08:00
ttype=$(uci -q get autotimeset.@stime[$i].ttype ) || ttype=0
delay=$(uci -q get autotimeset.@stime[$i].delay ) || delay=10
2023-05-21 23:35:11 +08:00
[ "x$hour" = "x0" ] && hour="00"
[ "x$minute" = "x0" ] && minute="00"
2023-01-15 20:16:49 +08:00
case "$stype" in
1)
2023-05-25 16:21:42 +08:00
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
2023-01-15 20:16:49 +08:00
;;
2)
2023-05-25 16:21:42 +08:00
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
2023-01-15 20:16:49 +08:00
;;
3)
2023-05-25 16:21:42 +08:00
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
2023-01-15 20:16:49 +08:00
;;
4)
2023-05-25 16:21:42 +08:00
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
2023-01-15 20:16:49 +08:00
;;
5)
2023-05-25 16:21:42 +08:00
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
2023-01-15 20:16:49 +08:00
;;
6)
2023-05-25 16:21:42 +08:00
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
2023-01-15 20:16:49 +08:00
;;
7)
2023-05-25 16:21:42 +08:00
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
2023-01-15 20:16:49 +08:00
;;
8)
2023-05-25 16:21:42 +08:00
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
2023-01-15 20:16:49 +08:00
;;
2023-01-20 20:19:19 +08:00
9)
2023-05-25 16:21:42 +08:00
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
2023-05-21 23:35:11 +08:00
;;
10)
2023-07-15 23:35:34 +08:00
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)
2023-05-25 16:21:42 +08:00
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
2023-05-21 23:35:11 +08:00
;;
2023-07-15 23:35:34 +08:00
12)
2023-05-25 16:21:42 +08:00
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
2023-01-20 20:19:19 +08:00
;;
2024-03-12 00:13:36 +08:00
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
;;
2024-03-23 04:15:49 +08:00
14)
2024-03-12 00:13:36 +08:00
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
;;
2024-03-23 04:15:49 +08:00
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
;;
2023-01-15 20:16:49 +08:00
esac
2021-09-24 23:37:27 +08:00
fi
2023-01-15 20:16:49 +08:00
done
2021-09-24 23:37:27 +08:00
}
start()
2022-09-06 20:23:01 +08:00
{
del_cru
2023-05-25 16:21:42 +08:00
[ -n "`tail -c1 $CR`" ] && echo >> $CR
2023-01-15 20:16:49 +08:00
run_autotimeset
2024-03-12 00:13:36 +08:00
echo '}' >>$TT
2022-09-06 20:23:01 +08:00
/etc/init.d/cron reload
2021-09-24 23:37:27 +08:00
}
stop()
{
del_cru
2024-03-12 00:13:36 +08:00
echo '}' >>$TT
2023-01-15 20:16:49 +08:00
/etc/init.d/cron reload
2021-09-24 23:37:27 +08:00
}
2022-09-06 20:23:01 +08:00
restart()
{
start
}
2021-09-24 23:37:27 +08:00
del_cru()
2024-03-12 00:13:36 +08:00
{
echo -e '#!/bin/sh /etc/rc.common\n\nSTART=99\nstart(){\necho "Service autotimesetrun started! " >> $LOG\n' > $TT
2023-05-25 16:21:42 +08:00
sed -i '/timesethandler/d' $CR >/dev/null 2>&1
2021-09-24 23:37:27 +08:00
}