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

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

# Source config.
SourceIfNotEmpty /etc/sysconfig/lircd

[ -z "$OPT" ] && OPT=""

[ -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: "
	start_daemon --no-announce -- lircd -p 660 $OPT
	RETVAL=$?
	start_daemon --lockfile "$LOCKFILE" lircmd
	RETVAL2=$?
	[ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] || RETVAL=1
	return $RETVAL
}

stop()
{
	echo -n "Shutting down Infrared Remote Control: "
	stop_daemon --no-announce lircmd
	RETVAL=$?
	stop_daemon --no-announce --lockfile "$LOCKFILE" lircd
	RETVAL2=$?
	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
