diff --git a/bin/oref0-bluetoothup.sh b/bin/oref0-bluetoothup.sh index 2a3a98c57..0ebede225 100755 --- a/bin/oref0-bluetoothup.sh +++ b/bin/oref0-bluetoothup.sh @@ -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 @@ -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