🎉 Sync 2026-06-28 20:31:01

This commit is contained in:
github-actions[bot] committed 2026-06-28 20:31:01 +08:00
1 parent 31880da43f
commit 15bc162efb
24 files changed
+279 -227

No files matched your search

+87
View File
@@ -8,6 +8,9 @@ START=99
STOP=10
USE_PROCD=1
CRON_FILE="/etc/crontabs/root"
CRON_TAG="# ssw-schedule"
load_config_gpio(){
local gpio value
for c in gpio value; do
@@ -39,6 +42,82 @@ _apply_modem_state(){
sleep 30 && reload_iface &
}
# Parse "HH:MM" -> cron fields "MM HH"
time_to_cron(){
local t="$1" h m
h="${t%%:*}"
m="${t##*:}"
h=$(echo "$h" | sed 's/^0*//')
m=$(echo "$m" | sed 's/^0*//')
[ -z "$h" ] && h=0
[ -z "$m" ] && m=0
printf "%s %s" "$m" "$h"
}
# Add duration minutes to "HH:MM", output as cron "MM HH"
time_add_min(){
local t="$1" dur="$2" h m total_min
h="${t%%:*}"
m="${t##*:}"
h=$(echo "$h" | sed 's/^0*//')
m=$(echo "$m" | sed 's/^0*//')
[ -z "$h" ] && h=0
[ -z "$m" ] && m=0
total_min=$(( h * 60 + m + dur ))
h=$(( total_min / 60 % 24 ))
m=$(( total_min % 60 ))
printf "%s %s" "$m" "$h"
}
# Build cron day/month/weekday fields from period settings
# Outputs: "dom month dow"
cron_period_fields(){
local period="$1"
local period_days="$2"
local weekday="$3"
case "$period" in
daily) echo "* * *" ;;
weekly) echo "* * ${weekday:-1}" ;;
monthly) echo "1 * *" ;;
interval) echo "*/${period_days:-1} * *" ;;
*) echo "* * *" ;;
esac
}
update_cron(){
local s_enable s_period s_time_on s_duration s_period_days s_weekday
config_get s_enable schedule enable "0"
config_get s_period schedule period "daily"
config_get s_time_on schedule time_on "00:00"
config_get s_duration schedule duration "0"
config_get s_period_days schedule period_days "1"
config_get s_weekday schedule weekday "1"
# Remove old ssw entries
sed -i "/$CRON_TAG/d" "$CRON_FILE" 2>/dev/null
[ "$s_enable" != "1" ] && {
/etc/init.d/cron reload 2>/dev/null
return
}
local fields cron_on cron_off
fields=$(cron_period_fields "$s_period" "$s_period_days" "$s_weekday")
cron_on=$(time_to_cron "$s_time_on")
cron_off=$(time_add_min "$s_time_on" "$s_duration")
printf "%s %s /usr/share/ssw_schedule.sh %s\n" \
"$cron_on" "$fields" "$CRON_TAG" >> "$CRON_FILE"
if [ "$s_duration" -gt 0 ] 2>/dev/null; then
printf "%s %s /usr/share/ssw_schedule.sh revert %s\n" \
"$cron_off" "$fields" "$CRON_TAG" >> "$CRON_FILE"
fi
/etc/init.d/cron reload 2>/dev/null
logger -t "SW SIM" "Schedule updated: on=${s_time_on} duration=${s_duration}min period=${s_period}"
}
start_service(){
config_load ssw
config_foreach load_config_gpio modem
@@ -62,13 +141,21 @@ start_service(){
_apply_modem_state
fi
update_cron
procd_open_instance
procd_set_param command /usr/share/ssw_track.sh
procd_close_instance
}
stop_service(){
sed -i "/$CRON_TAG/d" "$CRON_FILE" 2>/dev/null
/etc/init.d/cron reload 2>/dev/null
}
reload_service(){
config_load ssw
update_cron
start_service
}