#!/bin/sh
#
# irda			This shell script takes care of starting and stopping
#				IrDA support
#
# description: lrmanager is the irda daemon required for irda to work \
# properly. 
#
# chkconfig: 2345 47 85

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

# Source IrDA networking configuration.
SourceIfNotEmpty /etc/sysconfig/irda

# Check that irda is up.
[ "$IRDA" != "no" ] || exit 0

[ -f /usr/sbin/irattach ] || exit 0

ARGS=
if [ -n "$DONGLE" ] ; then
	ARGS="$ARGS -d $DONGLE"
fi
if [ "$DISCOVERY" = "yes" ];then
	ARGS="$ARGS -s"
fi

LOCKFILE=/var/lock/subsys/irda
RETVAL=0

start()
{
	# Attach irda device 
	echo -n "Starting IrDA: "
	start_daemon --lockfile "$LOCKFILE" -- irattach ${DEVICE} ${ARGS}
	RETVAL=$?
	return $RETVAL
}

stop()
{
	# Stop service.
	echo -n "Shutting down IrDA: "
	stop_daemon --lockfile "$LOCKFILE" -- irattach
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status irattach
		RETVAL=$?
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|reload|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
