netmode: check mode from opconf in uci-default

(cherry picked from commit fe7a0b7d0c)

12c8a916 netmode: check mode from opconf.json in uci-default

Co-authored-by: Vivek Dutta <vivek.dutta@iopsys.eu>
This commit is contained in:
Vivek Dutta 2025-11-28 15:57:28 +05:30 committed by IOPSYS Dev
parent a3d7280423
commit e67f2bbcf7
No known key found for this signature in database
3 changed files with 34 additions and 9 deletions

View file

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=netmode
PKG_VERSION:=1.1.10
PKG_VERSION:=1.1.11
PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_LICENSE:=GPL-2.0-only

View file

@ -117,6 +117,7 @@ start_service() {
config_get_bool enabled global enabled '0'
[ $enabled -eq 0 ] && return
[ -d $MODEDIR ] || mkdir -p $MODEDIR
# Get the desired netmode from config
config_get mode global mode ""
# Check if netmode is set as boot environment parameter
@ -127,9 +128,12 @@ start_service() {
# Get the last saved mode
lastmode="$(cat $MODEDIR/.last_mode 2>/dev/null)"
# Return if desired mode is same as last saved mode
[ "$mode" == "$lastmode" ] && return
if [ "$mode" = "$lastmode" ]; then
_log "Not switching mode[${mode}], lastmode[${lastmode}]"
return
fi
_log "Switching to [${mode}] Mode" >/dev/console
_log "Switching to [${mode}] Mode"
# Configure env variables
configure_env_vars ${mode}
@ -147,8 +151,8 @@ start_service() {
# Execute mode specific scripts
if [ -d $MODEDIR/$mode/scripts ]; then
_log "Executing $MODEDIR/$mode/scripts/* scripts"
for script in $(ls $MODEDIR/$mode/scripts/); do
_log "Executing [${mode}], script [${script}]"
sh $MODEDIR/$mode/scripts/$script
done
fi
@ -158,9 +162,8 @@ start_service() {
cleanup_env_vars "${mode}"
# Save mode as last mode
[ -d $MODEDIR ] || mkdir -p $MODEDIR
echo "$mode" > $MODEDIR/.last_mode
_log "Switching to Mode [${mode}] done, last mode updated" >/dev/console
_log "Switching to Mode [${mode}] done, last mode updated"
}
service_triggers()

View file

@ -1,7 +1,25 @@
#!/bin/sh
enabled="$(uci -q get netmode.global.enabled)"
[ "$enabled" == "1" ] || exit 0
if [ "$enabled" != "1" ]; then
exit 0
fi
# Check if netmode getting provisioned from opconf, in case of opconf
# provisioning, mode setting not required
mode="$(jsonfilter -i /opconf/opconf.json -e @.netmode.mode 2>/dev/null)"
if [ -n "${mode}" ]; then
exit 0
fi
# Check if opconf has wan provisioning enabled, if yes, get the proto/mode from opconf
proto="$(jsonfilter -i /usr_data/opconf/opconf.json -e '@.network.wan[@.name="wan"].proto' 2>/dev/null)"
if [ -n "${proto}" ]; then
mode="routed-${proto}"
uci -q set netmode.global.mode="${mode}"
echo "${mode}" > /etc/netmodes/.last_mode
exit 0
fi
mode="$(uci -q get netmode.global.mode)"
wanproto=$(uci -q get network.wan.proto)
@ -13,7 +31,9 @@ if [ -n "$mode" ]; then
fi
fi
[ -f /etc/netmodes/supported_modes.json ] || exit 0
if [ ! -f "/etc/netmodes/supported_modes.json" ]; then
exit 0
fi
# NetMode is enabled without a Mode being set
# Figure out the current mode from network config
@ -26,10 +46,12 @@ esac
found=0
for md in $(jsonfilter -i /etc/netmodes/supported_modes.json -e "@.supported_modes.*.name"); do
[ "$md" == "$curmode" ] && found=1
[ "$md" = "$curmode" ] && found=1
done
if [ $found -eq 1 ]; then
uci -q set netmode.global.mode="$curmode"
echo "$curmode" > /etc/netmodes/.last_mode
else
exit 1
fi