From 0c436ae7d56378e7782a2e7905b7eecc637acbc7 Mon Sep 17 00:00:00 2001 From: Amartya Nambiar Date: Mon, 21 Nov 2022 19:57:54 +0530 Subject: [PATCH 1/4] try out various disconnection methods --- disable_bluetooth.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/disable_bluetooth.sh b/disable_bluetooth.sh index 510da7e..18f5508 100644 --- a/disable_bluetooth.sh +++ b/disable_bluetooth.sh @@ -1,5 +1,8 @@ #!/bin/bash + +# blueutil --disconnect db-a0-7d-17-8e-8e --wait-disconnect db-a0-7d-17-8e-8e +# blueutil --disconnect 74-45-ce-bc-1f-26 --wait-disconnect 74-45-ce-bc-1f-26 blueutil --power 0 # Uncomment to debug -# echo "[$(date)] :attempting to disable bluetooth" >> ~/bluetooth.log +# echo "[$(date)] :attempting to disable bluetooth" >> ~/bluetooth.log \ No newline at end of file From 0a32b78c5e2850197574ea3fd38f79551109a0a0 Mon Sep 17 00:00:00 2001 From: Amartya Nambiar <51471924+amartyanambiar@users.noreply.github.com> Date: Mon, 21 Nov 2022 19:59:28 +0530 Subject: [PATCH 2/4] Delete disable_bluetooth.sh --- disable_bluetooth.sh | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 disable_bluetooth.sh diff --git a/disable_bluetooth.sh b/disable_bluetooth.sh deleted file mode 100644 index 18f5508..0000000 --- a/disable_bluetooth.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -# blueutil --disconnect db-a0-7d-17-8e-8e --wait-disconnect db-a0-7d-17-8e-8e -# blueutil --disconnect 74-45-ce-bc-1f-26 --wait-disconnect 74-45-ce-bc-1f-26 -blueutil --power 0 - -# Uncomment to debug -# echo "[$(date)] :attempting to disable bluetooth" >> ~/bluetooth.log \ No newline at end of file From 4996052386af4977262f0458b289c801a456a3c9 Mon Sep 17 00:00:00 2001 From: Amartya Nambiar Date: Mon, 21 Nov 2022 20:01:29 +0530 Subject: [PATCH 3/4] wake to connect previously paired devices --- PairedDevices.txt | 2 ++ disable_bluetooth.sh | 8 ++++++++ enable_bluetooth.sh | 8 ++++++++ setup.sh | 5 +++++ 4 files changed, 23 insertions(+) create mode 100644 PairedDevices.txt create mode 100644 disable_bluetooth.sh diff --git a/PairedDevices.txt b/PairedDevices.txt new file mode 100644 index 0000000..16c3430 --- /dev/null +++ b/PairedDevices.txt @@ -0,0 +1,2 @@ +74-45-ce-bc-1f-26 +db-a0-7d-17-8e-8e diff --git a/disable_bluetooth.sh b/disable_bluetooth.sh new file mode 100644 index 0000000..18f5508 --- /dev/null +++ b/disable_bluetooth.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# blueutil --disconnect db-a0-7d-17-8e-8e --wait-disconnect db-a0-7d-17-8e-8e +# blueutil --disconnect 74-45-ce-bc-1f-26 --wait-disconnect 74-45-ce-bc-1f-26 +blueutil --power 0 + +# Uncomment to debug +# echo "[$(date)] :attempting to disable bluetooth" >> ~/bluetooth.log \ No newline at end of file diff --git a/enable_bluetooth.sh b/enable_bluetooth.sh index 4565b12..d08a55a 100644 --- a/enable_bluetooth.sh +++ b/enable_bluetooth.sh @@ -1,5 +1,13 @@ #!/bin/bash +SLEEP_SCRIPTS_DIR=~/.sleepscripts + blueutil --power 1 + + +while read device; do + blueutil --connect $device & +done < ${SLEEP_SCRIPTS_DIR}/PairedDevices.txt + # Uncomment to debug # echo "[$(date)] :attempting to enable bluetooth" >> ~/bluetooth.log diff --git a/setup.sh b/setup.sh index 81560ad..7e9a24d 100644 --- a/setup.sh +++ b/setup.sh @@ -94,6 +94,9 @@ echo "***********************" echo "Preparing sleep scripts" echo "***********************" +blueutil --paired | tr -d ',' | awk 'NR>0 { print $2 }' > PairedDevices.txt + + # Determine and escape absolute paths of sleepwatcher and Blueutil SLEEPWATCHER_PATH=$(which sleepwatcher | sed 's_/_\\/_g') BLUEUTIL_PATH=$(which blueutil | sed 's_/_\\/_g') @@ -104,6 +107,8 @@ sed "s/blueutil/${BLUEUTIL_PATH}/" ./disable_bluetooth.sh > \ ${SLEEP_SCRIPTS_DIR}/disable_bluetooth.sh || exit 1; sed "s/blueutil/${BLUEUTIL_PATH}/" ./enable_bluetooth.sh > \ ${SLEEP_SCRIPTS_DIR}/enable_bluetooth.sh || exit 1; +sed "s/blueutil/${BLUEUTIL_PATH}/" ./PairedDevices.txt > \ + ${SLEEP_SCRIPTS_DIR}/PairedDevices.txt|| exit 1; chmod +x ${SLEEP_SCRIPTS_DIR}/* || exit 1; echo "** sleep scripts copied to ${SLEEP_SCRIPTS_DIR}" From d22581521907250ad24965714c974857eb7ff7fb Mon Sep 17 00:00:00 2001 From: Amartya Nambiar Date: Mon, 21 Nov 2022 20:07:56 +0530 Subject: [PATCH 4/4] added necessary comments --- PairedDevices.txt | 2 -- disable_bluetooth.sh | 2 -- enable_bluetooth.sh | 3 +-- setup.sh | 3 ++- 4 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 PairedDevices.txt diff --git a/PairedDevices.txt b/PairedDevices.txt deleted file mode 100644 index 16c3430..0000000 --- a/PairedDevices.txt +++ /dev/null @@ -1,2 +0,0 @@ -74-45-ce-bc-1f-26 -db-a0-7d-17-8e-8e diff --git a/disable_bluetooth.sh b/disable_bluetooth.sh index 18f5508..6860f32 100644 --- a/disable_bluetooth.sh +++ b/disable_bluetooth.sh @@ -1,7 +1,5 @@ #!/bin/bash -# blueutil --disconnect db-a0-7d-17-8e-8e --wait-disconnect db-a0-7d-17-8e-8e -# blueutil --disconnect 74-45-ce-bc-1f-26 --wait-disconnect 74-45-ce-bc-1f-26 blueutil --power 0 # Uncomment to debug diff --git a/enable_bluetooth.sh b/enable_bluetooth.sh index d08a55a..d3aef41 100644 --- a/enable_bluetooth.sh +++ b/enable_bluetooth.sh @@ -3,8 +3,7 @@ SLEEP_SCRIPTS_DIR=~/.sleepscripts blueutil --power 1 - - +# Go through PairedDevices.txt and connect while read device; do blueutil --connect $device & done < ${SLEEP_SCRIPTS_DIR}/PairedDevices.txt diff --git a/setup.sh b/setup.sh index 7e9a24d..113f7e4 100644 --- a/setup.sh +++ b/setup.sh @@ -94,6 +94,7 @@ echo "***********************" echo "Preparing sleep scripts" echo "***********************" +# Create PairedDevices.txt file in KBOS directory - contains the list of paired devices blueutil --paired | tr -d ',' | awk 'NR>0 { print $2 }' > PairedDevices.txt @@ -101,7 +102,7 @@ blueutil --paired | tr -d ',' | awk 'NR>0 { print $2 }' > PairedDevices.txt SLEEPWATCHER_PATH=$(which sleepwatcher | sed 's_/_\\/_g') BLUEUTIL_PATH=$(which blueutil | sed 's_/_\\/_g') -# Copy sleepscripts to user directory +# Copy sleepscripts, PairedDevices.txt to user directory mkdir -p ${SLEEP_SCRIPTS_DIR} || exit 1; sed "s/blueutil/${BLUEUTIL_PATH}/" ./disable_bluetooth.sh > \ ${SLEEP_SCRIPTS_DIR}/disable_bluetooth.sh || exit 1;