Lines Matching +full:count +full:- +full:up
2 #-
3 # ----------------------------------------------------------------------------
4 # "THE BEER-WARE LICENSE" (Revision 42):
7 # this stuff is worth it, you can buy me a beer in return Poul-Henning Kamp
8 # ----------------------------------------------------------------------------
13 exerr () { echo -e "Error: $*" >&2 ; exit 1; }
14 print_syntax () { echo -e "Syntax: $0 scan [-d device] [-n node]"; exit 1; }
31 shift "$((OPTIND-1))"
34 [ "$#" -eq 0 ] || print_syntax
39 if [ $( id -u ) -ne 0 ]; then
40 exerr "$0 must modify files that belong to root. Re-run as root."
44 /usr/bin/tail -n +2 | /usr/bin/cut -d ' ' -f 1 )
49 /usr/bin/grep -o "Name: .* Type: ubt" |/usr/bin/cut -d' ' -f2 )
56 # Found the node but its stack is not set up? Do it now.
62 # If we have Bluetooth controller nodes without a set up stack,
63 # ask the user if we shall start it up
68 prompt="Choose a host controller to set up: [${ng_nodes%% *}]"
69 read -p "${prompt}" node
74 # Re-read known nodes
76 /usr/bin/tail -n +2 | /usr/bin/cut -d ' ' -f 1 )
78 # check if we succeeded in bringing it up
79 [ "${known_nodes}" ] || exerr "Failed to set up Bluetooth stack"
92 [ "${node}" ] && node="-n ${node}"
98 bdaddresses=$( /usr/sbin/hccontrol -N ${node} inquiry 2>/dev/null |
99 /usr/bin/grep -o "BD_ADDR: .*" | /usr/bin/cut -d ' ' -f 2 )
101 # Count entries and, if a device was requested on command line,
103 unset found count
105 count=X${count}
109 count=X
116 if ! [ "${found}" -o "${count}" -a -z "${device}" ]; then
118 if [ "${#retry}" -eq 5 ]; then
127 [ ${#count} -gt 1 ] && plural=s || plural=''
128 printf "done.\nFound %d new bluetooth device%s " ${#count} ${plural}
132 unset count
134 count=X${count}
135 bdname=$( /usr/bin/bthost -b "${bdaddress}" 2>/dev/null )
138 /usr/bin/grep -o "Name: .*" |/usr/bin/cut -d ' ' -f 2- )
141 printf "[%2d] %s\t\"%s\" (%s)\n" ${#count} "${bdaddress}" \
144 eval bdaddress_${#count}=\${bdaddress}
145 eval bdname_${#count}=\${bdname}
146 eval friendlyname_${#count}=\${friendlyname}
149 # If a device was pre-selected, do not query the user
155 [ ${#count} -gt 1 ] && prompt="${prompt}-${#count}"
156 read -p "${prompt}, or 0 to rescan]: " topair
157 if ! [ "${topair}" -ge 0 -a "${topair}" -le "${#count}" ] \
164 [ "${topair}" -eq "0" ] && unset bdaddresses retry
176 read -p "Enter friendly name. [${friendlyname}]: " _r
180 # Remove white space and non-friendly characters
181 bdname=$( printf "%s" "${_r}" | tr -c '[:alnum:]-,.' _ )
206 read -p "Enable hcsecd? [yes]: " _r
213 secd_config=$( /usr/sbin/sysrc -n hcsecd_config )
214 secd_entries=$( /usr/bin/grep -Eo "bdaddr[[:space:]]+(${bdaddress}|${bdname})" \
222 read -p "Continue? [yes]: " _r
228 read -p "Enter PIN [nopin]: " pin
242 # also, if there's a way to force devices to re-pair, try this
246 # first up: HID
248 /usr/sbin/sdpcontrol -a "${bdaddress}" search HID | \
249 /usr/bin/grep -q "^Record Handle: " || exit 0
252 read -p "Set it up? [yes]: " _r
258 # Here we have found an HID and were asked to set it up
264 read -p "Enable bthidd? [yes]: " _r
272 bthidd_known=$( /usr/sbin/bthidcontrol -a "${bdaddress}" known | \
280 bthidd_config=$( /usr/sbin/sysrc -n bthidd_config )
282 /usr/sbin/bthidcontrol -a "${bdaddress}" query >> "${bthidd_config}"
284 # Re-read config to see if we succeeded adding the device
285 bthidd_known=$( /usr/sbin/bthidcontrol -a "${bdaddress}" known | \
290 printf "success.\nTo re-read its config, bthidd must be restarted.\n"
295 read -p "Restart bthidd now? [yes]: " _r