#!/bin/sh /etc/rc.common
START=91
. /lib/config/uci.sh
uci_load bmxd
start () {
	interface=$(uci get bmxd.general.interface)
	if [ "$interface" = "" ]; then
		echo $1 Error, you must specify at least a network interface
		exit
	fi
	announce=$(uci get bmxd.general.announce)
	gateway_class=$(uci get bmxd.general.gateway_class)
	originator_interval=$(uci get bmxd.general.originator_interval)
	preferred_gateway=$(uci get bmxd.general.preferred_gateway)
	routing_class=$(uci get bmxd.general.routing_class)
	visualisation_srv=$(uci get bmxd.general.visualisation_srv)
	policy_routing_script=$(uci get bmxd.general.policy_routing_script)
	bmx_args=""

	if [ $announce ]; then
		bmx_args=${bmx_args}'-a '$announce' '
	fi

	if [ $gateway_class ]; then
		bmx_args=${bmx_args}'-g '$gateway_class' '
	fi

	if [ $originator_interval ]; then
		bmx_args=${bmx_args}'-o '$originator_interval' '
	fi

	if [ $preferred_gateway ]; then
		bmx_args=${bmx_args}'-p '$preferred_gateway' '
	fi

	if [ $routing_class ]; then
		bmx_args=${bmx_args}'-r '$routing_class' '
	fi
		
	if [ $visualisation_srv ]; then
		bmx_args=${bmx_args}'-s '$visualisation_srv' '
	fi
	
	if [ $policy_routing_script ]; then
		bmx_args=${bmx_args}'--policy-routing-script '$policy_routing_script' '
	fi

	bmx_args=${bmx_args}$interface
	bmxd $bmx_args >/dev/null 2>&1
}

restart () {
	$0 stop
	sleep 3
	$0 start
}
        
stop () {
	killall bmxd
}
