mirror of
https://github.com/stornic56/debianito-post-install.git
synced 2026-10-31 21:18:08 +00:00
89233b0750
- `.github/workflows/ci.yml` added as a new workflow: job `lint-and-test` on `runs-on: ubuntu-latest` with `container: debian:trixie`, checking out via `actions/checkout@v4`, installing `bats` and `shellcheck`, running `shellcheck --severity=error debianito.sh modules/**/*.sh` (with `shopt -s globstar`) and `bats tests/`.
- `debianito.sh` CLI parser: `AUTO_YES=0`, `ALLOW_DESTRUCTIVE=0` declared after `MODULES_DIR` and before `_boot_mark`; `_usage()` prints `Usage: debianito.sh [OPTIONS]` with `--yes`, `--allow-destructive` and `--help`; the `while [ $# -gt 0 ]` / `case` loop consumes `--yes` and `--allow-destructive`, prints `Unknown option: $1 (run with --help for usage)` to stderr and `exit 2` for unknown flags, and `--help|-h` runs `_usage` then `exit 0`.
- `modules/utils.sh`: new global `_SELECTION_CONFIRMED=0` and `_confirm_install_list()` (utils.sh:756-785), which renders items capped at 15 with `... and N more`, computes `height` capped at 24, calls `_confirm "$title" "$list" "$height" 65`, arms `_SELECTION_CONFIRMED=${#items[@]}` on yes, and returns 1 for an empty list or on decline. `_install_pkg()` (utils.sh:789-804) decrements the countdown instead of prompting, and only prompts via `elif ! _confirm "Install: ${pkg}" "Install ${pkg}\nVersion: ${ver}?"; then return 0`.
- Bulk retrofit in `modules/extras/**/*.sh` (18 sites): `_confirm_install_list "Título" "${array[@]}" || return` placed right after the `whiptail` selection is parsed, the install loop left intact, and `_SELECTION_CONFIRMED=0` after the loop. Files: office/office.sh:101, system/software_centers.sh:29, system/system.sh:133, communication/communication.sh:68, design/design.sh:42, download/download.sh:48+55, terminals/terminals.sh:31, security/security.sh:30, players/players.sh:20, themes/fonts/fonts.sh:32, dev/dev.sh:44, programming/programming.sh:57, themes/desktop-themes/desktop-themes.sh:30, fetch/fetch.sh:41, themes/icons/icons.sh:47, themes/cursors/cursors.sh:28, internet/internet.sh:197, java.
- `modules/bullseye/extras.sh` (13 sites) plus `modules/bullseye/legacy.sh` (1 site, `install_gaming_bullseye`, guarded with `if [ ${#_install_pkgs[@]} -gt 0 ]` so a i386-only selection does not blank the summary) plus `modules/desktop_display.sh` (1 site, XFCE Custom — a no-loop `_run_cmd` batch with the reset immediately after it). Special cases: download.sh and bullseye/download each have two checklists merged into one combined summary; legacy.sh gaming skips the reset when the list is empty; XFCE Custom resets before `_xfce_polkit_rules` so the counter cannot leak.
- `modules/desktops/desktop_gnome.sh` (new): `gnome_menu()` runs a `_radiolist` with "1" "GNOME (Full Desktop)", "2" "GNOME Core (Minimal Install)", "3" "Back", then `_install_gnome_full()` and `_install_gnome_core()`. Each arms `_confirm_install_list "GNOME Full Desktop" gnome gdm3 || return` (core: `gnome-core gdm3`), keeps an already-configured display manager via `_existing_display_manager` by setting `target_dm="$keep_dm"`, writes the preseed `echo "${target_dm} shared/default-x-display-manager select ${target_dm}" | sudo debconf-set-selections`, installs `sudo apt install -y gnome gdm3` / `gnome-core gdm3`, enables `gdm3` only when `target_dm = "gdm3"`, resets `_SELECTION_CONFIRMED=0` and calls `_offer_pipewire_after_desktop`.
- `modules/desktops/desktop_kde.sh` (new): `kde_menu()` runs a `_radiolist` with "1" "KDE Plasma (Full Desktop)", "2" "KDE Plasma Desktop (Minimal)", "3" "Back"; `_install_kde_full()` and `_install_kde_minimal()` arm `_confirm_install_list "KDE Plasma Full" kde-standard sddm || return` (minimal: `kde-plasma-desktop sddm`), preseed `sddm shared/default-x-display-manager select sddm`, install `sudo apt install -y kde-standard sddm` / `kde-plasma-desktop sddm`, enable `sddm` only when it is the target DM, reset the counter and offer PipeWire.
- `modules/desktop_display.sh` `desktop_environment_menu()`: `env_items+=("3" "GNOME")`, `env_items+=("4" "KDE Plasma")`, `env_items+=("5" "Back")`; the case adds `3)` loading `gnome` via `_load_module gnome || continue` and calling `gnome_menu`, and `4)` loading `kde` via `_load_module kde || continue` and calling `kde_menu`; the dead TODO comment was removed.
- PipeWire retrofit in `modules/desktop_display.sh` (6 sites): `_install_lxde_full`, `_install_lxde_core`, `_install_xfce_full`, `_install_xfce_minimal`, `_install_xfce_wayland` and `_install_xfce_custom` each call `_offer_pipewire_after_desktop` after their install block.
- `_offer_pipewire_after_desktop()` and `_existing_display_manager()` added at the end of `modules/desktop_display.sh`: `_offer_pipewire_after_desktop` checks `pipewire-audio` (`pipewire` when `DEBIAN_VERSION = 11`), returns 0 via `is_installed`, otherwise `_confirm "PipeWire Audio" "No PipeWire audio server is installed.\n\nInstall the PipeWire audio stack (recommended)?"` calls `_install_pipewire_standard` and returns 0. `_existing_display_manager` reads `${DM_FILE:-/etc/X11/default-display-manager}`, reads the basename as the DM, and otherwise scans `gdm3 lightdm sddm greetd gdm` with `systemctl is-enabled`, printing nothing when none is found.
- `_ensure_apt_updated` added before the GNOME/KDE `apt install` transactions (4 sites, deduplicated per session); `gnome gdm3` and `kde-standard sddm` are installed alongside even when another display manager is kept as the default.
- Extraction to `modules/desktops/`: `desktop_lxde.sh` (38 lines) and `desktop_xfce.sh` (119 lines) created with the `lxde_menu` / `_install_lxde_full` / `_install_lxde_core` and `xfce_menu` / `_install_xfce_full` / `_install_xfce_minimal` / `_install_xfce_wayland` / `_install_xfce_custom` / `_xfce_polkit_rules` blocks moved verbatim; both carry `# License GPL v3` in their headers.
- `modules/desktop_display.sh` reduced from 542 to 394 lines (−154): lines 55-208 removed, the dispatch (desktop_display.sh:39-46) replaced with `_load_module xfce || continue` / `lxde_menu`, and the file left with `manage_desktop_display`, `desktop_environment_menu`, `display_manager_menu`, `lightdm_config_menu`, `configure_greetd`, `configure_gdm3`, `configure_sddm`, the two shared helpers.
- `modules/utils.sh` `_load_module` map: `xfce)` → `${MODULES_DIR}/desktops/desktop_xfce.sh`, `lxde)` → `${MODULES_DIR}/desktops/desktop_lxde.sh`, `gnome)` → `${MODULES_DIR}/desktops/desktop_gnome.sh`, `kde)` → `${MODULES_DIR}/desktops/desktop_kde.sh`; deps for `xfce`, `lxde`, `gnome` and `kde` are `(desktop_display audio)` and `desktop_display` is `(repos audio)`.
- `modules/desktops/desktop_xfce.sh` `_xfce_polkit_rules()` writes `/etc/polkit-1/rules.d/85-suspend.rules` and `89-backlight.rules` via `sudo tee`, adds the `backlight` group with `groupadd --system` fallback, adds the real login user from `/etc/passwd` to `backlight` and restarts `polkit.service`.
- ES→EN user-facing strings: 14 strings across 4 files — `desktop_display.sh` `lxdе_menu` ("LXDE (Full Desktop)", "LXDE Core (Minimal Install)"), `gpu/nvidia.sh` Kepler legacy-driver notice ("Kepler GPU detected (GKxxx)… Install the legacy driver for Kepler?"), `bullseye/legacy.sh` ("Install NVIDIA driver?", "Skipping NVIDIA driver.", "Installing NVIDIA driver ${gpu_gen}...") and `bullseye/extras.sh` ("firmware-linux-nonfree provides drivers for… Install?").
- ES→EN internal comments: ~35 comments across 9 files — section headers in `_install_nvidia_standard`, `gpu/_helpers.sh` (lines 5, 113), `gpu/nvidia.sh` (lines 8-12, 19-22, 68-70, 167-172, 196, 239-253, 262-263, 275, 291, 336-338, 376), `gpu.sh` (lines 15-17), `bullseye/repos.sh` (line 2), `firmware.sh` (line 235, "--- Load verification ---"), `utils.sh` (lines 129, 132, 153 — timezone Paso 1/2/4) and `utils.sh:546,548`.
- set -e abort fix: `debianito.sh:149` now reads `_system_preferences_menu || true`, consistent with the other dispatch chains (14 of the 15 chains already had the guard); a declined pre-apply summary now leaves the TUI alive instead of terminating the script.
- `docs/desktops_display.md`: 4 hunks — intro now lists GNOME/GNOME Core/KDE Plasma/KDE Plasma Desktop/XFCE/XFCE Wayland/XFCE Custom/LXDE, a new "Modular layout" paragraph describing `modules/desktops/` and lazy loading, Block 1 rewritten into four environments, five new bullets (pre-apply summary, existing-DM preservation, PipeWire offer, stale-lists guard) and a Desktop Environment Packages table.
- `docs/quickstart.md` line 284: Desktop Environment entry expanded to pick from XFCE (full / minimal / Wayland `labwc` on Trixie / custom checklist), LXDE (full / core), GNOME (full / core) or KDE Plasma (full / minimal).
- `_existing_display_manager` now takes the config path via `local dm_file="${DM_FILE:-/etc/X11/default-display-manager}"` so the offline test suite never reads the real system file.
- `tests/test_helper.bash`: added `_mock_systemctl()` for `is-enabled` (units in `MOCK_SYSTEMCTL_ENABLED` report `enabled`, everything else `disabled`), `MOCK_SYSTEMCTL_ENABLED=""`, `WHIPTAIL_CALLS`/`MOCK_WHIPTAIL_OUTPUT`/`MOCK_WHIPTAIL_RC`, `MOCK_DPKG_INSTALLED` and the `systemctl` entry in the mock list and in `mock_reset()`.
- `tests/desktops.bats` created with 16 tests: `_existing_display_manager` (file read, file-preferred over an enabled unit, enabled-unit fallback, candidate order, missing file, nothing configured), `_offer_pipewire_after_desktop` (5 tests: skip-installed, accept-installs, decline-returns-0, Bullseye package name, wrong package name on 11), `_load_module` (4 tests for xfce/lxde/gnome/kde) and an unknown-module case; 17→33 tests total.
- `.github/workflows/ci.yml` shellcheck severity raised from `--severity=error` to `--severity=warning`.
- `debianito.sh`: `RED`, `GREEN`, `YELLOW`, `CYAN` and `NC` plus `AUTO_YES`, `ALLOW_DESTRUCTIVE` and `DEBIAN_CODENAME` are now `export`ed as cross-file globals.
- `modules/utils.sh`: `HAS_NVIDIA`, `DESKTOP_ENV`, `AUDIO_SERVER`, `DEBIAN_VERSION` and the other cross-file globals are `export`ed.
- `modules/extras/system/software_centers.sh` gained a `#!/usr/bin/env bash` shebang.
- `shellcheck` triage (v0.11.0, baseline `--severity=warning` 25 findings → 0): removed two dead-code lines (`headless` in `extras/dev/dev.sh`, orphan `dev_id` in `firmware.sh`); `SC2206` in `extras/dev/essential.sh` fixed by expanding `$comp_pkgs` to `"${comp_pkgs[@]}"`; `SC2010`/`SC2046` (3 sites) replaced `ls … | grep` with `compgen -G "…"`; `SC2155` (2 sites, `gpu.sh` and `rescue.sh`) split command substitutions into separate lines; `SC2166` in `repos.sh` replaced `-o` with `{ … || … }`; `SC2221`/`SC2222` (2 sites, `sysinfo.sh` and `utils.sh`) collapsed the `wl*|wlp*|wlo*|wlan*` alternation to `wl*`; `SC1090` in `extras.sh` gained a justification comment on the disable directive.
- Final verification: `bash -n` on all 15 modified `.sh` files and `set -euo pipefail` at `debianito.sh:3` both intact; `bats tests/` reports 33 ok / 0 failed; invariants `offers 11`, `confirm_install_list 39` and `_SELECTION_CONFIRMED=0 40` hold.
387 lines
17 KiB
Bash
387 lines
17 KiB
Bash
#!/usr/bin/env bash
|
|
# NVIDIA GPU driver installation
|
|
#
|
|
# CASE A : Trixie + backports kernel → Official NVIDIA CUDA Repo (Pinned v590)
|
|
# CASE B : Kernel stable (any distro) → Debian stable
|
|
#
|
|
# Note: Debian 12 (Bookworm) backports reached EOL (2026-08-09);
|
|
# the NVIDIA flow only uses the stable repo for Debian 12.
|
|
|
|
# -------------------------------------------------------------------
|
|
# Shared helper: enable NVIDIA CUDA repo
|
|
# Debian 13 (Trixie): cuda-keyring (official method — broken extrepo)
|
|
# Debian 12 (Bookworm): extrepo nvidia-cuda (works)
|
|
# -------------------------------------------------------------------
|
|
_enable_cuda_repo() {
|
|
_is_cuda_repo_ready && return 0
|
|
|
|
if [ "$DEBIAN_VERSION" = "13" ]; then
|
|
# Official NVIDIA method: cuda-keyring (extrepo does not
|
|
# configure the repo correctly on Trixie)
|
|
if dpkg -s cuda-keyring &>/dev/null; then
|
|
return 0 # already installed → its .list already exists
|
|
fi
|
|
local tmp_deb
|
|
tmp_deb=$(mktemp "${TMPDIR:-/tmp}/cuda-keyring.XXXXXX.deb") || return 1
|
|
if ! wget -q "https://developer.download.nvidia.com/compute/cuda/repos/debian13/x86_64/cuda-keyring_1.1-1_all.deb" \
|
|
-O "$tmp_deb"; then
|
|
rm -f "$tmp_deb"
|
|
_msg "CUDA Repo — Error" "Failed to download cuda-keyring.\n\nNo NVIDIA driver was installed." 10 60
|
|
return 1
|
|
fi
|
|
if ! sudo dpkg -i "$tmp_deb"; then
|
|
rm -f "$tmp_deb"
|
|
_msg "CUDA Repo — Error" "Failed to install cuda-keyring.\n\nNo NVIDIA driver was installed." 10 60
|
|
return 1
|
|
fi
|
|
rm -f "$tmp_deb"
|
|
return 0
|
|
fi
|
|
|
|
# Debian 12 (y otros): extrepo nvidia-cuda
|
|
if ! command -v extrepo &>/dev/null; then
|
|
_run_cmd "extrepo" "sudo apt install -y extrepo" "Installing extrepo..." || return 1
|
|
fi
|
|
_run_cmd "CUDA Repo" \
|
|
"sudo extrepo enable nvidia-cuda" \
|
|
"Enabling official NVIDIA CUDA repository..." || return 1
|
|
}
|
|
|
|
# -------------------------------------------------------------------
|
|
# Shared DKMS helpers: verify the NVIDIA module compiled for the
|
|
# currently running kernel; repair via dpkg-reconfigure if not
|
|
# -------------------------------------------------------------------
|
|
# Returns: 0 if the NVIDIA DKMS module shows "installed" for $(uname -r)
|
|
_nvidia_dkms_installed() {
|
|
local kernel line
|
|
kernel=$(uname -r)
|
|
line=$(dkms status 2>/dev/null | grep "^nvidia" | grep -F "$kernel" | grep ": installed" | head -1)
|
|
[ -n "$line" ]
|
|
}
|
|
|
|
# Returns 0 if Secure Boot is active (mokutil present and enabled)
|
|
_nvidia_secure_boot_enabled() {
|
|
command -v mokutil &>/dev/null || return 1
|
|
mokutil --sb-state 2>/dev/null | grep -q "SecureBoot enabled"
|
|
}
|
|
|
|
# Non-fatal notice: the DKMS module is compiled but NOT signed.
|
|
# Advanced users can sign it with MOK; novices need to know why
|
|
# they will see a black screen after reboot. If mokutil is missing,
|
|
# nothing is shown (mokutil is not preinstalled on Debian).
|
|
_warn_secure_boot() {
|
|
if _nvidia_secure_boot_enabled; then
|
|
echo -e "${RED}WARNING: Secure Boot is enabled. The NVIDIA DKMS module is compiled but NOT signed.${NC}"
|
|
echo -e "${RED}You MUST sign the module with MOK or disable Secure Boot in BIOS before rebooting.${NC}"
|
|
echo -e "${RED}See: https://wiki.debian.org/SecureBoot#Signing_kernel_modules${NC}"
|
|
fi
|
|
}
|
|
|
|
# Verify the DKMS build for the current kernel and repair it if needed.
|
|
# $@ = candidate dkms packages to reconfigure, in priority order
|
|
# (the first installed one is used for dpkg-reconfigure).
|
|
_verify_nvidia_dkms_build() {
|
|
local kernel
|
|
kernel=$(uname -r)
|
|
|
|
echo ""
|
|
echo "──────────────────────────────────────────────"
|
|
echo "Verifying DKMS module compilation for ${kernel}:"
|
|
|
|
if ! command -v dkms &>/dev/null; then
|
|
echo -e "${RED}(dkms not installed — DKMS build cannot be verified)${NC}"
|
|
echo "──────────────────────────────────────────────"
|
|
return 1
|
|
fi
|
|
|
|
dkms status 2>/dev/null | grep "^nvidia" || echo "(no nvidia DKMS module found)"
|
|
|
|
if _nvidia_dkms_installed; then
|
|
_warn_secure_boot
|
|
echo -e "${GREEN}DKMS module compiled for ${kernel}. Reboot required.${NC}"
|
|
echo "──────────────────────────────────────────────"
|
|
return 0
|
|
fi
|
|
|
|
echo -e "${YELLOW}DKMS module NOT compiled for ${kernel}. Repairing...${NC}"
|
|
local pkg repaired=false
|
|
for pkg in "$@"; do
|
|
if dpkg -l "$pkg" 2>/dev/null | grep -q "^ii"; then
|
|
_run_cmd "NVIDIA" "sudo dpkg-reconfigure $pkg" "Reconfiguring $pkg..."
|
|
repaired=true
|
|
break
|
|
fi
|
|
done
|
|
if ! $repaired; then
|
|
echo -e "${RED}No DKMS package found to reconfigure.${NC}"
|
|
fi
|
|
|
|
if _nvidia_dkms_installed; then
|
|
_warn_secure_boot
|
|
echo -e "${GREEN}DKMS module compiled successfully for ${kernel}. Reboot required.${NC}"
|
|
echo "──────────────────────────────────────────────"
|
|
return 0
|
|
else
|
|
echo -e "${RED}DKMS module still not compiled for ${kernel}.${NC}"
|
|
echo "Check the build log manually:"
|
|
echo " /var/lib/dkms/nvidia*/.../build/make.log"
|
|
echo " dmesg | grep nvidia"
|
|
echo "──────────────────────────────────────────────"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# -------------------------------------------------------------------
|
|
# NVIDIA driver version selection (Debian 12/13)
|
|
# Sets the global NVIDIA_SELECTED_VERSION; first option is the default.
|
|
# Returns: 0 if a version was chosen, 1 if the user cancelled
|
|
# -------------------------------------------------------------------
|
|
_is_cuda_repo_ready() {
|
|
[ -f /etc/apt/sources.list.d/extrepo_nvidia-cuda.sources ] ||
|
|
grep -qr 'developer.download.nvidia.com' /etc/apt/sources.list.d/ 2>/dev/null
|
|
}
|
|
|
|
_show_nvidia_version_menu() {
|
|
local choice
|
|
if [ "$DEBIAN_VERSION" = "12" ]; then
|
|
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 "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
|
|
fi
|
|
[ -z "$choice" ] && return 1
|
|
NVIDIA_SELECTED_VERSION="$choice"
|
|
return 0
|
|
}
|
|
|
|
# -------------------------------------------------------------------
|
|
# NVIDIA Wayland/KMS base configuration (/etc/modprobe.d/nvidia-wayland.conf)
|
|
# Applies on Debian 12/13, any driver version (535/550/590/595).
|
|
# Architecture and hybrid detection are ORTHOGONAL:
|
|
# - Architecture → affects ONLY fbdev (kepler: the 470 does not
|
|
# support it) and the color/info message.
|
|
# - Hybrid vs desktop → affects NVreg (Preserve / kernel suspend
|
|
# notifier), INDEPENDENT of architecture.
|
|
# 590/595 add the kernel suspend notifier (complements, never
|
|
# replaces, NVreg_PreserveVideoMemoryAllocations).
|
|
# -------------------------------------------------------------------
|
|
_configure_nvidia_wayland() {
|
|
local ver="${1:-$NVIDIA_SELECTED_VERSION}"
|
|
local conf="/etc/modprobe.d/nvidia-wayland.conf"
|
|
local arch
|
|
local content=""
|
|
local color="${GREEN}"
|
|
local msg="Wayland config (desktop): KMS + video memory preservation enabled."
|
|
arch=$(_get_nvidia_arch_family)
|
|
|
|
# ── Architecture: fbdev only and color message ──
|
|
case "$arch" in
|
|
kepler)
|
|
color="${RED}"
|
|
msg="WARNING: Wayland not supported on Kepler. Use X11 (Xorg)."
|
|
;;
|
|
maxwell | pascal)
|
|
color="${YELLOW}"
|
|
msg="Wayland support on ${arch} is experimental. X11 recommended."
|
|
;;
|
|
esac
|
|
|
|
# ── Hybrid vs desktop: NVreg independent of architecture ──
|
|
if _is_hybrid_laptop; then
|
|
content="options nvidia-drm modeset=1"$'\n'
|
|
[ "$arch" != "kepler" ] && content+="options nvidia-drm fbdev=1"$'\n'
|
|
color="${GREEN}"
|
|
msg="Wayland config (hybrid laptop): KMS enabled — NVreg omitted."
|
|
else
|
|
content="options nvidia NVreg_PreserveVideoMemoryAllocations=1"$'\n'
|
|
case "$ver" in
|
|
590 | 595) content+="options nvidia NVreg_UseKernelSuspendNotifiers=1"$'\n' ;;
|
|
esac
|
|
content+="options nvidia-drm modeset=1"$'\n'
|
|
[ "$arch" != "kepler" ] && content+="options nvidia-drm fbdev=1"$'\n'
|
|
fi
|
|
|
|
printf "%b" "$content" | sudo tee "$conf" >/dev/null || return 1
|
|
echo -e "${color}${msg}${NC}"
|
|
}
|
|
|
|
# -------------------------------------------------------------------
|
|
# CASE A: Trixie + Backports Kernel → Official CUDA Repo (Pinned v590)
|
|
# -------------------------------------------------------------------
|
|
_install_nvidia_cuda_repo() {
|
|
local ver="${1:-590}"
|
|
local warn="WARNING: You are about to install NVIDIA v${ver} from\n"
|
|
warn+="the official NVIDIA CUDA repository.\n\n"
|
|
warn+="Source: Official NVIDIA CUDA Repo\n"
|
|
warn+="Driver: Production Branch v${ver} (unified metapackage)\n"
|
|
warn+="[+] nvidia-driver-pinning-${ver} (version lock)\n"
|
|
warn+="[+] nvidia-open (driver + open kernel modules)\n\n"
|
|
warn+="Do you want to proceed at your own risk?"
|
|
|
|
if ! _confirm_custom "NVIDIA Driver — v${ver}" "$warn" "Proceed" "Abort" 18 70; then
|
|
echo -e "${YELLOW}NVIDIA installation aborted by user.${NC}"
|
|
return 1
|
|
fi
|
|
|
|
# Step 1: Enable CUDA repo (cuda-keyring Trixie / extrepo Bookworm)
|
|
if ! _enable_cuda_repo; then
|
|
_msg "CUDA Repo — Error" "Failed to enable the official NVIDIA CUDA repository.\n\nNo NVIDIA driver was installed." 10 60
|
|
return 1
|
|
fi
|
|
|
|
# Step 2: explicit apt update — without an updated index the repo
|
|
# is invisible and apt would resolve the Debian candidate (v550)
|
|
# instead of v${ver}.
|
|
if ! _run_cmd "CUDA Repo" "sudo apt update" \
|
|
"Updating package lists after enabling CUDA repository..."; then
|
|
NVIDIA_DRIVER_MODE=""
|
|
_msg "CUDA Repo — Error" "Failed to update APT after enabling CUDA repo.\n\nNo NVIDIA driver was installed." 10 60
|
|
return 1
|
|
fi
|
|
|
|
# Step 3: Official pinning — INDEPENDENT and mandatory APT
|
|
# transaction. APT reads /etc/apt/preferences.d/ at startup, not
|
|
# during the transaction: the pinning must be installed BEFORE
|
|
# installing the driver. If the repo does not publish it, it is
|
|
# an NVIDIA repo problem: abort cleanly instead of installing a
|
|
# version the user did not choose.
|
|
if ! _run_cmd "NVIDIA Pinning" \
|
|
"sudo apt install -y nvidia-driver-pinning-${ver}" \
|
|
"Installing NVIDIA version pinning (${ver})..."; then
|
|
NVIDIA_DRIVER_MODE=""
|
|
_msg "NVIDIA — Error" "Failed to install NVIDIA driver pinning ${ver}.\n\nNo NVIDIA driver was installed." 10 60
|
|
return 1
|
|
fi
|
|
|
|
# Step 4: Install the metapackage (pinning already active). If it
|
|
# fails, the pinning remains installed (config only, not a problem).
|
|
# firmware-nvidia-gsp arrives as a mandatory transitive dependency
|
|
# (nvidia-open → nvidia-kernel-open-dkms → firmware-nvidia-gsp),
|
|
# aligned with the official docs: apt -V install nvidia-open.
|
|
if ! _run_cmd "NVIDIA CUDA" \
|
|
"sudo apt install -y nvidia-open" \
|
|
"Installing NVIDIA driver from CUDA repository..."; then
|
|
NVIDIA_DRIVER_MODE=""
|
|
_msg "NVIDIA — Error" "NVIDIA driver installation FAILED.\n\nNo NVIDIA driver was installed." 10 60
|
|
return 1
|
|
fi
|
|
|
|
# Post-install: the installed DKMS module must match the ${ver} branch
|
|
local dkms_ver
|
|
dkms_ver=$(dpkg -l nvidia-kernel-dkms nvidia-kernel-open-dkms 2>/dev/null | awk '$1=="ii" {print $3; exit}')
|
|
if [[ "$dkms_ver" == ${ver}.* ]]; then
|
|
echo -e "${GREEN}DKMS module ${dkms_ver} matches branch v${ver}.${NC}"
|
|
else
|
|
echo -e "${RED}WARNING: DKMS package (${dkms_ver:-none}) does not match v${ver}.*${NC}"
|
|
fi
|
|
|
|
NVIDIA_DRIVER_MODE="cuda-repo"
|
|
echo -e "${GREEN}NVIDIA Production Driver v${ver} installed from CUDA repo. Reboot required.${NC}"
|
|
|
|
_verify_nvidia_dkms_build nvidia-kernel-open-dkms nvidia-kernel-dkms || true
|
|
}
|
|
|
|
# -------------------------------------------------------------------
|
|
# Bookworm Kepler interception — forces nvidia-legacy-470xx-driver
|
|
# -------------------------------------------------------------------
|
|
_install_nvidia_bookworm_kepler() {
|
|
local nv_pkg="nvidia-tesla-470-driver"
|
|
local nv_ver
|
|
nv_ver=$(apt-cache policy "$nv_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') || true
|
|
|
|
echo -e "${YELLOW}Kepler GPU detected — forcing ${nv_pkg}.${NC}"
|
|
|
|
local msg="Kepler GPU detected (GKxxx).\n\n"
|
|
msg+="On Debian 12 Bookworm, Kepler requires the legacy\n"
|
|
msg+="driver instead of the modern one. Using package:\n"
|
|
msg+=" ${nv_pkg} ${nv_ver:-unknown}\n"
|
|
msg+="to avoid black-screen failures.\n\n"
|
|
msg+=" [USE] ${nv_pkg}\n"
|
|
msg+=" [+] linux-headers-amd64\n"
|
|
msg+=" [+] firmware-misc-nonfree\n"
|
|
msg+=" [+] nvidia-settings\n\n"
|
|
msg+="Install the legacy driver for Kepler?"
|
|
|
|
if ! _confirm_custom "NVIDIA Kepler — Bookworm" "$msg" "Install" "Skip" 14 70; then
|
|
echo "Skipping Kepler driver."
|
|
NVIDIA_DRIVER_MODE=""
|
|
return 0
|
|
fi
|
|
|
|
if ! _run_cmd "NVIDIA Kepler" \
|
|
"sudo apt install -y linux-headers-amd64 $nv_pkg firmware-misc-nonfree nvidia-settings" \
|
|
"Installing nvidia-legacy-470xx-driver..."; then
|
|
NVIDIA_DRIVER_MODE=""
|
|
_msg "NVIDIA Kepler — Error" "Kepler driver installation FAILED.\n\nNo NVIDIA driver was installed." 10 60
|
|
return 1
|
|
fi
|
|
|
|
NVIDIA_DRIVER_MODE="${NVIDIA_DRIVER_MODE:-stable}"
|
|
echo -e "${GREEN}Kepler driver (${nv_pkg}) installed. Reboot required.${NC}"
|
|
|
|
_verify_nvidia_dkms_build nvidia-tesla-470-kernel-dkms || true
|
|
}
|
|
|
|
# -------------------------------------------------------------------
|
|
# CASE B: Kernel stable (any distro) → Debian stable
|
|
# -------------------------------------------------------------------
|
|
_install_nvidia_standard() {
|
|
# --- 1. ARCHITECTURE → KERNEL MODULE ---
|
|
# Only Turing+ (known) uses the open module. Unknown/empty or
|
|
# old architecture (Kepler/Fermi/Maxwell/Pascal/Volta) →
|
|
# closed module as safe fallback.
|
|
local fam
|
|
fam=$(_get_nvidia_arch_family)
|
|
local kernel_pkg="nvidia-kernel-dkms"
|
|
case "$fam" in
|
|
turing | ampere | ada | blackwell) kernel_pkg="nvidia-open-kernel-dkms" ;;
|
|
esac
|
|
|
|
# --- 2. PACKAGES — a single apt install ---
|
|
local extra_pkgs="linux-headers-amd64 nvidia-driver firmware-nvidia-gsp nvidia-vaapi-driver"
|
|
[ "$DEBIAN_VERSION" = "12" ] && extra_pkgs+=" mesa-vdpau-drivers"
|
|
local install_pkgs="$kernel_pkg $extra_pkgs"
|
|
|
|
# --- 3. CONFIRMATION MESSAGE ---
|
|
local kernel_ver msg
|
|
kernel_ver=$(apt-cache policy "$kernel_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') || true
|
|
|
|
msg="Source: Debian ${DEBIAN_CODENAME^} Stable\n"
|
|
msg+="Kernel Module: ${kernel_pkg} ${kernel_ver:-unknown} (arch: ${fam:-unknown})\n"
|
|
msg+="[+] linux-headers-amd64\n"
|
|
msg+="[+] firmware-nvidia-gsp\n"
|
|
msg+="[+] nvidia-vaapi-driver"
|
|
[ "$DEBIAN_VERSION" = "12" ] && msg+="\n[+] mesa-vdpau-drivers"
|
|
|
|
if ! _confirm "NVIDIA Driver" "$msg" 14 70; then
|
|
echo "Skipping NVIDIA driver installation."
|
|
return 0
|
|
fi
|
|
|
|
# --- 4. EXECUTION ---
|
|
if ! _run_cmd "NVIDIA" "sudo apt install -y $install_pkgs" \
|
|
"Installing NVIDIA driver from stable..."; then
|
|
NVIDIA_DRIVER_MODE=""
|
|
_msg "NVIDIA — Error" "NVIDIA driver installation FAILED.\n\nNo NVIDIA driver was installed." 10 60
|
|
return 1
|
|
fi
|
|
NVIDIA_DRIVER_MODE="stable"
|
|
|
|
# Mandatory fix for Debian 12 with the open module
|
|
if [ "$DEBIAN_VERSION" = "12" ] && [[ "$kernel_pkg" == *"open"* ]]; then
|
|
echo "options nvidia NVreg_OpenRmEnableUnsupportedGpus=1" | sudo tee /etc/modprobe.d/nvidia-open.conf >/dev/null
|
|
echo "Applied required Open RM parameter for Debian 12."
|
|
fi
|
|
|
|
# --- 5. DKMS POST-INSTALL VERIFICATION ---
|
|
echo -e "${GREEN}NVIDIA driver installed. Reboot required.${NC}"
|
|
_verify_nvidia_dkms_build "$kernel_pkg" || true
|
|
}
|