mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
netmode: check mode from opconf.json in uci-default
This commit is contained in:
parent
d9688d0d7b
commit
12c8a91693
3 changed files with 34 additions and 9 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=netmode
|
PKG_NAME:=netmode
|
||||||
PKG_VERSION:=1.1.10
|
PKG_VERSION:=1.1.11
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||||
PKG_LICENSE:=GPL-2.0-only
|
PKG_LICENSE:=GPL-2.0-only
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@ start_service() {
|
||||||
config_get_bool enabled global enabled '0'
|
config_get_bool enabled global enabled '0'
|
||||||
[ $enabled -eq 0 ] && return
|
[ $enabled -eq 0 ] && return
|
||||||
|
|
||||||
|
[ -d $MODEDIR ] || mkdir -p $MODEDIR
|
||||||
# Get the desired netmode from config
|
# Get the desired netmode from config
|
||||||
config_get mode global mode ""
|
config_get mode global mode ""
|
||||||
# Check if netmode is set as boot environment parameter
|
# Check if netmode is set as boot environment parameter
|
||||||
|
|
@ -127,9 +128,12 @@ start_service() {
|
||||||
# Get the last saved mode
|
# Get the last saved mode
|
||||||
lastmode="$(cat $MODEDIR/.last_mode 2>/dev/null)"
|
lastmode="$(cat $MODEDIR/.last_mode 2>/dev/null)"
|
||||||
# Return if desired mode is same as last saved mode
|
# 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 variables
|
||||||
configure_env_vars ${mode}
|
configure_env_vars ${mode}
|
||||||
|
|
@ -147,8 +151,8 @@ start_service() {
|
||||||
|
|
||||||
# Execute mode specific scripts
|
# Execute mode specific scripts
|
||||||
if [ -d $MODEDIR/$mode/scripts ]; then
|
if [ -d $MODEDIR/$mode/scripts ]; then
|
||||||
_log "Executing $MODEDIR/$mode/scripts/* scripts"
|
|
||||||
for script in $(ls $MODEDIR/$mode/scripts/); do
|
for script in $(ls $MODEDIR/$mode/scripts/); do
|
||||||
|
_log "Executing [${mode}], script [${script}]"
|
||||||
sh $MODEDIR/$mode/scripts/$script
|
sh $MODEDIR/$mode/scripts/$script
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
@ -158,9 +162,8 @@ start_service() {
|
||||||
cleanup_env_vars "${mode}"
|
cleanup_env_vars "${mode}"
|
||||||
|
|
||||||
# Save mode as last mode
|
# Save mode as last mode
|
||||||
[ -d $MODEDIR ] || mkdir -p $MODEDIR
|
|
||||||
echo "$mode" > $MODEDIR/.last_mode
|
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()
|
service_triggers()
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,25 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
enabled="$(uci -q get netmode.global.enabled)"
|
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)"
|
mode="$(uci -q get netmode.global.mode)"
|
||||||
wanproto=$(uci -q get network.wan.proto)
|
wanproto=$(uci -q get network.wan.proto)
|
||||||
|
|
@ -13,7 +31,9 @@ if [ -n "$mode" ]; then
|
||||||
fi
|
fi
|
||||||
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
|
# NetMode is enabled without a Mode being set
|
||||||
# Figure out the current mode from network config
|
# Figure out the current mode from network config
|
||||||
|
|
@ -26,10 +46,12 @@ esac
|
||||||
|
|
||||||
found=0
|
found=0
|
||||||
for md in $(jsonfilter -i /etc/netmodes/supported_modes.json -e "@.supported_modes.*.name"); do
|
for md in $(jsonfilter -i /etc/netmodes/supported_modes.json -e "@.supported_modes.*.name"); do
|
||||||
[ "$md" == "$curmode" ] && found=1
|
[ "$md" = "$curmode" ] && found=1
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $found -eq 1 ]; then
|
if [ $found -eq 1 ]; then
|
||||||
uci -q set netmode.global.mode="$curmode"
|
uci -q set netmode.global.mode="$curmode"
|
||||||
echo "$curmode" > /etc/netmodes/.last_mode
|
echo "$curmode" > /etc/netmodes/.last_mode
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue