#!/bin/sh
#
# bluetooth	Bluetooth subsystem starting and stopping. Turn HID adapters into Bluetooth ones.
#
# chkconfig:	345 50 83
#
# description:	Bluetooth subsystem
#
# $Id$


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

[ -f /etc/sysconfig/bluetooth ] && . /etc/sysconfig/bluetooth

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/bluetooth ]; then
		msg_already_running bluetooth
		return
	fi

	if [ ! -x /sbin/udevadm ]; then
		return
	fi

	msg_starting "Bluetooth devices"
	daemon /sbin/udevadm trigger --subsystem-match=bluetooth --action=add
	RETVAL=$?
	touch /var/lock/subsys/bluetooth
}

stop() {
	if [ ! -f /var/lock/subsys/bluetooth ]; then
		msg_not_running bluetooth
		return
	fi

	# nothing needed to stop it
	rm -f /var/lock/subsys/bluetooth
}

condrestart() {
	if [ ! -f /var/lock/subsys/bluetooth ]; then
		msg_not_running bluetooth
		RETVAL=$1
		return
	fi

	stop
	start
}

status() {
	if [ ! -f /var/lock/subsys/bluetooth ]; then
		msg_not_running bluetooth
		RETVAL=3
		return $RETVAL
	fi

	nls "bluetooth is running"
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload|force-reload)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  status)
	status
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
