#!/bin/sh

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

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="BT Uart"

set -e

case $1 in
        start)
                echo -n "Starting $DESC: "
		if [ -e /sys/class/rfkill/rfkill0 ];then
	                /usr/bin/hciattach /dev/ttyAMA0 bcm43xx 3000000 flow -
			if [ -e /sys/class/bluetooth/hci0 ];then
		                /usr/bin/hciconfig hci0 up
			fi;
		else
			echo "BT Not Available"
		fi;
        ;;
        stop)
                echo -n "Stopping $DESC: "
		if [ -e /sys/class/bluetooth/hci0 ];then
	                /usr/bin/hciconfig hci0 down
		fi;
        ;;
        restart|force-reload)
                $0 stop
                sleep 1
                $0 start
        ;;
        status)
                status ${DAEMON} || exit $?
        ;;
        *)
                N=/etc/init.d/pulseaudio
                echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
                exit 1
        ;;
esac

exit 0
