Skip to content

Instantly share code, notes, and snippets.

@sirn
Created July 31, 2019 08:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirn/428637dd2528874804d2bb2eb2ae2610 to your computer and use it in GitHub Desktop.
Save sirn/428637dd2528874804d2bb2eb2ae2610 to your computer and use it in GitHub Desktop.
Stop Intel Bluetooth from being an absolute shitshow

Fix Intel Bluetooth

Intel Bluetooth sometimes seems to stuck in a weird state where it cannot response to any command (e.g. Bug #1790454). Bluetooth will simply not working when this happens, and can only be fixed by unplugging the computer from any power source (reliable) or restart until it works (may took 5-10 tries for it to work).

This script simply try to unload the driver and reload it with an option to repeatly doing so (press R) until it started working. It is written for runit, so when used elsewhere you might want to replace sv stop and sv start lines to systemctl stop bluetooth.service and systemctl start bluetooth.service respectively.

#!/bin/sh
#
# Stop Intel Bluetooth from being ab absolute shitshow
#
if [ "$(id -u)" != "0" ]; then
exec sudo sh "$0"
fi
## Utils
##
echo_err() {
msg=$*
echo >&2 "$0: $msg"
}
echo_msg() {
msg=$*
echo >&2 "$(tput -- bold)==>$(tput -- sgr0) $msg"
}
## Configurations
##
_btmod="btusb btintel btbcm bnep rfcomm bluetooth"
_btmod_r=
## Disabling
##
echo_msg "Disabling bluetoothd..."
rfkill block bluetooth
sv stop bluetoothd
echo_msg "Unloading bluetooth modules..."
for mod in $_btmod; do
_btmod_r="$mod ${_btmod_r:+ $_btmod_r}"
modprobe -vr "$mod"
done
## Reenabling
##
echo_msg "Reloading bluetooth modules..."
for mod in $_btmod_r; do
modprobe -v "$mod"
done
echo_msg "Restarting bluetoothd..."
sv start bluetoothd
rfkill unblock bluetooth
## Finalizing
##
echo_msg "Finalizing..."
while true; do
OLDIFS=$IFS
IFS=
printf >&2 "Press q to exit or r to rerun? "
read -r input
case $input in
[Qq] )
exit 0
;;
[Rr] )
IFS=$OLDIFS
exec sh "$0"
;;
esac
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment