Simplify logic into functions

This commit is contained in:
RisingPrism 2020-10-03 21:05:49 -04:00
parent 52e504ea7c
commit cbb980bd75

View File

@ -7,33 +7,36 @@ medium_delay=5
short_delay=1 short_delay=1
echo "Beginning of startup!" echo "Beginning of startup!"
function stop_display_manager_if_running {
if systemctl is-active --quiet $1 ; then
echo $1 >> /tmp/vfio-store-display-manager
systemctl stop $1
fi
while systemctl is-active --quiet $1 ; do
sleep "${short_delay}"
done
}
function unload_module_if_loaded {
if lsmod | grep $1 &> /dev/null ; then
modprobe -r $1
echo $1 >> /tmp/vfio-loaded-gpu-modules
fi
while lsmod | grep $1 &> /dev/null ; do
sleep 1
done
}
# Stop currently running display manager # Stop currently running display manager
if test -e "/tmp/vfio-store-display-manager" ; then if test -e "/tmp/vfio-store-display-manager" ; then
rm -f /tmp/vfio-store-display-manager rm -f /tmp/vfio-store-display-manager
fi fi
if systemctl is-active --quiet sddm.service ; then stop_display_manager_if_running sddm.service
echo sddm.service >> /tmp/vfio-store-display-manager stop_display_manager_if_running gdm.service
systemctl stop sddm.service stop_display_manager_if_running lightdm.service
fi stop_display_manager_if_running lxdm.service
while systemctl is-active --quiet sddm.service ; do stop_display_manager_if_running xdm.service
sleep "${short_delay}"
done
if systemctl is-active --quiet gdm.service ; then
echo gdm.service >> /tmp/vfio-store-display-manager
systemctl stop gdm.service
fi
if systemctl is-active --quiet lightdm.service ; then
echo lightdm.service >> /tmp/vfio-store-display-manager
systemctl stop lightdm.service
fi
if systemctl is-active --quiet lxdm.service ; then
echo lxdm.service >> /tmp/vfio-store-display-manager
systemctl stop lxdm.service
fi
if systemctl is-active --quiet xdm.service ; then
echo xdm.service >> /tmp/vfio-store-display-manager
systemctl stop xdm.service
fi
# Unbind VTconsoles if currently bound # Unbind VTconsoles if currently bound
if test -e "/sys/class/vtconsole/vtcon0/bind" ; then if test -e "/sys/class/vtconsole/vtcon0/bind" ; then
@ -46,44 +49,24 @@ if test -e "/sys/class/vtconsole/vtcon1/bind" ; then
fi fi
#Unbind EFI-Framebuffer if currently bound #Unbind EFI-Framebuffer if currently bound
if test -e "/sys/bus/platform/drivers/efi-framebuffer/unbind" ; then # if test -e "/sys/bus/platform/drivers/efi-framebuffer/unbind" ; then
echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind # echo efi-framebuffer.0 > /sys/bus/platform/drivers/efi-framebuffer/unbind
sleep "${medium_delay}" # sleep "${medium_delay}"
else # else
echo "Could not find framebuffer to unload!" # echo "Could not find framebuffer to unload!"
fi # fi
# Unload loaded GPU drivers # Unload loaded GPU drivers
if test -e "/tmp/vfio-loaded-gpu-modules" ; then if test -e "/tmp/vfio-loaded-gpu-modules" ; then
rm -f /tmp/vfio-loaded-gpu-modules rm -f /tmp/vfio-loaded-gpu-modules
fi fi
if lsmod | grep amdgpu &> /dev/null ; then
modprobe -r amdgpu unload_module_if_loaded amdgpu
echo amdgpu >> /tmp/vfio-loaded-gpu-modules unload_module_if_loaded nvidia_drm
fi unload_module_if_loaded nvidia_modeset
while lsmod | grep amdgpu &> /dev/null ; do unload_module_if_loaded nvidia_uvm
sleep 1 unload_module_if_loaded nvidia
done unload_module_if_loaded ipmi_devintf
if lsmod | grep nvidia_drm &> /dev/null ; then
modprobe -r nvidia_drm
echo nvidia_drm >> /tmp/vfio-loaded-gpu-modules
fi
if lsmod | grep nvidia_modeset &> /dev/null ; then
modprobe -r nvidia_modeset
echo nvidia_modeset >> /tmp/vfio-loaded-gpu-modules
fi
if lsmod | grep nvidia_uvm &> /dev/null ; then
modprobe -r nvidia_uvm
echo nvidia_uvm >> /tmp/vfio-loaded-gpu-modules
fi
if lsmod | grep nvidia &> /dev/null ; then
modprobe -r nvidia
echo nvidia >> /tmp/vfio-loaded-gpu-modules
fi
if lsmod | grep ipmi_devintf &> /dev/null ; then
modprobe -r ipmi_devintf
echo ipmi_devintf >> /tmp/vfio-loaded-gpu-modules
fi
# Unbind the GPU from display driver # Unbind the GPU from display driver