#! /bin/bash

#! /bin/bash

echo "stopping GUI..."
sudo systemctl stop gdm
sudo systemctl stop user@103992.service

echo "waiting for DRM nodes to be released"
retries=0
while sudo lsof -w | grep /dev/dri > /dev/null ; do
    echo "attempt $retries...."
    sleep 0.5
    retries=$((retries + 1))
    [[ $retries -gt 5 ]] && exit 1
done

echo "unloading AMDGPU..."
for vtcon in /sys/class/vtconsole/*; do 
    echo 0 | sudo tee ${vtcon}/bind > /dev/null
done
sudo modprobe -r amdgpu
