32 lines
1.1 KiB
Bash
Executable File
32 lines
1.1 KiB
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>
|
|
|
|
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"
|
|
# bluetoothd just converts my symlinks into plain files anyway, so may as well cp directly
|
|
cp "$srcdir/$f" "$condir/info"
|
|
# ln -sf --no-dereference "$srcdir/$f" "$condir/info"
|
|
touch "$condir/attributes"
|
|
done
|