#! /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 bluetooth daemons ### END INIT INFO # # bluez Bluetooth subsystem starting and stopping # # originally from bluez's scripts/bluetooth.init # # Edd Dumbill # LSB 3.0 compilance and enhancements by Filippo Giunchedi # # Updated for bluez 4.7 by Mario Limonciello # # Note: older daemons like dund pand hidd are now shipped inside the # bluez-compat package global PATH := '/sbin:/bin:/usr/sbin:/usr/bin' global DESC := 'bluetooth' global DAEMON := '/usr/sbin/bluetoothd' global HCIATTACH := '/usr/sbin/hciattach' global HID2HCI_ENABLED := '1' global HID2HCI_UNDO := '1' global UART_CONF := '/etc/bluetooth/uart' global RFCOMM_NAME := 'rfcomm' global RFCOMM := "/usr/bin/$RFCOMM_NAME" global RFCOMM_CONF := "/etc/bluetooth/$RFCOMM_NAME.conf" global SDPTOOL := '/usr/bin/sdptool' global SSD_OPTIONS := ""--oknodo --quiet --exec $DAEMON"" test -f $DAEMON || exit 0 # FIXME: any of the sourced files may fail if/with syntax errors test -f /etc/default/bluetooth && source /etc/default/bluetooth test -f /etc/default/rcS && source /etc/default/rcS source /lib/lsb/init-functions set -e # FIXME: this function is possibly a no-op proc run_sdptool { # declaring IFS local in this function, removes the need to # save/restore it var IFS = '', o = '' test -x $SDPTOOL || return 1 # FIXME: where does SDPTOOL_OPTIONS come from? if ! test -z $SDPTOOL_OPTIONS { IFS := '";'" for o in [$SDPTOOL_OPTIONS] { #echo "execing $SDPTOOL $o" IFS := '" '" if test $VERBOSE != no { $SDPTOOL $o } else { $SDPTOOL $o >/dev/null !2 > !1 } } } } proc hci_input { log_progress_msg "switching to HID/HCI no longer done in init script, see /usr/share/doc/bluez/NEWS.Debian.gz" || : } alias enable_hci_input=hci_input alias disable_hci_input=hci_input proc start_uarts { test -f $HCIATTACH && test -f $UART_CONF || return grep -v '^#' $UART_CONF | while read i { if test $VERBOSE != no { $HCIATTACH $i } else { $HCIATTACH $i >/dev/null !2 > !1 } } } proc stop_uarts { killall $(HCIATTACH##*/) >/dev/null !2 > !1 || : } proc start_rfcomm { if test -x $RFCOMM && test -f $RFCOMM_CONF { # rfcomm must always succeed for now: users # may not yet have an rfcomm-enabled kernel if test $VERBOSE != no { log_progress_msg $(RFCOMM##*/) $RFCOMM -f $RFCOMM_CONF bind all || : } else { $RFCOMM -f $RFCOMM_CONF bind all >/dev/null !2 > !1 || : } } } proc stop_rfcomm { if test -x $RFCOMM { if test $VERBOSE != no { log_progress_msg $(RFCOMM##*/) $RFCOMM unbind all || : } else { $RFCOMM unbind all >/dev/null !2 > !1 || : } } } proc restart_rfcomm { if test -x $RFCOMM && test -f $RFCOMM_CONF { if test $VERBOSE != no { log_progress_msg $(RFCOMM##*/) $RFCOMM unbind all || : $RFCOMM -f $RFCOMM_CONF bind all || : } else { $RFCOMM unbind all >/dev/null !2 > !1|| : $RFCOMM -f $RFCOMM_CONF bind all >/dev/null !2 > !1 || : } } } matchstr $1 { start { log_daemon_msg "Starting $DESC" if test $BLUETOOTH_ENABLED = 0 { log_progress_msg "disabled. see /etc/default/bluetooth" log_end_msg 0 exit 0 } start-stop-daemon --start $SSD_OPTIONS log_progress_msg $(DAEMON##*/) run_sdptool || : start_uarts || : if test $HID2HCI_ENABLED = 1 { enable_hci_input } start_rfcomm || : if test $HIDD_ENABLED = 1 || test $PAND_ENABLED = 1 || test $DUND_ENABLED = 1 { log_progress_msg "compatibily daemons not started, see bluez-compat package" } log_end_msg 0 } stop { log_daemon_msg "Stopping $DESC" if test $BLUETOOTH_ENABLED = 0 { log_progress_msg "disabled." log_end_msg 0 exit 0 } stop_rfcomm || : if test $HID2HCI_UNDO = 1 { disable_hci_input } start-stop-daemon --stop $SSD_OPTIONS log_progress_msg $(DAEMON) stop_uarts || : log_end_msg 0 } restart|force-reload { $0 stop sleep 1 $0 start } status { status_of_proc $DAEMON $DESC && exit 0 || exit $Status } * { global N := '/etc/init.d/bluetooth' echo "Usage: $N {start|stop|restart|force-reload|status}" > !2 exit 1 } } exit 0 # vim:noet