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 ################################################################################
9 . /etc/grml/lsb-functions
11 if [ "$(id -ru)" != "0" ] ; then
12 eerror "Need root privileges. Please run $0 as user root." ; eend 1
18 einfo "Starting bluetooth support."
21 if pgrep dbus-daemon 1>/dev/null; then
22 einfo "dbus already running." ; eend 0
24 einfo "Starting dbus."
25 /etc/init.d/dbus start 1>/dev/null ; eend $?
28 if pgrep sdpd 1>/dev/null; then
29 einfo "Main bluetooth daemons seem to be already running." ; eend 0
31 einfo "Starting main bluetooth support."
32 /etc/init.d/bluetooth start 1>/dev/null ; eend $?
35 if pgrep hcid 1>/dev/null; then
36 einfo "hcid already running."
38 einfo "Starting hcid."
40 if start-stop-daemon --start --exec /usr/sbin/hcid 1>$HCIINFO 2>&1 ; then
44 eerror "hcid could not be started: `cat $HCIINFO`. Exiting."
50 einfo "Loading bluetooth modules:"
51 for module in bluetooth ohci1394 hci_usb ; do
53 einfo "$module" ; modprobe $module ; eend $?
57 einfo "Scanning for human input device(s). Press the 'connect' button on the device!"
58 einfo "Scanning might take a while. Searching..."
61 if hidd --search 1>${SUCCESS} 2>${ERROR} ; then
62 if ! grep -q 'Connecting to device' $SUCCESS ; then
63 eerror "Could not find any devices. Exiting." ; eend 1
66 ID=$(awk '/Connecting to device/ {print $4}' $SUCCESS)
67 if [ -n "$ID" ] ; then
68 einfo "Success: connected device ${ID}." ; eend 0
69 logger -t "bluez-connect" "connected human input device ${ID}"
71 ewarn "Warning: searching for device succeded but no connection could be established."
75 eerror "Error: `cat $ERROR`" ; eend 1
80 einfo "Stopping hcid."
81 killall hcid ; eend $? # workaround because start-stop-daemon does not work :-/
82 einfo "Disconnecting all human input devices."
83 logger -t "bluez-connect" "disconnected all human input devices"
84 hidd --killall ; eend $?
92 local INFO="$(hidd --show)"
93 einfo "$0 - checking status:"
95 if pgrep hcid 1>/dev/null ; then
96 einfo "hcid running." ; eend 0
98 eerror "hcid not running." ; eend 1
100 if [ -n "$INFO" ] ; then
101 einfo "$INFO" ; eend 0
103 eerror "No devices connected." ; eend 1
108 echo "Usage: $0 {start|stop|status|restart|force-reload}"
117 ## END OF FILE #################################################################