#! /bin/sh
#
# hostapd init.d script
# (c) 2004, Faidon Liambotis <faidon@cube.gr>
#

if [ -f /etc/default/hostapd ] ; then
	. /etc/default/hostapd
fi

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/hostapd
DAEMON_OPTS="$DAEMON_OPTS -B /etc/hostapd/hostapd.conf"
NAME=hostapd
DESC="advanced IEEE 802.11 management"

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	if [ ! "$RUN_DAEMON" = "yes" ]; then
		echo "disabled via /etc/default/hostapd"
	else
		echo -n "$NAME";
		if start-stop-daemon --start --quiet --exec $DAEMON -- $DAEMON_OPTS > /dev/null; then
			echo "."
			exit 0 # EXIT_SUCCESS
		else
			echo "...failed."
			exit 1 # EXIT_FAILURE
		fi
	fi
	;;
  stop)
	echo -n "Stopping $DESC: "
	echo -n "$NAME"; start-stop-daemon --stop --quiet --exec $DAEMON || true
	echo "."
	;;
  restart|force-reload)
  	$0 stop
	sleep 8
	$0 start
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
