3 # Purpose: connect human input device via bluetooth to local system
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 # Latest change: Die Aug 08 19:58:41 CEST 2006 [mika]
8 ################################################################################
10 . /etc/grml/lsb-functions
12 if [ $UID != 0 ] ; then
13 eerror "Need root privileges. Please run $0 as user root." ; eend 1
19 einfo "Starting bluetooth support."
22 if pgrep dbus-daemon 1>/dev/null; then
23 einfo "dbus already running." ; eend 0
25 einfo "Starting dbus."
26 /etc/init.d/dbus start 1>/dev/null ; eend $?
29 if pgrep sdpd 1>/dev/null; then
30 einfo "Main bluetooth daemons seem to be already running." ; eend 0
32 einfo "Starting main bluetooth support."
33 /etc/init.d/bluetooth start 1>/dev/null ; eend $?
36 if pgrep hcid 1>/dev/null; then
37 einfo "hcid already running."
39 einfo "Starting hcid."
41 if start-stop-daemon --start --exec /usr/sbin/hcid 1>$HCIINFO 2>&1 ; then
45 eerror "hcid could not be started: `cat $HCIINFO`. Exiting."
51 einfo "Loading bluetooth modules:"
52 for module in bluetooth ohci1394 hci_usb ; do
54 einfo "$module" ; modprobe $module ; eend $?
58 einfo "Scanning for human input device(s). Press the 'connect' button on the device!"
59 einfo "Scanning might take a while. Searching..."
62 if hidd --search 1>${SUCCESS} 2>${ERROR} ; then
63 if ! grep -q 'Connecting to device' $SUCCESS ; then
64 eerror "Could not find any devices. Exiting." ; eend 1
67 ID=$(awk '/Connecting to device/ {print $4}' $SUCCESS)
68 if [ -n "$ID" ] ; then
69 einfo "Success: connected device ${ID}." ; eend 0
70 logger -t "bluez-connect" "connected human input device ${ID}"
72 ewarn "Warning: searching for device succeded but no connection could be established."
76 eerror "Error: `cat $ERROR`" ; eend 1
81 einfo "Stopping hcid."
82 killall hcid ; eend $? # workaround because start-stop-daemon does not work :-/
83 einfo "Disconnecting all human input devices."
84 logger -t "bluez-connect" "disconnected all human input devices"
85 hidd --killall ; eend $?
93 local INFO="$(hidd --show)"
94 einfo "$0 - checking status:"
96 if pgrep hcid 1>/dev/null ; then
97 einfo "hcid running." ; eend 0
99 eerror "hcid not running." ; eend 1
101 if [ -n "$INFO" ] ; then
102 einfo "$INFO" ; eend 0
104 eerror "No devices connected." ; eend 1
109 echo "Usage: $0 {start|stop|status|restart|force-reload}"
118 ## END OF FILE #################################################################