diff --git a/netmode/files/etc/init.d/netmode b/netmode/files/etc/init.d/netmode index 9f6a4dbed..0ca69cbd0 100755 --- a/netmode/files/etc/init.d/netmode +++ b/netmode/files/etc/init.d/netmode @@ -7,17 +7,13 @@ USE_PROCD=1 MODEDIR="/etc/netmodes" -run_netmode_scripts() { - mode="$1" - when="$2" - - path=$(readlink -f $MODEDIR/$mode) - [ "${path:0:13}" == "$MODEDIR" ] || exit - - if [ -d $MODEDIR/$mode/scripts/$when ]; then - logger -s -p user.info -t "netmode" "Executing $when netmode scripts" - for script in $(ls MODEDIR/$mode/scripts/$when/); do - sh $MODEDIR/$mode/scripts/$when/$script +libnetmode_exec() { + when="$1" + # Execute /lib/netmode scripts + if [ -d /lib/netmode/$when ]; then + logger -s -p user.info -t "netmode" "Executing /lib/netmode/$when scripts" + for script in $(ls /lib/netmode/$when/); do + sh /lib/netmode/$when/$script done fi } @@ -41,12 +37,28 @@ start_service() { logger -s -p user.info -t "netmode" "Switching to $mode Mode" >/dev/console - run_netmode_scripts $mode "pre" + # Execute netmode generic pre-mode-switch scripts + libnetmode_exec "pre" + + # Copy netmode UCI config files if [ -d $MODEDIR/$mode/uci ]; then logger -s -p user.info -t "netmode" "Copying $MODEDIR/$mode/uci/* to /etc/config/" cp $MODEDIR/$mode/uci/* /etc/config/ 2>/dev/null fi - run_netmode_scripts $mode "post" + + # Execute netmode generic scripts + libnetmode_exec + + # Execute mode specific scripts + if [ -d $MODEDIR/$mode/scripts ]; then + logger -s -p user.info -t "netmode" "Executing $MODEDIR/$mode/scripts/* scripts" + for script in $(ls $MODEDIR/$mode/scripts/); do + sh $MODEDIR/$mode/scripts/$script + done + fi + + # Execute netmode generic post-mode-switch scripts + libnetmode_exec "post" } service_triggers() diff --git a/netmode/files/etc/netmodes/bridge/scripts/pre/bridge_mode.sh b/netmode/files/etc/netmodes/bridge/scripts/pre/bridge_mode.sh deleted file mode 100644 index 928dd08b7..000000000 --- a/netmode/files/etc/netmodes/bridge/scripts/pre/bridge_mode.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/sh - -. /usr/share/libubox/jshn.sh -. /lib/functions.sh - -BRIDGEPORTS="" - -get_vlan() { - local device="$1" - for section in $(uci show network | grep "=device" | cut -d '=' -f1); do - if [ "$(uci -q get $section.ifname)" == "$device" ]; then - uci -q get $section.name - break - fi - done -} - -add_wifi_devs() -{ - - add_wdev() - { - local cfg=$1 -# local disabled - -# config_get_bool disabled $cfg disabled 0 -# config_get_bool ifname $cfg ifname - -# if [ $disabled -eq 0 -a -n "$ifname" ]; then -# BRIDGEPORTS="$ifname" -# fi - - uci -q set wireless.$cfg.network="wan" - } - - config_load wireless - config_foreach add_wdev "wifi-iface" - - uci -q commit wireless -} - -add_xtm_devs() { - local section device vlan - - for section in $(uci show dsl | grep "=.*tm-device" | cut -d'=' -f1); do - if [ -n "$(uci -q get $section.device)" ]; then - - vlan="$(get_vlan $device)" - [ -n "$vlan" ] && device="$vlan" - - if [ -n "$device" ]; then - BRIDGEPORTS="$BRIDGEPORTS $device" - fi - - fi - done -} - -add_eth_ports() { - - add_port() - { - local cfg=$1 - local ifname vlan - - config_get ifname $cfg ifname - - vlan="$(get_vlan $ifname)" - [ -n "$vlan" ] && ifname="$vlan" - - if [ -n "$ifname" ]; then - BRIDGEPORTS="$BRIDGEPORTS $ifname" - fi - } - - config_load ports - config_foreach add_port "ethport" -} - -add_xtm_devs -add_eth_ports -add_wifi_devs - -BRIDGEPORTS="$(echo $BRIDGEPORTS | sed -e 's/[[:space:]]*$//')" - -uci -q set network.wan.type="bridge" -uci -q set network.wan.ifname="$BRIDGEPORTS" -uci -q set network.wan6.ifname="@wan" -uci -q delete network.lan.ifname - -ubus call uci commit '{"config":"network"}' - diff --git a/netmode/files/etc/netmodes/router/scripts/pre/router_mode.sh b/netmode/files/etc/netmodes/router/scripts/pre/router_mode.sh deleted file mode 100644 index 457d32d44..000000000 --- a/netmode/files/etc/netmodes/router/scripts/pre/router_mode.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/sh - -. /usr/share/libubox/jshn.sh -. /lib/functions.sh - -WANPORTS="" -LANPORTS="" - -get_vlan() { - local device="$1" - for section in $(uci show network | grep "=device" | cut -d '=' -f1); do - if [ "$(uci -q get $section.ifname)" == "$device" ]; then - uci -q get $section.name - break - fi - done -} - -add_wifi_devs() -{ - - add_wdev() - { - local cfg=$1 - - config_get mode $cfg mode "ap" - - if [ "$mode" == "ap" ]; then - uci -q set wireless.$cfg.network="lan" - fi - } - - config_load wireless - config_foreach add_wdev "wifi-iface" - - uci -q commit wireless -} - -add_xtm_devs() { - local section device vlan - - for section in $(uci show dsl | grep "=.*tm-device" | cut -d'=' -f1); do - device="$(uci -q get $section.device)" - - if [ -n "$device" ]; then - vlan="$(get_vlan $device)" - [ -n "$vlan" ] && device="$vlan" - - if [ -n "$device" ]; then - WANPORTS="$WANPORTS $device" - fi - fi - done -} - -add_eth_ports() { - - add_port() - { - local cfg=$1 - local uplink ifname vlan - - config_get ifname $cfg ifname - config_get_bool uplink $cfg uplink 0 - - vlan="$(get_vlan $ifname)" - [ -n "$vlan" ] && ifname="$vlan" - - if [ $uplink -eq 1 ]; then - WANPORTS="$WANPORTS $ifname" - else - LANPORTS="$LANPORTS $ifname" - fi - } - - config_load ports - config_foreach add_port "ethport" -} - -add_xtm_devs -add_eth_ports -add_wifi_devs - -WANPORTS="$(echo $WANPORTS | sed -e 's/[[:space:]]*$//')" -LANPORTS="$(echo $LANPORTS | sed -e 's/[[:space:]]*$//')" - -uci -q set network.wan.type="anywan" -uci -q set network.wan.ifname="$WANPORTS" -uci -q set network.wan6.ifname="@wan" -uci -q set network.lan.type="bridge" -uci -q set network.lan.ifname="$LANPORTS" - -ubus call uci commit '{"config":"network"}' -