Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions bin/oref0-bluetoothup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ adapter=$(get_pref_string .bt_hci 2>/dev/null) || adapter=0

DAEMON_PATHS=(/usr/local/bin/bluetoothd /usr/libexec/bluetooth/bluetoothd /usr/sbin/bluetoothd)

# wait up to 3 seconds for hci name to be set
function wait_for_hci_name {
max_wait_seconds=3
elapsed_seconds=0
while (( elapsed_seconds < max_wait_seconds )) && ! ( hciconfig -a hci${adapter} | grep -q "$HOSTNAME" )
do
sleep 1
elapsed_seconds=$((elapsed_seconds + 1))
done
echo "$(date) Waited $elapsed_seconds second(s) for hci name to be set"
}

function stop_bluetooth {
echo "$(date) Stopping bluetoothd..."
if is_debian_jessie ; then
Expand Down Expand Up @@ -63,12 +75,13 @@ if ( hciconfig -a hci${adapter} | grep -q "DOWN" ) ; then
fi

if !( hciconfig -a hci${adapter} | grep -q $HOSTNAME ) ; then
# Not sure that this is needed on Stretch, add an is_debian_jessie check here if something different required.
echo Bluetooth hci name does not match hostname: $HOSTNAME. Setting bluetooth hci name.
sudo hciconfig hci${adapter} name $HOSTNAME
if !( hciconfig -a hci${adapter} | grep -q $HOSTNAME ) ; then
hciconfig -a hci${adapter}
echo "$(date) Failed to set bluetooth hci name. Stop bluetoothd and allow next cycle to handle restart."
stop_bluetooth
fi
# Not sure that this is needed on Stretch, add an is_debian_jessie check here if something different required.
echo Bluetooth hci name does not match hostname: $HOSTNAME. Setting bluetooth hci name.
sudo hciconfig hci${adapter} name $HOSTNAME
wait_for_hci_name
if ! ( hciconfig -a hci${adapter} | grep -q "$HOSTNAME" ) ; then
hciconfig -a hci${adapter}
echo "$(date) Failed to set bluetooth hci name. Stop bluetoothd and allow next cycle to handle restart."
stop_bluetooth
fi
fi