mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-31 01:15:13 +08:00
🐶 Sync 2026-03-30 14:49:16
This commit is contained in:
1 parent
3b5915fae8
commit
4f3a77ef9c
9 files changed
+110
-187
No files matched your search
@@ -1,8 +1,6 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
#
|
||||
# Copyright (C) 2015 OpenWrt-dist
|
||||
# Copyright (C) 2016 fw867 <ffkykzs@gmail.com>
|
||||
# Copyright (C) 2024 iv7777 <hongba@rocketmail.com>
|
||||
# Copyright (C) 2025 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
# See /LICENSE for more information.
|
||||
@@ -13,75 +11,54 @@ CONFIG=timewol
|
||||
CRONTAB_FILE="/etc/crontabs/root"
|
||||
ETHERWAKE_CMD="/usr/bin/etherwake"
|
||||
|
||||
# Function to get UCI configuration values with defaults
|
||||
uci_get_by_type() {
|
||||
local type=$1
|
||||
local option=$2
|
||||
local default=$3
|
||||
local index=${4:-0} # Use 0 if $4 is not provided
|
||||
|
||||
local value
|
||||
value=$(uci get "$CONFIG.@$type[$index].$option" 2>/dev/null) || value=$default
|
||||
echo "$value"
|
||||
config_n_get() {
|
||||
local ret=$(uci -q get "${CONFIG}.${1}.${2}" 2>/dev/null)
|
||||
echo "${ret:=$3}"
|
||||
}
|
||||
|
||||
# Function to check if a value represents a true boolean
|
||||
is_true() {
|
||||
case "$1" in
|
||||
1|on|true|yes|enabled) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
case "$1" in
|
||||
1|on|true|yes|enabled) return 0 ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Function to load configuration and check if enabled
|
||||
load_config() {
|
||||
local enabled
|
||||
enabled=$(uci_get_by_type basic enable "0")
|
||||
is_true "$enabled"
|
||||
local enabled=$(config_n_get @basic[0] enable 0)
|
||||
is_true "$enabled"
|
||||
}
|
||||
|
||||
# Function to add WoL rules to the crontab
|
||||
add_rule() {
|
||||
# Remove existing etherwake entries
|
||||
sed -i '/etherwake/d' "$CRONTAB_FILE"
|
||||
sed -i '/etherwake/d' "$CRONTAB_FILE"
|
||||
|
||||
for i in $(seq 0 100); do
|
||||
local macaddr
|
||||
local maceth
|
||||
local minute
|
||||
local hour
|
||||
local day
|
||||
local month
|
||||
local weeks
|
||||
|
||||
macaddr=$(uci_get_by_type macclient macaddr "" "$i")
|
||||
maceth=$(uci_get_by_type macclient maceth "" "$i")
|
||||
|
||||
# Stop if no more macaddr entries
|
||||
[ -z "$macaddr" ] && break
|
||||
[ -z "$maceth" ] && break
|
||||
|
||||
minute=$(uci_get_by_type macclient minute "0" "$i")
|
||||
hour=$(uci_get_by_type macclient hour "*" "$i")
|
||||
day=$(uci_get_by_type macclient day "*" "$i")
|
||||
month=$(uci_get_by_type macclient month "*" "$i")
|
||||
weeks=$(uci_get_by_type macclient weeks "*" "$i")
|
||||
|
||||
echo "$minute $hour $day $month $weeks $ETHERWAKE_CMD -D -i $maceth $macaddr" >> "$CRONTAB_FILE"
|
||||
done
|
||||
local ids=$(uci show $CONFIG | grep "=macclient" | awk -F '.' '{print $2}' | awk -F '=' '{print $1}')
|
||||
[ -n "$ids" ] && {
|
||||
for id in $ids; do
|
||||
local enabled=$(config_n_get $id enable 0)
|
||||
local macaddr=$(config_n_get $id macaddr)
|
||||
local maceth=$(config_n_get $id maceth)
|
||||
[ $enabled -eq 1 ] && [ -n "$macaddr" ] && [ -n "$maceth" ] && {
|
||||
local minute=$(config_n_get $id minute "0")
|
||||
local hour=$(config_n_get $id hour "*")
|
||||
local day=$(config_n_get $id day "*")
|
||||
local month=$(config_n_get $id month "*")
|
||||
local weeks=$(config_n_get $id weeks "*")
|
||||
echo "$minute $hour $day $month $weeks $ETHERWAKE_CMD -D -i $maceth $macaddr" >> "$CRONTAB_FILE"
|
||||
}
|
||||
done
|
||||
}
|
||||
}
|
||||
|
||||
# Function to start the service
|
||||
start() {
|
||||
if load_config; then
|
||||
add_rule
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
if load_config; then
|
||||
add_rule
|
||||
/etc/init.d/cron restart
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to stop the service
|
||||
stop() {
|
||||
# Remove etherwake entries from crontab
|
||||
sed -i '/etherwake/d' "$CRONTAB_FILE"
|
||||
sed -i '/etherwake/d' "$CRONTAB_FILE"
|
||||
/etc/init.d/cron restart
|
||||
}
|
||||
Reference in new issue
Block a user