Skip to content

Instantly share code, notes, and snippets.

@vaslabs
Forked from GloriousEggroll/nvidia-installer.sh
Created May 28, 2023 10:52
Show Gist options
  • Save vaslabs/8279510fae133f20f57760beaf5daa63 to your computer and use it in GitHub Desktop.
Save vaslabs/8279510fae133f20f57760beaf5daa63 to your computer and use it in GitHub Desktop.
nvidia /etc/profile.d/ script
#!/usr/bin/sh
nvgpu=$(lspci | grep -iE 'VGA|3D' | grep -i nvidia | cut -d ":" -f 3)
nvkernmod=$(lspci -k | grep -iEA3 'VGA|3D' | grep -iA3 nvidia | grep -i 'kernel driver' | grep -iE 'vfio-pci|nvidia')
if [[ ! -z $nvgpu ]]; then
if [[ -z $nvkernmod ]]; then
# Check for internet connection
wget -q --spider http://google.com
if [ $? -eq 0 ]; then
zenity --question\
--title="Nvidia GPU Hardware Detected" \
--width=600 \
--text="`printf "The following Nvidia hardware has been found on your system:\n\n\
$nvgpu\n\n\
This hardware requires 3rd party Nvidia drivers to be installed in order to function correctly.\n\n\
By pressing 'Yes', you will be prompted for your password in order to install these drivers.\n\n\
After the driver installation completes the system will be rebooted.\n\n"`"
case $? in
0)
PASSWD="$(zenity --password)\n"
(
echo "# Installing Nvidia drivers"
echo "10"; sleep 1
echo "# Installing Nvidia drivers"
echo "50"; sleep 1
echo "# Updating to latest kernel (required for Nvidia drivers)"
echo -e $PASSWD | sudo -S dnf install -y kernel kernel-headers
echo "# Purging any previous lingering nvidia drivers/packages"
sudo -S dnf remove -y akmod-nvidia xorg-x11-drv-nvidia-cuda
sudo -S dnf remove -y nvidia-settings xorg-x11-drv-nvidia* kmod-nvidia
echo "# Installing Nvidia drivers"
sudo -S dnf install -y akmod-nvidia xorg-x11-drv-nvidia-cuda
echo "75"; sleep 1
echo "# Nvidia driver installation complete! The system will now reboot."
echo "100"; sleep 1
) | zenity --title "Nvidia GPU Hardware Detected" --progress --no-cancel --width=600 --percentage=0
# reset kscsreen settings
rm -Rf /home/$USER/.local/share/kscreen
# remove any previous declined answer
rm /home/$USER/.config/nvcheck-declined
reboot
;;
*)
# User declined to install nvidia drivers
zenity --info\
--title="Nvidia GPU Hardware Detected" \
--width=600 \
--text="`printf "We will not ask you this again until your next login.\n\n"`"
echo 1 > /home/$USER/.config/nvcheck-declined
exit 0
;;
esac
else
# No internet connection found
zenity --info\
--title="No Internet connection." \
--width=600 \
--text="`printf "An internet connection is required to install Nvidia drivers. Once your system is connected to the internet, run 'nvcheck.sh' from the terminal to restart the installer.\n\n"`"
echo 1 > /home/$USER/.config/nvcheck-declined
exit 0
fi
fi
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment