home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / etc / init.d / bluetooth < prev    next >
Encoding:
Text File  |  2006-08-30  |  6.6 KB  |  289 lines

  1. #! /bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides: bluetooth
  4. # Short-Description: Start bluez bluetooth userspace daemons
  5. ### END INIT INFO
  6. #
  7. # bluez-utils    Bluetooth subsystem starting and stopping
  8. #
  9. # originally from bluez's scripts/bluetooth.init
  10. #
  11. # Edd Dumbill <ejad@debian.org>
  12. # LSB 3.0 compilance and enhancements  by Filippo Giunchedi <filippo@debian.org>
  13. #
  14. # startup control over dund and pand can be changed by 
  15. # editing /etc/default/bluez-utils
  16.  
  17. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  18. DESC="Bluetooth services"
  19.  
  20. HCID=/usr/sbin/hcid
  21. HCIATTACH=/usr/sbin/hciattach
  22. HCID_NAME=hcid
  23. HCID_OPTIONS=-x
  24.  
  25. HID2HCI=/usr/sbin/hid2hci
  26.  
  27. UART_CONF=/etc/bluetooth/uart
  28.  
  29. RFCOMM=/usr/bin/rfcomm
  30. RFCOMM_NAME=rfcomm
  31. RFCOMM_CONF=/etc/bluetooth/rfcomm.conf
  32.  
  33. SDPD=/usr/sbin/sdpd
  34. SDPD_NAME=sdpd
  35.  
  36. SDPTOOL=/usr/bin/sdptool
  37.  
  38. DUND_DAEMON=/usr/bin/dund
  39. DUND_NAME=dund
  40. PAND_DAEMON=/usr/bin/pand
  41. PAND_NAME=pand
  42. HIDD_DAEMON=/usr/bin/hidd
  43. HIDD_NAME=hidd
  44.  
  45. DUND_ENABLED=0
  46. PAND_ENABLED=0
  47. HIDD_ENABLED=0
  48. DUND_OPTIONS=""
  49. PAND_OPTIONS=""
  50. HIDD_OPTIONS="--master --server"
  51.  
  52. test -f /etc/default/bluetooth && . /etc/default/bluetooth
  53. test -f /etc/default/rcS && . /etc/default/rcS
  54.  
  55. . /lib/lsb/init-functions
  56.  
  57. # test for essential daemons
  58. test -x $HCID || exit 0
  59. test -x $HCIATTACH || exit 0
  60. test -x $RFCOMM || exit 0
  61. test -x $SDPD || exit 0
  62.  
  63. # disable nonessential daemons if not present
  64. if test "$DUND_ENABLED" != "0"; then
  65.     if ! test -f $DUND_DAEMON; then
  66.         DUND_ENABLED=0
  67.     fi
  68. fi
  69.  
  70. if test "$PAND_ENABLED" != "0"; then
  71.     if ! test -f $PAND_DAEMON; then
  72.         PAND_ENABLED=0
  73.     fi
  74. fi
  75.  
  76. if test "$HIDD_ENABLED" != "0"; then
  77.     if ! test -f $HIDD_DAEMON; then
  78.         HIDD_ENABLED=0
  79.     fi
  80. fi
  81.  
  82. set -e
  83.  
  84. run_sdptool()
  85. {
  86.     test -x $SDPTOOL || return 1 
  87.  
  88.     if ! test -z "$SDPTOOL_OPTIONS" ; then
  89.         IFS=";"
  90.         for o in $SDPTOOL_OPTIONS ; do
  91.             #echo "execing $SDPTOOL $o"
  92.             $SDPTOOL $o &>/dev/null
  93.         done
  94.     fi
  95.  
  96. }
  97.  
  98. enable_hci_input()
  99. {
  100.        if [ "$VERBOSE" != no ]; then
  101.                log_success_msg "Switching on Bluetooth input devices..."
  102.                $HID2HCI --tohci
  103.        else
  104.                $HID2HCI --tohci >/dev/null 2>&1
  105.        fi
  106. }
  107.  
  108. disable_hci_input()
  109. {
  110.        if [ "$VERBOSE" != no ]; then
  111.                log_success_msg "Switching Bluetooth input devices back to HID mode..."
  112.                $HID2HCI --tohid
  113.        else
  114.                $HID2HCI --tohid >/dev/null 2>&1
  115.        fi
  116. }
  117.  
  118. start_pan()
  119. {
  120.     if test "$DUND_ENABLED" != "0"; then
  121.         start-stop-daemon --start --quiet --exec $DUND_DAEMON -- $DUND_OPTIONS
  122.         [ "$VERBOSE" != no ] && log_success_msg "Starting $DUND_NAME..."
  123.  
  124.     fi
  125.     if test "$PAND_ENABLED" != "0"; then
  126.         start-stop-daemon --start --quiet --exec $PAND_DAEMON -- $PAND_OPTIONS
  127.         [ "$VERBOSE" != no ] && log_success_msg "Starting $PAND_NAME..."
  128.     fi
  129. }
  130.  
  131.  
  132. stop_pan()
  133. {
  134.     if test "$DUND_ENABLED" != "0"; then
  135.         start-stop-daemon --stop --quiet --exec $DUND_DAEMON || true
  136.         [ "$VERBOSE" != no ] && log_success_msg "Stopping $DUND_NAME..."
  137.     fi
  138.     if test "$PAND_ENABLED" != "0"; then
  139.         start-stop-daemon --stop --quiet --exec $PAND_DAEMON || true
  140.         [ "$VERBOSE" != no ] && log_success_msg "Stopping $PAND_NAME..."
  141.     fi
  142. }
  143.  
  144. start_hid()
  145. {
  146.     if test "$HIDD_ENABLED" != "0"; then
  147.         start-stop-daemon --start --quiet --exec $HIDD_DAEMON -- $HIDD_OPTIONS
  148.         [ "$VERBOSE" != no ] && log_success_msg "Starting $HIDD_NAME..."
  149.     fi
  150. }
  151.  
  152. stop_hid()
  153. {
  154.     if test "$HIDD_ENABLED" != "0"; then
  155.         $HIDD_DAEMON --killall
  156.         start-stop-daemon --stop --quiet --exec $HIDD_DAEMON || true
  157.         [ "$VERBOSE" != no ] && log_success_msg "Stopping $HIDD_NAME..."
  158.     fi
  159. }
  160.  
  161. start_uarts()
  162. {
  163.     [ -f $HCIATTACH ] && [ -f $UART_CONF ] || return
  164.     grep -v '^#' $UART_CONF | while read i; do
  165.                if [ "$VERBOSE" != no ]; then
  166.                        $HCIATTACH $i
  167.                else
  168.                        $HCIATTACH $i >/dev/null 2>&1
  169.                fi
  170.     done
  171. }
  172.  
  173. stop_uarts()
  174. {
  175.     killall hciattach > /dev/null 2>&1 || true
  176. }
  177.  
  178. start_rfcomm()
  179. {
  180.     if [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] ; then
  181.         # rfcomm must always succeed for now: users
  182.         # may not yet have an rfcomm-enabled kernel
  183.                 if [ "$VERBOSE" != no ]; then
  184.                        log_success_msg "Starting $RFCOMM_NAME..."
  185.                        $RFCOMM -f $RFCOMM_CONF bind all || true
  186.                 else
  187.                        $RFCOMM -f $RFCOMM_CONF bind all >/dev/null 2>&1 || true
  188.                 fi
  189.     fi
  190. }
  191.  
  192. stop_rfcomm()
  193. {
  194.     if [ -x $RFCOMM ] ; then
  195.                if [ "$VERBOSE" != no ]; then
  196.                        log_success_msg "Stopping $RFCOMM_NAME..."
  197.                        $RFCOMM unbind all || true
  198.                else
  199.                        $RFCOMM unbind all >/dev/null 2>&1 || true
  200.                fi
  201.     fi
  202. }
  203.  
  204. restart_rfcomm()
  205. {
  206.     if [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] ; then
  207.                if [ "$VERBOSE" != no ]; then
  208.                        log_success_msg  "Restarting $RFCOMM_NAME..."
  209.                        $RFCOMM unbind all || true
  210.                        $RFCOMM -f $RFCOMM_CONF bind all || true
  211.                else
  212.                        $RFCOMM unbind all >/dev/null 2>&1|| true
  213.                        $RFCOMM -f $RFCOMM_CONF bind all >/dev/null 2>&1 || true
  214.                fi
  215.     fi
  216. }
  217.  
  218. case "$1" in
  219.   start)
  220.     log_daemon_msg "Starting $DESC"
  221.     
  222.     if test "$BLUETOOTH_ENABLED" == "0"; then
  223.         log_progress_msg "disabled. see /etc/default/bluetooth"
  224.         log_end_msg 0
  225.         exit 0
  226.     fi
  227.  
  228.     start-stop-daemon --start --quiet --exec $HCID -- $HCID_OPTIONS || true
  229.     log_progress_msg "hcid"
  230.     start_uarts || true
  231.     
  232.     start-stop-daemon --start --quiet --exec $SDPD || true
  233.     log_progress_msg "sdpd"
  234.     
  235.     run_sdptool || true
  236.     log_progress_msg "sdp_options"
  237.  
  238.     start_hid || true
  239.     enable_hci_input || true
  240.     start_rfcomm || true
  241.     start_pan || true
  242.     log_end_msg 0
  243.     ;;
  244.   stop)
  245.     log_daemon_msg "Stopping $DESC"
  246.     stop_pan || true
  247.     stop_rfcomm || true
  248.     disable_hci_input || true
  249.     stop_hid || true
  250.     start-stop-daemon --stop --quiet --exec $SDPD || true
  251.     log_progress_msg "$SDPD_NAME"
  252.     start-stop-daemon --stop --quiet --exec $HCID || true
  253.     log_progress_msg "$HCID_NAME"
  254.     stop_uarts || true
  255.     log_end_msg 0
  256.     ;;
  257.   restart|force-reload)
  258.     log_daemon_msg "Restarting $DESC"
  259.     stop_hid || true
  260.     stop_pan || true
  261.     start-stop-daemon --stop --quiet --exec $SDPD || true
  262.     start-stop-daemon --stop --quiet --exec $HCID || true
  263.     sleep 1
  264.     if test "$BLUETOOTH_ENABLED" == "0"; then
  265.         log_progress_msg "disabled. see /etc/default/bluetooth"
  266.         log_end_msg 0
  267.         exit 0
  268.     fi
  269.     start-stop-daemon --start --quiet --exec $HCID || true
  270.     start-stop-daemon --start --quiet --exec $SDPD || true
  271.     log_progress_msg "$HCID_NAME"
  272.     log_progress_msg "$SDPD_NAME"
  273.     start_pan || true
  274.     start_hid || true
  275.     restart_rfcomm
  276.     log_end_msg 0
  277.     ;;
  278.   *)
  279.     N=/etc/init.d/bluetooth
  280.     # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
  281.     echo "Usage: $N {start|stop|restart|force-reload}" >&2
  282.     exit 1
  283.     ;;
  284. esac
  285.  
  286. exit 0
  287.  
  288. # vim:noet
  289.