#!/bin/sh

exec >/dev/null 2>&1

DROPBEAR=/usr/sbin/dropbear
DROPBEAR_CONF_PATH="/etc/dropbear"
DROPBEAR_ARGS="-F -p 22"
DROPBEAR_LOG=/dev/null

do_start()
{
	grep "ssh=off" /proc/cmdline >/dev/null 2>&1
	if [ $? -eq 0 ]; then
		pidof aoebridge
		if [ $? -ne 0 ]; then
			exit
		fi
	fi

	echo -n "Starting Dropbear: "
	chmod 600 $DROPBEAR_CONF_PATH/dropbear_*_host_key
	start-stop-daemon -S -q -b \
		-x $DROPBEAR -- $DROPBEAR_ARGS >$DROPBEAR_LOG 2>&1

	echo "OK"
}

do_stop()
{
	echo -n "Stopping Dropbear: "
	for pid in `pgrep '^dropbear'`; do kill $pid; done >/dev/null 2>&1
	echo "OK"
}

case "$1" in
	start)
		do_start
		;;
	stop)
		do_stop
		;;
	restart|reload)
		stop
		start
		;;
	*)
		echo "Usage: $0 {start|stop|restart}"
		exit 1
esac
