set -x

# This service appears to have issues when system sleeps - stop service
systemctl -M 'cspark@' --user stop mpd-discord-rpc.service

# Stop desktop environment and display manager
pkill kwin_wayland
systemctl --user -M cspark stop plasma*
systemctl stop display-manager
pkill sddm
pkill sddm-helper

# Log out of session
session=`loginctl session-status | awk 'NR==1{print $1}'`
loginctl terminate-session $session

# My audio interface has issues after coming out from a suspended type state, this will reset it to fix it when necessary.
# Unbind audio interface
echo `grep 0a73 /sys/bus/usb/devices/*/idVendor | cut -d '/' -f 6` > /sys/bus/usb/drivers/usb/unbind
# Remove snd_usb_audio once no longer in use
while ! modprobe -r snd_usb_audio; do
	sleep 1
done

# Remove amdgpu once no longer in use
while ! modprobe -r amdgpu; do
	sleep 1
done
