#!/bin/sh # This script has been written by Dave Mielke . It's a light # weight, text mode, Bluetooth PIN helper script. Its dependencies are: # * /bin/sh The standard system command shell. # * open A command which opens a free virtual terminal. # * dialog A command which presents a text-mode dialog. # # The file /etc/bluetooth/pins is searched for a line corresponding to the # Bluetooth address of the device. Each line of this file should contain the # address of a device and its PIN, in that order, separated by space. If the # address is found then the corresponding PIN is automatically supplied. If # it's not found then the user is prompted via a text-mode dialog in a free # virtual terminal. The console automatically returns to the original virtual # terminal as soon as the PIN is entered. pinsFile="/etc/bluetooth/pins" pinLimit=16 [ "${#}" -gt 0 ] && { direction="${1}" shift [ "${#}" -gt 0 ] && { address="${1}" shift if [ "${#}" -gt 0 ] then name="${1}" shift else name="" fi [ -f "${pinsFile}" -a -r "${pinsFile}" ] && exec <"${pinsFile}" && { while read a p x do [ "${a}" = "${address}" ] && { echo "PIN:${p}" exit 0 } done } if [ "${direction}" = "out" ] then adjective="outgoing" preposition="to" else adjective="incoming" preposition="from" fi title="Bluetooth PIN Prompt" time="`date '+%Y-%m-%d@%H:%M:%S'`" prompt="Enter PIN for ${adjective} Bluetooth connection ${preposition} ${name}[${address}]" pin="`open 3>&1 -s -w -- dialog --output-fd 3 --clear --title "${title}" --cr-wrap --max-input "${pinLimit}" --inputbox "${time}\n\n${prompt}" 0 0 ""`" [ -n "${pin}" ] && { echo "PIN:${pin}" exit 0 } } } echo ERR exit 0