#!/bin/sh
#
# lircmd	Linux Infrared Remote Control mouse daemon
#
# chkconfig:	2345 92 8
# description:	LIRC is a package that allows you to decode and send \
#		infra-red signals of many (but not all) commonly used \
#		remote controls.
#
# processname:	lircmd
# pidfile:	/var/run/lirc/lircmd.pid
# config:	/etc/lirc/lircmd.conf

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

start() {
	if [ -f /var/lock/subsys/lircmd ]; then
		msg_already_running "Linux Infrared Remote Control mouse daemon"
		return
	fi

	msg_starting "Linux Infrared Remote Control mouse daemon"
	daemon /usr/sbin/lircmd
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/lircmd
}

stop() {
	if [ ! -f /var/lock/subsys/lircmd ]; then
		msg_not_running "Linux Infrared Remote Control mouse daemon"
		return
	fi

	msg_stopping "Linux Infrared Remote Control mouse daemon"
	killproc lircmd
	rm -f /var/lock/subsys/lircmd >/dev/null 2>&1
}

condrestart() {
	if [ ! -f /var/lock/subsys/lircmd ]; then
		msg_not_running "Linux Infrared Remote Control mouse daemon"
		RETVAL=$1
		return
	fi

	stop
	start
}

reload() {
	if [ ! -f /var/lock/subsys/lircmd ]; then
		msg_not_running "Linux Infrared Remote Control mouse daemon"
		RETVAL=7
		return
	fi

	msg_reloading "Linux Infrared Remote Control mouse daemon"
	killproc lircmd -HUP
	RETVAL=$?
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  reload|force-reload)
	reload
	;;
  status)
	status lircmd
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
	;;
esac

exit $RETVAL
