#!/bin/sh
#
# irmp3        This shell script takes care of starting and stopping
#               the Infrared MP3 service.
# chkconfig: 2345 99 10
# description: Starts the irm3 service.
# processname: irmp3

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

# Source networking configuration.
if [ ! -f /etc/sysconfig/network ]; then
    exit 0
fi

# See how we were called.
case "$1" in
  start)
	action "Turning on LCD backlight: " "/usr/local/bin/backlight on"
	# Start daemons.
	echo -n "Starting irmp3: "
	# Following two lines for mod_crt use.
	#export SVGALIB_DEFAULT_MODE=54
	#daemon /usr/local/sbin/irmp3 -f -l /var/log/irmp3.log
	daemon /usr/local/sbin/irmp3 -l /var/log/irmp3.log
	echo
	touch /var/lock/subsys/irmp3
        cd /usr/local/bin
	echo -n "Starting irmp3_sdl_monitor: "
	# Just to make sure there isn't already one running which will block the display...
	killproc irmp3_sdl_monitor
	export SDL_NOMOUSE=1
	daemon /usr/local/bin/irmp3_sdl_monitor &
	echo
	touch /var/lock/subsys/irmp3_sdl_monitor
	;;
  stop)
	# Stop daemons.
	action "Turning off LCD backlight: " "/usr/local/bin/backlight off"
	echo -n "Shutting down irmp3: "
	killproc irmp3
	echo
	rm -f /var/lock/subsys/irmp3
	echo -n "Shutting down irmp3_sdl_monitor: "
	killproc irmp3_sdl_monitor
	echo
	rm -f /var/lock/subsys/irmp3_sdl_monitor
	;;
  status)
	status irmp3
	;;
  restart)
	$0 stop
	$0 start
	;;
  condstart)
  	checkpid `pidofproc irmp3`
	if [ $? -eq 1 ]; then
		$0 start
	fi
	;;
  condstop)
  	checkpid `pidofproc irmp3`
	if [ $? -eq 0 ]; then
		$0 stop
	fi
	;;
  toggle)
	checkpid `pidofproc irmp3` 
  	if [ $? -eq 0 ]; then
		$0 stop
	else
		$0 start
	fi
	;;	
  *)
	echo "Usage: irmp3 {start|stop|status|restart|condstart|condstop|toggle}"
	exit 1
esac

exit 0
