#!/bin/sh
#
# lirc:        This is an init script for RedHat distribution.
#
# Author:      Denis V. Dmitrienko <denis@null.net>
#
# chkconfig: 345 95 10
# description: lirc is a Linux Infrared Remote Control system.

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

[ -f /usr/sbin/lircd ] || exit 0
[ -f /usr/sbin/lircmd ] || exit 0

LOCKFILE="/var/lock/subsys/lirc"
RETVAL=0

start()
{
	echo -n "Starting Infrared Remote Control: "
	daemon lircd -p 660
	RETVAL=$?
	daemon lircmd
	RETVAL2=$?
	echo
	[ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] &&
	    touch "$LOCKFILE" || RETVAL=1
	return $RETVAL
}

stop()
{
	echo -n "Shutting down Infrared Remote Control: "
	killproc lircmd
	RETVAL=$?
	killproc lircd
	RETVAL2=$?
	echo
	[ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && rm -f "$LOCKFILE"
	return $RETVAL
}

restart()
{
    stop
    start
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status lircd
	status lircmd
	;;
  restart)
	restart
	;;
  condstop)
	if [ -e "$LOCKFILE" ]; then
	    stop
	fi
	;;
  condrestart)
	if [ -e "$LOCKFILE" ]; then
	    restart
	fi
	;;
  *)
	echo "Usage: lirc {start|stop|status|restart|condstop|condrestart}"
	RETVAL=1
esac

exit $RETVAL
