#!/bin/sh
# start/stop miredo
MIREDO_PID=/var/run/miredo.pid

case $1 in
	start)
		if [ "$RC_NETWORK_PID" ]; then # boot time, when wait for Wpagui and rc.network to finish
			while pidof 50-Wpagui > /dev/null; do sleep 1; done
			while [ -e $RC_NETWORK_PID ]; do sleep 1; done
			echo "Starting miredo ..."
		fi
		! lsmod | grep -qm 1 ipv6 && modprobe ipv6 2> /dev/null
		[ ! -e $MIREDO_PID ] && miredo
		;;
	stop)
		[ -e $MIREDO_PID ] && kill $(cat $MIREDO_PID)
		;;
	restart)
		$0 stop
		sleep 2
		$0 start
		;;
	status)
		[ -e $MIREDO_PID ] && echo "miredo is running" || echo "miredo is stopped."
		;;
	*)
		echo "usage: $0 [start|stop|restart]"
		;;
esac

# End of file
