implemented trust menu and autotrust

This commit is contained in:
Alexander Bocken 2020-06-09 20:20:35 +02:00
parent 3dbb35c5e5
commit 28661c0ab3
2 changed files with 17 additions and 1 deletions

View File

@ -44,5 +44,5 @@ make uninstall
Here's a growing list of features that are not yet actively worked on but might be nice in the future. Currently I'm more concerned with reliability than fulfilling feature requests, but I'm still open to put some on this list.
- start scanning for new devices immediately at execution to save time when pairing new devices -> Implemented (I think, seems to be working at least)
- auto-trust newly paired devices/trust device via dmenu
- auto-trust newly paired devices/trust device via dmenu -> Implemented changeable via the AUTOTRUST variable in the beginning of bt, menu display adjusts accordingly
- blacklist devices via dmenu

16
bt
View File

@ -4,11 +4,18 @@ SCAN_PERIOD=5
#locations of blacklist and hard coded list of paired devices (watch out, need to modify Makefile as well if you want to change these values and still use make install)
BLACKLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/blacklist
PAIRLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/paired
AUTOTRUST=true
actions="turn off
turn on
pair
unpair"
if ! $AUTOTRUST; then
actions+="
trust"
fi
#Checks for necessary programs to be present. Very unlikely not to be present but let's just err on the safer side.
for prog in dmenu bluetoothctl awk cat date nl; do
if ! hash "$prog" 2>/dev/null; then
@ -68,6 +75,9 @@ pair(){
bluetoothctl pair "$dev_id" && sleep 2
bluetoothctl connect "$dev_id"
if $AUTOTRUST; then
bluetoothctl trust "$dev_id"
fi
#if device is not already hard coded as paired, add to paired devices list
if grep -q "$dev_id" "$PAIRLIST"
then
@ -96,6 +106,12 @@ case $choice in
echo "$new_paired_list" > "$PAIRLIST"
fi
cleanup;;
"trust") choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'remove which paired device?')
if [ -n "$choice" ]; then
dev_no=$( echo "$paired_devices" | nl | grep -P "[0-9]+\t$choice$" | awk '{print $1}')
dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}' )
bluetoothctl trust "$dev_id"
fi
esac
if [ -n "$choice" ]; then