#!/bin/sh
#
# lircd		Linux Infrared Remote Control daemon
#
# chkconfig:	2345 65 35
# 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:	lircd
# pidfile:	/var/run/lircd.pid
# config:	/etc/lircd.conf
# config:	/etc/sysconfig/lircd

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

# Get service config
[ -f /etc/sysconfig/lircd ] && . /etc/sysconfig/lircd

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/lircd ]; then
		msg_starting "Linux Infrared Remote Control daemon"
		OPTIONS=""
		[ -n "$DRIVER" ] && OPTIONS="--driver=$DRIVER"
		[ -n "$DEVICE" ] && OPTIONS="$OPTIONS --device=$DEVICE"
		modprobe -s lirc > /dev/null 2>&1
                daemon lircd $OPTIONS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/lircd
	else
		msg_already_running "Linux Infrared Remote Control daemon"
	fi
	;;
  stop)
	# Stop daemons.
	if [ -f /var/lock/subsys/lircd ]; then
		msg_stopping "Linux Infrared Remote Control daemon"
		killproc lircd
		rm -f /var/lock/subsys/lircd >/dev/null 2>&1
	else
		msg_not_running "Linux Infrared Remote Control daemon"
	fi
	;;
  status)
	status lircd
	exit $?
	;;
  restart)
	test -f /var/lock/subsys/lircmd && RESTART_LIRCMD=yes
	test -n "$RESTART_LIRCMD" && /etc/rc.d/init.d/lircmd stop
	$0 stop
	$0 start
	RETVAL=$?
	test -n "$RESTART_LIRCMD" && /etc/rc.d/init.d/lircmd start
	;;
  reload|force-reload)
	if [ -f /var/lock/subsys/lircd ]; then
		msg_reloading "Linux Infrared Remote Control daemon"
		killproc lircd -HUP
		RETVAL=$?
	else
		msg_not_running fwlogwatch >&2
		exit 7
	fi
	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
