#! /bin/bash
#
# ultrabayd          Start/Stop the Thinkpad Ultrabay daemon.
#
# chkconfig: 2345 95 05
# description: ultrabayd is used to auto-detect if Ultrabay is present \
#              in a thinkpad or not, and un/register the corresponding \
#              IDE interface. It is useful when thinkpad is docked/undocked.
# processname: ultrabayd

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

RETVAL=0

# See how we were called.
  
prog="ultrabayd"

start() {
	gprintf "Starting %s: " "$prog"
	daemon $prog
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ultrabayd
	return $RETVAL
}

stop() {
	gprintf "Stopping %s: " "$prog"
	killproc $prog
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ultrabayd
	return $RETVAL
}	

rhstatus() {
	status $prog
}	

restart() {
  	stop
	start
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	restart
	;;
  status)
  	rhstatus
	;;
  condrestart)
  	[ -f /var/lock/subsys/$prog ] && restart || :
	;;
  *)
	gprintf "Usage: %s {start|stop|status|reload|restart|condrestart}\n" "$0"
	exit 1
esac

exit $?
