From 1fd74364fac592a3b56aa9e2b6e210aa2af5660c Mon Sep 17 00:00:00 2001 From: Suvendhu Hansa Date: Thu, 11 Sep 2025 13:25:27 +0530 Subject: [PATCH] wifidmd: add external apply handler --- wifidmd/bbfdm_service.json | 11 +++++ .../files/etc/wifidmd/bbf_config_reload.sh | 44 ++++++++----------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/wifidmd/bbfdm_service.json b/wifidmd/bbfdm_service.json index 329d60b2f..f517c32e9 100644 --- a/wifidmd/bbfdm_service.json +++ b/wifidmd/bbfdm_service.json @@ -11,6 +11,17 @@ ], "config": { "loglevel": "3" + }, + "apply_handler": { + "uci": [ + { + "file": [ + "wireless", + "mapcontroller" + ], + "external_handler": "/etc/wifidmd/bbf_config_reload.sh" + } + ] } } } diff --git a/wifidmd/files/etc/wifidmd/bbf_config_reload.sh b/wifidmd/files/etc/wifidmd/bbf_config_reload.sh index e89902848..b78f6c76e 100755 --- a/wifidmd/files/etc/wifidmd/bbf_config_reload.sh +++ b/wifidmd/files/etc/wifidmd/bbf_config_reload.sh @@ -2,27 +2,25 @@ # Script: bbf_config_reload.sh # Description: -# This script reloads WiFi Configs based on JSON input. -# Input should be a JSON string with boolean-like values (0 or 1) for: +# This script reloads WiFi Configs based on input args. +# Input args should be one of the below or both with space separate # - "wireless" # - "mapcontroller" # # Usage: -# sh bbf_config_reload.sh '{"wireless":"1","mapcontroller":"0"}' +# sh bbf_config_reload.sh wireless mapcontroller # # Actions: -# - If wireless == 1 and mapcontroller == 1 → Reload mapcontroller (SIGHUP) -# - If wireless == 1 and mapcontroller == 0 → Commit wireless config via ubus -# - If wireless == 0 and mapcontroller == 1 → Reload mapcontroller (SIGHUP) +# - If both wireless and mapcontroller → Reload mapcontroller (SIGHUP) +# - If only wireless → Commit wireless config via ubus +# - If only mapcontroller → Reload mapcontroller (SIGHUP) # - Otherwise → Do nothing -. /usr/share/libubox/jshn.sh - log() { echo "${@}"|logger -t bbf.config.wifi.reload -p info } -input="$1" +input="$@" # Validate input if [ -z "$input" ]; then @@ -30,18 +28,19 @@ if [ -z "$input" ]; then exit 1 fi -# Parse JSON input -json_load "$input" || { - log "Error: Failed to parse JSON input" - exit 1 -} - -json_get_var wireless wireless -json_get_var mapcontroller mapcontroller - # Normalize inputs (default to 0 if not set) -wireless=${wireless:-0} -mapcontroller=${mapcontroller:-0} +wireless=0 +mapcontroller=0 + +for arg in ${input}; do + if [ "${arg}" == "wireless" ]; then + wireless=1 + fi + + if [ "${arg}" == "mapcontroller" ]; then + mapcontroller=1 + fi +done # Define function to reload mapcontroller reload_mapcontroller() { @@ -65,9 +64,4 @@ else exit 1 fi -# Output success as JSON -json_init -json_add_boolean "Success" 1 -json_dump - exit 0