Skip to content

Instantly share code, notes, and snippets.

@derenv
Last active May 17, 2024 08:39
Show Gist options
  • Save derenv/9b7de12b7e6680be6bab616516783b1c to your computer and use it in GitHub Desktop.
Save derenv/9b7de12b7e6680be6bab616516783b1c to your computer and use it in GitHub Desktop.
Installs nvidia drivers and any development dependencies, then compiles the extension - designed for Ubuntu, tested on 23.10
#!/usr/bin/env bash
##
# Title: update_gne_vm.sh
# Author: Deren Vural
# Created: 13/03/2024
##
# Notes:
# - Installs nvidia drivers
# - Installs dependencies
# - Compiles and installs the extension
# - Once complete, user must reboot the system and enroll the MOK key
# - Explicitly runs some commands as root but not the rest - otherwise extension would be installed to root user
##
# Check that not running as root, otherwise extension doesn't install properly
if [[ "$EUID" -eq 0 ]]; then
printf "Please run as user, not root!\n"; exit 2
fi
# Variables
DRIVER_VERSION="550"
DRIVER_PACKAGES=("nvidia-driver-${DRIVER_VERSION:?}" "nvidia-utils-${DRIVER_VERSION:?}")
DEPENDENCY_PACKAGES=("ssh" "git" "make" "gnome-shell-extensions")
REPO_ADDR="https://github.com/ethanwharris/gnome-nvidia-extension.git"
printf "Starting installation..\n"
# Move to home to run install
cd "${HOME:?}" || { printf "Failed to move to \'%\' with exit code \'%s\'..\n" "${HOME:?}" "$?"; exit 1; }
# Update apt packages
sudo apt-get update -y || { printf "Failed to update packages with exit code \'%s\'..\n" "$?"; exit 1; }
# Upgrade installed packages
sudo apt-get upgrade -y || { printf "Failed to upgrade packages with exit code \'%s\'..\n" "$?"; exit 1; }
# Install nvidia driver packages
for NPACKAGE in "${DRIVER_PACKAGES[@]:?}"; do
sudo apt-get install -y "${NPACKAGE:?}" || { printf "Failed to install nvidia package: \'%s\' with exit code \'%s\'..\n" "${NPACKAGE:?}" "$?"; exit 1; }
done
# Install required packages
for DPACKAGE in "${DEPENDENCY_PACKAGES[@]:?}"; do
sudo apt-get install -y "${DPACKAGE:?}" || { printf "Failed to install required dependency: \'%s\' with exit code \'%s\'..\n" "${DPACKAGE:?}" "$?"; exit 1; }
done
# Clone remote repository
git clone "${REPO_ADDR:?}" || { printf "Failed to clone git repository with exit code \'%s\'..\n" "$?"; exit 1; }
# Move to local repository directory
cd gnome-nvidia-extension || { printf "Failed to enter local repository directory with exit code \'%s\'..\n" "$?"; exit 1; }
# Compile
make || { printf "\'make\' command failed with exit code \'%s\'..\n" "$?"; exit 1; }
make install || { printf "\'make install\' command failed with exit code \'%s\'..\n" "$?"; exit 1; }
printf "Installation complete..\n\nPlease reboot system and enroll MOK keys to enact changes!\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment