🌴 Sync 2026-03-05 23:51:42

This commit is contained in:
github-actions[bot] committed 2026-03-05 23:51:42 +08:00
1 parent 97c049ed0a
commit 0acff03804
14253 files changed
+3893239

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=mwan3-ledhelper
PKG_VERSION:=0.0.1
PKG_RELEASE:=1
PKG_MAINTAINER:=Konstantine Shevlakov <shevlakov@132lan.ru>
include $(INCLUDE_DIR)/package.mk
define Package/$(PKG_NAME)
PKGARCH:=all
TITLE:=MWAN3 Led Helper
DEPENDS:=+mwan3
endef
define Package/$(PKG_NAME)/description
Hotplug script to indicate led for mwan3 link states
endef
define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/$(PKG_NAME)/install
$(CP) ./root/* $(1)/
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
@@ -0,0 +1,4 @@
config led 'modem'
option iface 'modem' # mwan3 tracking interface
option led_on 'blue:wan' # flash led on online state (offlline is disable)
option led_off 'red:wan' # flash led on offline state (online is disable)
@@ -0,0 +1,78 @@
#!/bin/sh
mwan3_led_trigger() {
local INTERFACE="$1"
local ACTION="$2"
# LED state function
set_led() {
local led_name="$1"
local value="$2"
local led_path="/sys/class/leds/${led_name}/brightness"
# Set state LED
echo "$value" > "$led_path" 2>/dev/null
}
# Get config values
handle_led_config() {
local iface led_on led_off
config_get iface "$1" iface
config_get led_on "$1" led_on
config_get led_off "$1" led_off
# Check interface
[ "$iface" != "$INTERFACE" ] && return
case "$ACTION" in
connected)
# Selected LED led_on
set_led "$led_on" 255
# if defined led_off
[ -n "$led_off" ] && set_led "$led_off" 0
;;
disconnected)
if [ -n "$led_off" ]; then
# if defined led_off
set_led "$led_off" 255
fi
# Off flashing LED led_on
set_led "$led_on" 0
;;
ifdown)
set_led "$led_on" 0
if [ -n "$led_off" ]; then
set_led "$led_off" 0
fi
;;
esac
}
# get config
config_load mwan3_led
config_foreach handle_led_config led
}
[ -f "/etc/config/mwan3_led" ] && {
. /lib/functions.sh
. /lib/mwan3/mwan3.sh
initscript=/etc/init.d/mwan3
. /lib/functions/procd.sh
[ "$MWAN3_SHUTDOWN" != 1 ] && procd_lock
[ "$MWAN3_SHUTDOWN" != 1 ] && ! /etc/init.d/mwan3 running && {
exit 0
}
config_load mwan3
config_get_bool enabled "$INTERFACE" enabled 0
[ "${enabled}" -eq 1 ] || {
exit 0
}
mwan3_led_trigger $INTERFACE $ACTION
}
exit 0
+107
View File
@@ -0,0 +1,107 @@
#!/bin/sh
usage() {
echo "Usage: $0 -i <interface1> [interface2 ...] -l <led1> [led2 ...] [-o <led_off1> [led_off2 ...]]"
exit 1
}
# Parse arguments
parse_args() {
while [ $# -gt 0 ]; do
case "$1" in
-i)
shift
while [ $# -gt 0 ] && [ "$(echo "$1" | cut -c1)" != "-" ]; do
interfaces="$interfaces $1"
shift
done
;;
-l)
shift
while [ $# -gt 0 ] && [ "$(echo "$1" | cut -c1)" != "-" ]; do
leds_on="$leds_on $1"
shift
done
;;
-o)
shift
while [ $# -gt 0 ] && [ "$(echo "$1" | cut -c1)" != "-" ]; do
leds_off="$leds_off $1"
shift
done
;;
*)
usage
;;
esac
done
}
# Validate and adjust parameters
check_counts() {
# Count interfaces and LEDs
count_int=$(echo "$interfaces" | awk '{print NF}')
count_on=$(echo "$leds_on" | awk '{print NF}')
if [ "$count_int" -eq 0 ]; then
echo "Error: at least one interface must be specified"
usage
fi
if [ "$count_on" -eq 0 ]; then
echo "Error: at least one LED must be specified with -l"
usage
fi
# If more LEDs than interfaces, limit LEDs to match interfaces
if [ "$count_on" -gt "$count_int" ]; then
leds_on=$(echo "$leds_on" | awk -v n="$count_int" '{for(i=1;i<=n;i++) printf "%s ", $i; print ""}')
count_on="$count_int"
fi
# If more off LEDs than interfaces, limit off LEDs to match interfaces
if [ -n "$leds_off" ]; then
count_off=$(echo "$leds_off" | awk '{print NF}')
if [ "$count_off" -gt "$count_int" ]; then
leds_off=$(echo "$leds_off" | awk -v n="$count_int" '{for(i=1;i<=n;i++) printf "%s ", $i; print ""}')
fi
fi
}
# Generate configuration
generate_config() {
echo "$interfaces" | awk -v leds_on="$leds_on" -v leds_off="$leds_off" '
BEGIN {
split(leds_on, on_arr, " ")
split(leds_off, off_arr, " ")
}
{
for (i = 1; i <= NF; i++) {
if (leds_on != "" && i <= length(on_arr) || leds_off != "" && i <= length(off_arr)) {
print "config led '\''" $i "'\''"
print " option iface '\''" $i "'\''"
if (leds_on != "" && i <= length(on_arr)) {
print " option led_on '\''" on_arr[i] "'\''"
}
if (leds_off != "" && i <= length(off_arr)) {
print " option led_off '\''" off_arr[i] "'\''"
}
}
print ""
}
}'
}
# Main program
main() {
if [ $# -eq 0 ]; then
usage
fi
parse_args "$@"
check_counts
generate_config
}
main "$@"