From bf8b4de5da88a36f74dd5becc3ad1d1887401dd1 Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane Date: Tue, 10 Jun 2025 11:42:34 +0200 Subject: [PATCH] wifidmd: add a script to handle wifi configs relaod --- wifidmd/Makefile | 9 ++- .../files/etc/wifidmd/bbf_config_reload.sh | 73 +++++++++++++++++++ 2 files changed, 79 insertions(+), 3 deletions(-) create mode 100755 wifidmd/files/etc/wifidmd/bbf_config_reload.sh diff --git a/wifidmd/Makefile b/wifidmd/Makefile index 0bf4aad93..c27a0155e 100644 --- a/wifidmd/Makefile +++ b/wifidmd/Makefile @@ -5,13 +5,13 @@ include $(TOPDIR)/rules.mk PKG_NAME:=wifidmd -PKG_VERSION:=1.1.24 +PKG_VERSION:=1.1.25 LOCAL_DEV:=0 ifneq ($(LOCAL_DEV),1) PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/wifidmd.git -PKG_SOURCE_VERSION:=bed749fd1e3275c06fda4d2319614bae5c3a1d7f +PKG_SOURCE_VERSION:=7d680a0cd58fddcc909fb6cf89ebcc6a91ece3cc PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz PKG_MIRROR_HASH:=skip endif @@ -64,10 +64,13 @@ endif define Package/wifidmd/install $(INSTALL_DIR) $(1)/usr/sbin $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/wifidmd $(1)/usr/sbin/wifidmd - + $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/etc/init.d/wifidmd $(1)/etc/init.d/wifidmd + $(INSTALL_DIR) $(1)/etc/wifidmd + $(INSTALL_BIN) ./files/etc/wifidmd/bbf_config_reload.sh $(1)/etc/wifidmd + $(BBFDM_REGISTER_SERVICES) ./bbfdm_service.json $(1) $(PKG_NAME) endef diff --git a/wifidmd/files/etc/wifidmd/bbf_config_reload.sh b/wifidmd/files/etc/wifidmd/bbf_config_reload.sh new file mode 100755 index 000000000..e89902848 --- /dev/null +++ b/wifidmd/files/etc/wifidmd/bbf_config_reload.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +# 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: +# - "wireless" +# - "mapcontroller" +# +# Usage: +# sh bbf_config_reload.sh '{"wireless":"1","mapcontroller":"0"}' +# +# 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) +# - Otherwise → Do nothing + +. /usr/share/libubox/jshn.sh + +log() { + echo "${@}"|logger -t bbf.config.wifi.reload -p info +} + +input="$1" + +# Validate input +if [ -z "$input" ]; then + log "Error: No input provided" + 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} + +# Define function to reload mapcontroller +reload_mapcontroller() { + pid=$(pidof mapcontroller) + if [ -n "$pid" ]; then + log "Reloading mapcontroller (PID: $pid)..." + kill -SIGHUP "$pid" + else + log "Warning: mapcontroller process not found" + fi +} + +# Apply logic based on flags +if [ "$mapcontroller" -eq 1 ]; then + reload_mapcontroller +elif [ "$wireless" -eq 1 ]; then + log "Committing wireless config..." + ubus call uci commit '{"config":"wireless"}' +else + log "No action needed." + exit 1 +fi + +# Output success as JSON +json_init +json_add_boolean "Success" 1 +json_dump + +exit 0