wifidmd: add external apply handler

This commit is contained in:
Suvendhu Hansa 2025-09-11 13:25:27 +05:30 committed by Vivek Dutta
parent 20c49302c1
commit 1fd74364fa
2 changed files with 30 additions and 25 deletions

View file

@ -11,6 +11,17 @@
],
"config": {
"loglevel": "3"
},
"apply_handler": {
"uci": [
{
"file": [
"wireless",
"mapcontroller"
],
"external_handler": "/etc/wifidmd/bbf_config_reload.sh"
}
]
}
}
}

View file

@ -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