Created
October 23, 2023 09:56
-
-
Save hrko/800a60d9c73da168796c36733d624067 to your computer and use it in GitHub Desktop.
This script installs and updates the Flatpak GL runtime for NVIDIA on Ubuntu.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
# This script installs and updates the Flatpak GL runtime for NVIDIA on Ubuntu. | |
# It automatically detects the version of the NVIDIA driver and installs the corresponding Flatpak GL runtime. | |
print_section() { | |
local title | |
title=$1 | |
echo | |
echo "==> ${title}" | |
} | |
# Check if the script is being run with root privileges | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root." | |
exit 1 | |
fi | |
# Get the version of the NVIDIA driver. | |
print_section "Get the version of the NVIDIA driver installed using apt." | |
nvidia_driver_version=$(dpkg-query -l | grep nvidia-driver | awk '{print $3}' | cut -d '-' -f 1 | tr '.' '-') | |
echo "NVIDIA driver version: $nvidia_driver_version." | |
# Remove old versions of the Flatpak GL runtime for NVIDIA. | |
print_section "Remove old versions of the Flatpak GL runtime for NVIDIA." | |
old_runtimes=() | |
mapfile -t old_runtimes < <(flatpak list | grep -E 'org.freedesktop.Platform.GL(32)?.nvidia-' | grep -v "$nvidia_driver_version" | awk '{print $2}') | |
if ((${#old_runtimes[@]} > 0)); then | |
echo "Removing the following runtimes: ${old_runtimes[*]}." | |
flatpak uninstall --noninteractive --assumeyes "${old_runtimes[@]}" | |
else | |
echo "No old versions of the Flatpak GL runtime for NVIDIA found." | |
fi | |
# Check if the proper Flatpak GL runtime for NVIDIA is already installed and exit if so. | |
print_section "Check if the proper Flatpak GL runtime for NVIDIA is already installed." | |
flatpak_nvidia_gl="org.freedesktop.Platform.GL.nvidia-$nvidia_driver_version" | |
flatpak_nvidia_gl32="org.freedesktop.Platform.GL32.nvidia-$nvidia_driver_version" | |
if flatpak list | grep -q "$flatpak_nvidia_gl" && flatpak list | grep -q "$flatpak_nvidia_gl32"; then | |
echo "The Flatpak GL runtime for NVIDIA is already installed." | |
exit 0 | |
fi | |
# Install the Flatpak GL runtime for NVIDIA. | |
print_section "Install the Flatpak GL runtime for NVIDIA." | |
echo "Installing the following runtimes: $flatpak_nvidia_gl $flatpak_nvidia_gl32." | |
flatpak install --noninteractive --assumeyes flathub "$flatpak_nvidia_gl" "$flatpak_nvidia_gl32" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
License: MIT