Last active
May 27, 2019 02:23
-
-
Save bskiefer/f5a1eaf658f51767b6f69c2fd732e45d to your computer and use it in GitHub Desktop.
Connect rpi bluetooth devices automatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BLUETOOTH_DIR=/var/lib/bluetooth | |
for CONTROLLER_DIR in ${BLUETOOTH_DIR}/*; do | |
CONTROLLER_MAC=$(basename ${CONTROLLER_DIR}) | |
if [ -d "${CONTROLLER_DIR}" ] && [[ $CONTROLLER_MAC =~ ^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$ ]] ; then | |
for DEVICE_DIR in ${CONTROLLER_DIR}/*; do | |
DEVICE_MAC=$(basename ${DEVICE_DIR}) | |
if [ -d "${DEVICE_DIR}" ] && [[ $DEVICE_MAC =~ ^([0-9A-F]{2}[:]){5}([0-9A-F]{2})$ ]] ; then | |
if grep "Trusted=true" ${DEVICE_DIR}/info > /dev/null ; then | |
echo -e "select ${CONTROLLER_MAC}\nconnect ${DEVICE_MAC}\nquit" | bluetoothctl > /dev/null 2>&1 | |
fi | |
fi | |
done | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment