#! /bin/sh
### BEGIN INIT INFO
# Provides: bluetooth
# Required-Start:    $local_fs $syslog $remote_fs dbus
# Required-Stop:     $local_fs $syslog $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start bluetoothd
### END INIT INFO

. /lib/lsb/init-functions

set -e

case "$1" in
  start)
    #currently this init script exists only because of what appears to be
    #an egg and chicken problem
    #  bluetoothd normally starts up by udev rules.  it needs dbus to function,
    #  but dbus doesn't start up until after udev finishes triggering
    #
    if [ ! -f /sbin/udevadm.upgrade ]; then
      udevadm trigger --subsystem-match=bluetooth
      /usr/sbin/hciconfig hci0 reset
    fi
    ;;
  stop)
    pkill -TERM bluetoothd || true
    ;;
  restart|force-reload)
    $0 stop
    $0 start
    ;;
  status)
    status_of_proc "bluetoothd" "bluetooth" && exit 0 || exit $?
    ;;
  *)
    N=/etc/init.d/bluetooth
    # echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
    echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
    exit 1
    ;;
esac

exit 0
