#!/bin/sh
#
# Intel PRO/Wireless 3945ABG:   ipw3945d deamon
#
# chkconfig:	2345 09 91
#
# description:	This is a daemon for automatically switching \
#		ipw3945d on to get access to any AP.
#

# Source function library.
. /etc/rc.d/init.d/functions

DESC="Intel PRO/Wireless 3945ABG"
NAME="ipw3945d"

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/ipw3945d ]; then
		msg_starting "$DESC: $NAME"
		/sbin/modprobe --ignore-install ipw3945
		daemon --waitforname ipw3945d --waitfortime 3 /sbin/ipw3945d --timeout=-1 --quiet
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ipw3945d
	else
		msg_already_running "$DESC: $NAME"
	fi
}

stop() {
	if [ -f /var/lock/subsys/ipw3945d ]; then
		# Stop daemons.
		msg_stopping "$DESC: $NAME"
		/sbin/ipw3945d --kill
		/sbin/modprobe -r --ignore-remove ipw3945
		ok
		rm -f /var/lock/subsys/ipw3945d
	else
		msg_not_running "$DESC: $NAME"
	fi
}

RETVAL=0
case "$1" in
 start)
 	start
	;;
 stop)
 	stop
	;;
 restart|force-reload)
	stop
	sleep 1
	start
	;;
 status)
	status /sbin/ipw3945d
	exit $?
	;;
 *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3

esac
exit $RETVAL
