From f9a787e8dfc89c7804463ea2cb78ad3a93a423e1 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 5 Feb 2018 10:15:03 +0100 Subject: [PATCH] net/mwan3: add init script to enable/disable mwan3 globally Adding a init script to "/etc/init.d/" introduce the possibility to enable/disable mwan3 globally. Signed-off-by: Florian Eckert --- net/mwan3/files/etc/hotplug.d/iface/14-mwan3 | 3 ++ net/mwan3/files/etc/hotplug.d/iface/15-mwan3 | 11 ++++--- .../files/etc/hotplug.d/iface/16-mwan3-user | 3 ++ net/mwan3/files/etc/init.d/mwan3 | 32 +++++++++++++++++++ net/mwan3/files/usr/sbin/mwan3 | 14 ++++++++ 5 files changed, 59 insertions(+), 4 deletions(-) create mode 100755 net/mwan3/files/etc/init.d/mwan3 diff --git a/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 index f977b3d84..4f8e0be16 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/14-mwan3 @@ -12,6 +12,9 @@ if [ "$ACTION" = "ifup" ]; then fi config_load mwan3 +config_get_bool enabled globals 'enabled' '0' +[ ${enabled} -gt 0 ] || exit 0 + config_get local_source globals local_source 'none' [ "${local_source}" = "none" ] && { exit 0 diff --git a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 index 71d6393b4..bea7baad9 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 +++ b/net/mwan3/files/etc/hotplug.d/iface/15-mwan3 @@ -12,15 +12,18 @@ if [ "$ACTION" == "ifup" ]; then [ -n "$DEVICE" ] || exit 3 fi -mwan3_lock -mwan3_set_connected_iptables -mwan3_unlock - config_load mwan3 +config_get_bool enabled globals 'enabled' '0' +[ ${enabled} -gt 0 ] || exit 0 + config_get enabled $INTERFACE enabled 0 config_get initial_state $INTERFACE initial_state "online" [ "$enabled" == "1" ] || exit 0 +mwan3_lock +mwan3_set_connected_iptables +mwan3_unlock + if [ "$ACTION" == "ifup" ]; then config_get family $INTERFACE family ipv4 if [ "$family" = "ipv4" ]; then diff --git a/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user b/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user index 485f8de4e..9372c736e 100644 --- a/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user +++ b/net/mwan3/files/etc/hotplug.d/iface/16-mwan3-user @@ -4,6 +4,9 @@ . /lib/functions.sh config_load mwan3 + config_get_bool enabled globals 'enabled' '0' + [ ${enabled} -gt 0 ] || exit 0 + config_get enabled "$INTERFACE" enabled 0 [ "${enabled}" = "1" ] || exit 0 env -i ACTION="$ACTION" INTERFACE="$INTERFACE" DEVICE="$DEVICE" \ diff --git a/net/mwan3/files/etc/init.d/mwan3 b/net/mwan3/files/etc/init.d/mwan3 new file mode 100755 index 000000000..dac1fb89a --- /dev/null +++ b/net/mwan3/files/etc/init.d/mwan3 @@ -0,0 +1,32 @@ +#!/bin/sh /etc/rc.common + +START=19 + +reload() { + local enabled + + config_load mwan3 + config_get_bool enabled globals 'enabled' 0 + [ ${enabled} -gt 0 ] || { + echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start" + exit 0 + } + mwan3 restart +} + +boot() { + . /lib/config/uci.sh + uci_toggle_state mwan3 globals enabled "1" +} + +start() { + . /lib/config/uci.sh + uci_toggle_state mwan3 globals enabled "1" + mwan3 start +} + +stop() { + . /lib/config/uci.sh + uci_toggle_state mwan3 globals enabled "0" + mwan3 stop +} diff --git a/net/mwan3/files/usr/sbin/mwan3 b/net/mwan3/files/usr/sbin/mwan3 index 38e80a083..3e1b64456 100755 --- a/net/mwan3/files/usr/sbin/mwan3 +++ b/net/mwan3/files/usr/sbin/mwan3 @@ -54,6 +54,12 @@ ifup() echo "Too many arguments. Usage: mwan3 ifup " && exit 0 fi + config_get_bool enabled globals 'enabled' 0 + [ ${enabled} -gt 0 ] || { + echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start" + exit 0 + } + config_get enabled "$1" enabled 0 device=$(uci -p /var/state get network.$1.ifname) &> /dev/null @@ -112,7 +118,15 @@ status() start() { + local enabled + config_load mwan3 + config_get_bool enabled globals 'enabled' 0 + [ ${enabled} -gt 0 ] || { + echo "Warning: mwan3 is global disabled. Usage: /etc/init.d/mwan3 start" + exit 0 + } + config_foreach ifup interface }