#!/bin/sh
#
# bluetooth    Bluetooth subsystem starting and stopping
#
# chkconfig: 345 12 91
# description: Bluetooth subsystem
#

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

HID2HCI_ENABLE=false

SourceIfNotEmpty /etc/sysconfig/bluetooth

HCID=bluetoothd
HID2HCI=hid2hci

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

start()
{
	start_daemon --lockfile "$LOCKFILE" $HCID
	RETVAL=$?
	[ "$HID2HCI_ENABLE" = "true" ] && $HID2HCI -q --tohci ||:
	return $RETVAL
}

stop()
{
	stop_daemon --lockfile "$LOCKFILE" $HCID
	RETVAL=$?
	[ "$HID2HCI_UNDO" = "true" ] && $HID2HCI -q --tohid ||:
	return $RETVAL
}

restart()
{
	stop
	start
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
        reload|restart)
		restart
                ;;
        condstop)
	        if [ -e "$LOCKFILE" ]; then
		        stop
		fi
		;;
	condrestart)
		;;
	status)
		status "$HCID"
		;;
	*)
		echo "Usage: ${0##*/} {start|stop|reload|restart|condstop|condrestart|status}"
		RETVAL=1
		;;
esac

exit $RETVAL
