From f0be860f986b765ff4153507272967f4bbfc0b23 Mon Sep 17 00:00:00 2001 From: stornic56 <71296607+stornic56@users.noreply.github.com> Date: Fri, 7 Aug 2026 23:43:29 -0500 Subject: [PATCH] nvidia menu & management updates - Refined `_show_nvidia_version_menu` in `modules/gpu/nvidia.sh` for Debian 12/13 with precise labels ("Newest Stable", "Kepler Support") and explicit official repo recommendations. - Introduced new standalone module `modules/gpu/nvidia_manage.sh` integrated into the dispatcher to handle driver lifecycle management (Install/Change vs Remove) before version selection. - Implemented safe removal logic (`_nvidia_remove`) with explicit package purging, explicitly excluding `firmware-misc-nonfree`, and cleaning specific configs/repos without wildcards. - Ensured idempotency across all steps using `|| true` and preserved user CUDA toolkits while restoring Nouveau via initramfs regeneration. --- modules/gpu.sh | 5 ++++ modules/gpu/nvidia.sh | 14 ++++----- modules/gpu/nvidia_manage.sh | 56 ++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 modules/gpu/nvidia_manage.sh diff --git a/modules/gpu.sh b/modules/gpu.sh index db029e0..e0add2f 100644 --- a/modules/gpu.sh +++ b/modules/gpu.sh @@ -5,6 +5,7 @@ _GPU_DIR="${MODULES_DIR}/gpu" source "${_GPU_DIR}/_helpers.sh" source "${_GPU_DIR}/amd_intel.sh" source "${_GPU_DIR}/nvidia.sh" +source "${_GPU_DIR}/nvidia_manage.sh" # Consumed by gaming.sh to know which NVIDIA driver path was taken NVIDIA_DRIVER_MODE="" @@ -193,6 +194,10 @@ _install_nvidia_stack() { NVIDIA_DRIVER_MODE="" + if ! _nvidia_manage_menu; then + return + fi + if [ "$DEBIAN_VERSION" = "11" ]; then install_nvidia_bullseye diff --git a/modules/gpu/nvidia.sh b/modules/gpu/nvidia.sh index b951ebd..efcc18b 100644 --- a/modules/gpu/nvidia.sh +++ b/modules/gpu/nvidia.sh @@ -195,14 +195,14 @@ _is_cuda_repo_ready() { _show_nvidia_version_menu() { local choice if [ "$DEBIAN_VERSION" = "12" ]; then - choice=$(_menu "NVIDIA Driver Version" "Select the NVIDIA driver version for Debian 12 (Bookworm):" 12 70 3 \ - "535" "Official NVIDIA driver (Recommended)" \ - "470" "Legacy 470 (Kepler/Tesla GPUs)") + choice=$(_menu "Select NVIDIA Driver for Debian 12 (Bookworm):" "Choose the NVIDIA driver version:" 12 70 3 \ + "535" "v535 — Debian Official (Recommended)" \ + "470" "v470 — Debian Legacy (Kepler Support)") elif [ "$DEBIAN_VERSION" = "13" ]; then - choice=$(_menu "NVIDIA Driver Version" "Select the NVIDIA driver version for Debian 13 (Trixie):" 14 70 5 \ - "550" "Official Debian driver (Recommended)" \ - "590" "NVIDIA Repo v590 (Turing/Ampere/Ada/Blackwell)" \ - "595" "NVIDIA Repo v595 (Latest)") + choice=$(_menu "Select NVIDIA Driver for Debian 13 (Trixie):" "Choose the NVIDIA driver version:" 14 70 5 \ + "550" "v550 — Debian Official (Recommended)" \ + "590" "v590 — NVIDIA CUDA Repo (Production Branch)" \ + "595" "v595 — NVIDIA CUDA Repo (Newest Stable)") else NVIDIA_SELECTED_VERSION="auto" return 0 diff --git a/modules/gpu/nvidia_manage.sh b/modules/gpu/nvidia_manage.sh new file mode 100644 index 0000000..76c2fc5 --- /dev/null +++ b/modules/gpu/nvidia_manage.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# nvidia_manage.sh — NVIDIA management menu: install/change or remove + +_nvidia_manage_menu() { + local choice + choice=$(_menu "NVIDIA Driver" "Manage NVIDIA Driver" 12 70 4 \ + "1" "Install / Change NVIDIA Driver Version" \ + "2" "Remove NVIDIA Driver and Restore Nouveau") + + [ -z "$choice" ] && { + echo "Skipping NVIDIA installation." + return 1 + } + + case "$choice" in + 2) + _nvidia_remove + return 1 + ;; + *) return 0 ;; + esac +} + +_nvidia_remove() { + if ! dpkg -l 2>/dev/null | grep -qE "^ii (nvidia-driver|nvidia-tesla-470-driver|nvidia-open-kernel-dkms|nvidia-kernel-dkms)"; then + echo -e "${YELLOW}NVIDIA driver is not installed on this system.${NC}" + return 0 + fi + + if ! _confirm "Remove NVIDIA" "This will:\n - Purge the NVIDIA driver packages\n - Remove script-generated configs\n - Remove the CUDA repo sources\n - Regenerate initramfs\n\nProceed?"; then + echo "NVIDIA removal cancelled." + return 0 + fi + + echo "Removing NVIDIA driver packages..." + sudo apt purge -y nvidia-driver nvidia-kernel-dkms nvidia-open-kernel-dkms nvidia-tesla-470-driver nvidia-settings nvidia-vaapi-driver firmware-nvidia-gsp mesa-vdpau-drivers || true + + echo "Cleaning up dependencies..." + sudo apt autoremove --purge -y || true + + echo "Removing script-generated configuration..." + sudo rm -f /etc/modprobe.d/nvidia-wayland.conf || true + sudo rm -f /etc/modprobe.d/nvidia-open.conf || true + sudo rm -f /etc/apt/preferences.d/block-nvidia || true + sudo rm -f /etc/X11/xorg.conf.d/20-nvidia.conf || true + + echo "Removing NVIDIA repository sources..." + sudo rm -f /etc/apt/sources.list.d/cuda-*.list || true + sudo rm -f /etc/apt/sources.list.d/extrepo_nvidia-cuda.sources || true + + echo "Regenerating initramfs..." + sudo update-initramfs -u || true + + echo -e "${GREEN}NVIDIA driver removed. Please reboot your system.${NC}" + return 0 +}