#!/bin/sh
# /usr/lib/systemd/system-sleep/bluetooth-sleep.sh
# systemd restart of Bluetooth on wake after sleep
# made empirically - no idea why this config works better
# than the other combinations didn't.

case "$1" in
  pre)
    # Tried disabling on sleep here but it didn't help
    # but keep the "pre" case if something occurs to me.
    ;;
  post)
    # Stop the Bluetooth device on wake.
    /usr/sbin/rfkill block bluetooth
    sleep 2
    # Start the Bluetooth device after a little while.
    /usr/sbin/rfkill unblock bluetooth
    sleep 2
    # Wait a bit and then restart the Bluetooth service.
    /usr/bin/systemctl restart bluetooth
    sleep 2
    # Wait a bit and then restart the Bluetooth service again - the first restart
    # doesn't always do the trick.
    /usr/bin/systemctl restart bluetooth
    ;;
esac
exit 0

