#!/bin/sh
#
# btattach-bcm	btattach for Broadcom devices
#
# chkconfig: 345 30 80
# description: btattach for Broadcom devices
### BEGIN INIT INFO
# Provides: btattach-bcm
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start:  3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: btattach for Broadcom devices
### END INIT INFO

source /etc/rc.d/init.d/functions

RETVAL=0

LOCKFILE="/var/lock/subsys/btattach-bcm"

start() {
	if [ -e "${LOCKFILE}" ]; then
        exit 0
    else
	    echo -n $"Enabling Bluetooth attachment of Broadcom devices: "
        exec /usr/libexec/bluetooth/btattach-bcm-service.sh %I &
        udevadm trigger --subsystem-match=bluetooth
	    RETVAL=$?
	    [ ${RETVAL} -eq 0 ] && success || failure
	    touch ${LOCKFILE}
    fi
	echo
}

stop() {
	echo -n $"Disabling Bluetooth attachment of Broadcom devices: "
	echo " "
	RETVAL=$?
	[ ${RETVAL} -eq 0 ] && success || failure
	rm -f ${LOCKFILE}
	echo
}

btattach_status() {
	if [ -e ${LOCKFILE} ]; then
		echo $"Bluetooth Broadcom devices enabled."
		return 0
	else
		echo $"Bluetooth Broadcom devices disabled."
		return 3
	fi
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		btattach_status
		RETVAL=$?
		;;
	restart)
		stop
		start
		;;
	reload)
		stop
		start
		;;
	condrestart|try-restart)
		if [ -e "${LOCKFILE}" ]; then
			stop
			start
		fi
		;;
	*)
		echo $"Usage: $prog {start|stop|status|restart|reload|try-restart}"
		exit 1
esac
exit ${RETVAL}

