#!/bin/sh

[ -f "/etc/mwan3.user" ] && {
	. /lib/functions.sh
	. /lib/mwan3/mwan3.sh

	[ "$MWAN3_SHUTDOWN" != 1 ] && mwan3_lock "$ACTION" "$DEVICE-user"

	[ "$MWAN3_SHUTDOWN" != 1 ] && ! /etc/init.d/mwan3 running && {
		mwan3_unlock "$ACTION" "$DEVICE-user"
		exit 0
	}

	config_load mwan3

	config_get_bool enabled "$INTERFACE" enabled 0
	[ "${enabled}" -eq 1 ] || {
		[ "$MWAN3_SHUTDOWN" != 1 ] && mwan3_unlock "$ACTION" "$DEVICE-user"
		exit 0
	}

	[ "$MWAN3_SHUTDOWN" != 1 ] && mwan3_unlock "$ACTION" "$DEVICE-user"

	env -i ACTION="$ACTION" INTERFACE="$INTERFACE" DEVICE="$DEVICE" \
		/bin/sh /etc/mwan3.user
}

exit 0
