Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Because I need to use my keyboard to log in, I would like my keyboard pair automatically, pre-log in.

I am using Debian squeeze, and am new to linux. All tutorials I have found seem to require the HIDD package, which has been deprecated (I think) on current Debian releases.

Apt-get install returns a package not found in repo response.

Does anyone have a method to slove this problem?

If it matters, I am using Debian Squeeze on a Raspberry Pi, and an Apple Bluetooth Keyboard/Magic Trackpad.

share|improve this question

1 Answer 1

I occasionally use the following script to add bluetooth keyboards to my systems, it adds it at a system level, rather than a user level, which seems to make things work right from the boot, and my keyboard(s) are usable from the login prompt.

As written, you'll need bash (v4.0+ hopefully) and the bluez package, which supplies the bluez-simple-agent, bluez-test-device, bluez-test-input programs.

Most of the code below is to implement a list to allow you to choose which device, it really just boils down to the last 6 (non-comment) lines, if you know your BT MAC Address, you can replace all the choice stuff with a static assignment.

#!/bin/bash
#
# L Nix <lornix@lornix.com>
# setup-bt-kb : allow choosing & pairing a bluetooth keyboard from the console
#
declare -a addrlist
#
while [ 1 ]; do
    echo -n "Scanning for Bluetooth devices ... "
    readarray -n 10 -O 0 -t addrlist < <(hcitool scan|grep -v "^Scanning"|sed -e "s/^[ \t]//g" -e "s/\t/ /g" | head -n 9)
    echo
    echo
    length=${#addrlist[@]}
    a=1
    while [ ${a} -le ${length} ]; do
        echo "$a) ${addrlist[$a-1]}"
        a=$((a + 1))
    done
    echo
    while [ 1 ]; do
        if [ ${length} -gt 0 ]; then
            echo -n "Choose (1-${length}), or "
        fi
        echo -n "'R' to rescan: "
        read -n 1 REPLY
        echo
        case ${REPLY} in
            Q)
                # just quit
                exit 0
                ;;
            [0rR])
                echo
                REPLY=0
                break
                ;;
            [123456789])
                if [ ${REPLY} -le ${length} ]; then
                    echo "Got ${REPLY}"
                    break
                fi
                ;;
            *)
                ;;
        esac
    done
    if [ ${REPLY} -gt 0 ]; then
        break
    fi
done
#
device=${addrlist[${REPLY}-1]}
#
BTADDR=${device/% *}
BTNAME=${device/#??:??:??:??:??:?? }
#
echo "selecting '${BTNAME}' at ${BTADDR}"
#
echo "Pairing with ${BTNAME} (Generally '0000')"
bluez-simple-agent hci0 ${BTADDR}
#
echo "Setting trust level with ${BTNAME}"
bluez-test-device trusted ${BTADDR} yes
#
echo "Connecting to ${BTNAME}"
bluez-test-input connect ${BTADDR}
#
echo "Completed"
share|improve this answer
    
Thanks for the answer. I'm new to Linux. Can you please breakdown the script and explain what each part does? Especially the last '6 lines' you mentioned? –  zenbike Aug 10 '12 at 13:16
    
No. That's a lot of work, and not enough room here. It's easy to read, '#' starts a comment, you can read those... the rest are statements, which are generally self-explanatory. I suppose it's the last 10 lines, including the comments, which do all the actual work, the rest is pretty-stuff to make selecting a device easy. they invoke the bluez programs to add, pair and connect a desired device, using the Bluetooth ID (MAC) discovered in the top part of the script. Read the man pages for the programs, read the BASH man page for how scripting with BASH works. Learn to discover and explore. –  lornix Aug 10 '12 at 18:28
    
Almost EVERY command accepts the -h or --help options to describe their operation, and most have man pages (man bash, man bluez-test-input... etc) . Try things, explore, learn, discover. Read the BASH man page for help on scripting, the man pages for the various commands, mostly the bluez-... commands. –  lornix Aug 10 '12 at 18:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.