Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # L Nix <lornix@lornix.com>
  4. # setup-bt-kb : allow choosing & pairing a bluetooth keyboard from the console
  5. #
  6. declare -a addrlist
  7. #
  8. while [ 1 ]; do
  9. echo -n "Scanning for Bluetooth devices ... "
  10. readarray -n 10 -O 0 -t addrlist < <(hcitool scan|grep -v "^Scanning"|sed -e "s/^[ t]//g" -e "s/t/ /g" | head -n 9)
  11. echo
  12. echo
  13. length=${#addrlist[@]}
  14. a=1
  15. while [ ${a} -le ${length} ]; do
  16. echo "$a) ${addrlist[$a-1]}"
  17. a=$((a + 1))
  18. done
  19. echo
  20. while [ 1 ]; do
  21. if [ ${length} -gt 0 ]; then
  22. echo -n "Choose (1-${length}), or "
  23. fi
  24. echo -n "'R' to rescan: "
  25. read -n 1 REPLY
  26. echo
  27. case ${REPLY} in
  28. Q)
  29. # just quit
  30. exit 0
  31. ;;
  32. [0rR])
  33. echo
  34. REPLY=0
  35. break
  36. ;;
  37. [123456789])
  38. if [ ${REPLY} -le ${length} ]; then
  39. echo "Got ${REPLY}"
  40. break
  41. fi
  42. ;;
  43. *)
  44. ;;
  45. esac
  46. done
  47. if [ ${REPLY} -gt 0 ]; then
  48. break
  49. fi
  50. done
  51. #
  52. device=${addrlist[${REPLY}-1]}
  53. #
  54. BTADDR=${device/% *}
  55. BTNAME=${device/#??:??:??:??:??:?? }
  56. #
  57. echo "selecting '${BTNAME}' at ${BTADDR}"
  58. #
  59. echo "Pairing with ${BTNAME} (Generally '0000')"
  60. bluez-simple-agent hci0 ${BTADDR}
  61. #
  62. echo "Setting trust level with ${BTNAME}"
  63. bluez-test-device trusted ${BTADDR} yes
  64. #
  65. echo "Connecting to ${BTNAME}"
  66. bluez-test-input connect ${BTADDR}
  67. #
  68. echo "Completed"
  69.  
  70. bluez-test-device remove MAC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement