#!/bin/sh
#
# fan:		Starts the Toshiba fan daemon (smart mode)
#
# chkconfig:	2345 95 5
# description:	Stops the laptop fan when battery powered, starts \
#		otherwise.

. /etc/rc.d/init.d/functions

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/fan ]; then
		msg_starting "Toshiba fan daemon"
		daemon /usr/bin/fan -s
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/fan
	else
		msg_already_running "Toshiba fan daemon"
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/fan ]; then
		msg_stopping "Toshiba fan daemon"
		killproc fan
		rm -f /var/lock/subsys/fan
	else
		msg_not_running "Toshiba fan daemon"
	fi
	;;
  status)
	status fan
	exit $?
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
