Files
nix-files/scripts/install-bluetooth
colin c063ecd047 bluetooth keys: use sane.fs instead of activationScripts
also auto-determines the device ID, which was previously broken
2023-01-07 03:43:31 +00:00

30 lines
994 B
Bash
Executable File

#!/bin/sh
# usage: install-bluetooth <source_dir> <destdir>
# source_dir contains plain-text files of any filename.
# for each file, this extracts the MAC and creates a symlink in destdir which
# points to the original file, using the MAC name as file path
#
# bluetooth connection structure is /var/lib/bluetooth/<HOST_MAC>/<DEVICE_MAX>/{attributes,info}
# bluetoothd/main.conf options can be found here:
# - <https://pythonhosted.org/BT-Manager/config.html>
set -ex
srcdir="$1"
destdir="$2"
if [ "x$destdir" = "x" ]
then
devmac=$(cat /sys/kernel/debug/bluetooth/hci0/identity | cut -f 1 -d' ' | tr "a-z" "A-Z")
# default to the first MAC address on the host
destdir="/var/lib/bluetooth/$devmac"
test -d "$destdir" || mkdir "$destdir" || test -d "$destdir"
fi
for f in $(ls "$srcdir")
do
mac=$(sed -rn 's/# MAC=(.*)/\1/p' "$srcdir/$f")
condir="$destdir/$mac"
test -d "$condir" || mkdir "$condir" || test -d "$condir"
ln -sf --no-dereference "$srcdir/$f" "$condir/info"
done