From b423ccfc0be202b7e6e7192a8b8744c9331ec7fb Mon Sep 17 00:00:00 2001 From: stornic56 <71296607+stornic56@users.noreply.github.com> Date: Thu, 30 Jul 2026 20:33:21 -0500 Subject: [PATCH] audio stack & GPU driver unification - Unified PipeWire installation into a single checklist option ("PipeWire Audio Stack"). Removed confusing dual options (Standard/Backports) to streamline Debian 13 workflows. Added Bluetooth Hi-Res codec support (LDAC, aptX, AAC) with automatic detection of `libfdk-aac` variants across all Debian versions. - Refactored `_install_nvidia_standard()` in `modules/gpu/nvidia.sh` to respect the `NVIDIA_DRIVER_MODE` signal from the dispatcher, eliminating external dependency on `nvidia-detect`. Added logic to select between Open Kernel Modules (Turing/Ada/Ampere) and Classic DKMS (Maxwell/Pascal/Volta). Enhanced confirmation dialogs to display both driver and kernel module versions. - Updated `_install_mesa_32bit()` in `modules/gaming/_helpers.sh` with the same version resolution and upgrade logic as Audio, ensuring consistent UX for Backports selection on Debian 13. - Expanded `NVIDIA_FAMILY_MAP` in `modules/gpu/_helpers.sh` to include missing silicon prefixes (Hopper, Blackwell variants) while maintaining "legacy" abstraction for driver policy separation. --- modules/extras/audio/audio.sh | 178 ++++++++++++++++++---------------- modules/gaming/_helpers.sh | 44 ++++++++- modules/gpu.sh | 54 +++++++---- modules/gpu/_helpers.sh | 148 ++++++++-------------------- modules/gpu/nvidia.sh | 93 ++++++++---------- 5 files changed, 256 insertions(+), 261 deletions(-) diff --git a/modules/extras/audio/audio.sh b/modules/extras/audio/audio.sh index df18e6e..fd6a410 100644 --- a/modules/extras/audio/audio.sh +++ b/modules/extras/audio/audio.sh @@ -7,17 +7,12 @@ _cat_audio() { local -a items=() - local pw_state; pw_state=$(_state "pipewire") - items+=( - "pipewire-standard" "PipeWire Audio Stack (Recommended)" "$pw_state" - ) + local pw_label="PipeWire Audio Stack (Bluetooth Hi-Res)" - if [ "$DEBIAN_VERSION" = "13" ]; then - local bpo_state; bpo_state=$(_state "pipewire") - items+=( - "pipewire-backports" "PipeWire from Backports (v1.4.9)" "off" - ) - fi + local pw_state; pw_state=$(_state "pipewire-audio") + items+=( + "pipewire-audio" "$pw_label" "$pw_state" + ) local alsa_state; alsa_state=$(_state "alsa-utils") items+=( @@ -48,27 +43,9 @@ _cat_audio() { local cleaned; cleaned=$(echo "$choices" | tr -d '"') - local do_pipewire_standard=false - local do_pipewire_backports=false - for pkg in $cleaned; do case $pkg in - pipewire-standard) do_pipewire_standard=true ;; - pipewire-backports) do_pipewire_backports=true ;; - esac - done - - for pkg in $cleaned; do - case $pkg in - pipewire-standard) - if $do_pipewire_backports; then - continue - fi - _install_pipewire_standard - ;; - pipewire-backports) - _install_pipewire_backports - ;; + pipewire-audio) _install_pipewire_standard ;; alsa-utils) if ! is_installed "alsa-utils"; then _run_install "alsa-utils alsa-ucm-conf" @@ -100,70 +77,109 @@ _cat_audio() { esac done - if $do_pipewire_standard || $do_pipewire_backports; then - if [ "$DEBIAN_VERSION" != "11" ]; then - echo "Restarting PipeWire services..." - systemctl --user restart wireplumber pipewire pipewire-pulse 2>/dev/null || true - echo -e "${GREEN}PipeWire services restarted.${NC}" - fi - fi - echo -e "${GREEN}Audio & Sound setup complete.${NC}" } _install_pipewire_standard() { + local bt_pkgs="libldacbt-abr2 libldacbt-enc2 libopenaptx0 libspa-0.2-bluetooth" + if apt-cache show libfdk-aac2t64 &>/dev/null; then + bt_pkgs+=" libfdk-aac2t64" + elif apt-cache show libfdk-aac2 &>/dev/null; then + bt_pkgs+=" libfdk-aac2" + fi + + # ── Resolve versions (needed for both installed and not-installed branches) ── + local stable_ver="" + stable_ver=$(apt-cache policy pipewire-audio 2>/dev/null | awk 'NR==3 {print $2; exit}') || true + local bpo_ver="" + if [ "$DEBIAN_VERSION" = "13" ] && [ "$(is_backports_enabled)" = "true" ]; then + bpo_ver=$(apt-cache madison pipewire-audio 2>/dev/null | \ + grep "${DEBIAN_CODENAME}-backports" | awk '{print $3}' | head -1) || true + fi + + local pkg_check="pipewire-audio" + [ "$DEBIAN_VERSION" = "11" ] && pkg_check="pipewire" + + # ── Already installed branch ── + if is_installed "$pkg_check"; then + if [ -n "$bpo_ver" ]; then + local current_ver + current_ver=$(dpkg -l "$pkg_check" 2>/dev/null | awk '/^ii/{print $3}') || true + if _confirm "PipeWire" \ + "PipeWire ${current_ver:+v${current_ver} }already installed.\n\nUpgrade to backports version v${bpo_ver}?"; then + echo "Upgrading PipeWire Audio Stack..." + echo "-> Target version: v${bpo_ver} (from ${DEBIAN_CODENAME}-backports)" + echo "-> Including Bluetooth Hi-Res codecs (LDAC, aptX, AAC)" + _run_cmd "PipeWire" \ + "sudo apt install -y --reinstall -t ${DEBIAN_CODENAME}-backports pipewire-audio $bt_pkgs" \ + "Upgrading PipeWire from backports..." + if [ "$DEBIAN_VERSION" != "11" ]; then + echo "Restarting PipeWire services..." + systemctl --user restart wireplumber pipewire pipewire-pulse 2>/dev/null || true + echo -e "${GREEN}PipeWire services restarted.${NC}" + fi + return + fi + fi + echo "$pkg_check already installed." + return + fi + + # ── Confirm dialog ── + local apt_target="" pw_ver="" pw_src="" + if [ -n "$bpo_ver" ]; then + local msg="Backports repository is enabled.\n\n" + msg+="Available versions:\n" + msg+=" - Stable: v${stable_ver:-unknown}\n" + msg+=" - Backports: v${bpo_ver}\n\n" + msg+="Install from Backports (Recommended for newer hardware)\nor from Stable (more conservative)?" + if _confirm_custom "PipeWire Install" "$msg" "Backports" "Stable" 14 70; then + apt_target="-t ${DEBIAN_CODENAME}-backports" + pw_ver="$bpo_ver" + pw_src="from ${DEBIAN_CODENAME}-backports" + else + pw_ver="$stable_ver" + fi + else + local msg="PipeWire Audio Stack (v${stable_ver:-unknown})\n" + msg+="will be installed along with Bluetooth Hi-Res\n" + msg+="codecs (LDAC, aptX, AAC).\n\n" + msg+="Continue with installation?" + if ! _confirm "PipeWire Install" "$msg" 12 65; then + echo "PipeWire installation cancelled." + return + fi + pw_ver="$stable_ver" + fi + + echo "Installing PipeWire Audio Stack..." + echo "-> Detected version: ${pw_ver:-unknown} ${pw_src:+($pw_src)}" + echo "-> Including Bluetooth Hi-Res codecs (LDAC, aptX, AAC)" + case "$DEBIAN_VERSION" in 11) - if ! is_installed "pipewire"; then - _run_cmd "PipeWire" \ - "sudo apt install -y pipewire libspa-0.2-bluetooth pipewire-alsa libspa-0.2-jack" \ - "Installing PipeWire (Bullseye basic mode)..." - echo -e "${GREEN}PipeWire installed (Bullseye basic mode).${NC}" - else - echo "PipeWire already installed." - fi + _run_cmd "PipeWire" \ + "sudo apt install -y pipewire libspa-0.2-bluetooth pipewire-alsa libspa-0.2-jack $bt_pkgs" \ + "Installing PipeWire (Bullseye basic mode)..." + echo -e "${GREEN}PipeWire installed (Bullseye basic mode).${NC}" ;; 12) - if ! is_installed "pipewire-audio"; then - _run_cmd "PipeWire" \ - "sudo apt install -y pipewire-audio" \ - "Installing pipewire-audio meta-package (Bookworm)..." - echo -e "${GREEN}PipeWire audio stack installed.${NC}" - else - echo "pipewire-audio already installed." - fi + _run_cmd "PipeWire" \ + "sudo apt install -y pipewire-audio $bt_pkgs" \ + "Installing pipewire-audio meta-package (Bookworm)..." + echo -e "${GREEN}PipeWire audio stack installed.${NC}" ;; 13) - if ! is_installed "pipewire-audio"; then - _run_cmd "PipeWire" \ - "sudo apt install -y pipewire-audio" \ - "Installing pipewire-audio meta-package (Trixie)..." - echo -e "${GREEN}PipeWire audio stack installed.${NC}" - else - echo "pipewire-audio already installed." - fi + _run_cmd "PipeWire" \ + "sudo apt install -y $apt_target pipewire-audio $bt_pkgs" \ + "Installing pipewire-audio meta-package (Trixie)..." + echo -e "${GREEN}PipeWire audio stack installed.${NC}" ;; esac -} -_install_pipewire_backports() { - if [ "$DEBIAN_VERSION" != "13" ]; then - echo -e "${YELLOW}Backports install is only available on Debian 13 (Trixie). Skipping.${NC}" - return - fi - - if ! is_backports_enabled; then - _msg "Backports Required" \ - "Trixie-backports is not enabled.\n\nEnable it first via:\n Main Menu → 3 → Configure Repositories" 12 65 - echo -e "${YELLOW}Skipping PipeWire from backports.${NC}" - return - fi - - if ! is_installed "pipewire-audio"; then - _run_cmd "PipeWire Backports" \ - "sudo apt install -y -t ${DEBIAN_CODENAME}-backports pipewire-audio" \ - "Installing PipeWire from trixie-backports (v1.4.9)..." - else - echo "pipewire-audio already installed." + if [ "$DEBIAN_VERSION" != "11" ]; then + echo "Restarting PipeWire services..." + systemctl --user restart wireplumber pipewire pipewire-pulse 2>/dev/null || true + echo -e "${GREEN}PipeWire services restarted.${NC}" fi } diff --git a/modules/gaming/_helpers.sh b/modules/gaming/_helpers.sh index 1b75185..0c3b3f9 100644 --- a/modules/gaming/_helpers.sh +++ b/modules/gaming/_helpers.sh @@ -29,10 +29,50 @@ _install_mesa_32bit() { return fi - local apt_target="" + # ── Resolve versions for display ── + local rep_pkg="${base_pkgs[0]}" + local stable_ver="" + stable_ver=$(apt-cache policy "$rep_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') || true + local bpo_ver="" if [ "$DEBIAN_VERSION" = "13" ] && [ "$(is_backports_enabled)" = "true" ]; then - apt_target="-t ${DEBIAN_CODENAME}-backports" + bpo_ver=$(apt-cache madison "$rep_pkg" 2>/dev/null | \ + grep "${DEBIAN_CODENAME}-backports" | awk '{print $3}' | head -1) || true fi + + local check_pkg="libgl1-mesa-dri:i386" + + # ── Already installed branch ── + if is_installed "$check_pkg"; then + if [ -n "$bpo_ver" ]; then + local current_ver + current_ver=$(dpkg -l "$check_pkg" 2>/dev/null | awk '/^ii/{print $3}') || true + if _confirm "Mesa 32-bit" \ + "Mesa 32-bit libraries ${current_ver:+v${current_ver} }already installed.\n\nReinstall from backports v${bpo_ver}?"; then + echo "Reinstalling Mesa 32-bit from backports..." + _run_cmd "Mesa 32-bit" \ + "sudo apt install -y --reinstall -t ${DEBIAN_CODENAME}-backports ${install_list[*]}" \ + "Reinstalling Mesa 32-bit from backports..." + echo -e "${GREEN}Mesa 32-bit libraries reinstalled.${NC}" + return + fi + fi + echo "Mesa 32-bit libraries already installed." + return + fi + + # ── Not installed branch ── + local apt_target="" + if [ -n "$bpo_ver" ]; then + local msg="Backports repository is enabled.\n\n" + msg+="Available versions for Mesa 32-bit:\n" + msg+=" - Stable: v${stable_ver:-unknown}\n" + msg+=" - Backports: v${bpo_ver}\n\n" + msg+="Install from Backports or Stable?" + if _confirm_custom "Mesa 32-bit" "$msg" "Backports" "Stable" 14 70; then + apt_target="-t ${DEBIAN_CODENAME}-backports" + fi + fi + _run_cmd "Mesa 32-bit" "sudo apt install -y $apt_target ${install_list[*]}" \ "Installing Mesa drivers (${#install_list[@]} packages)..." echo -e "${GREEN}Mesa 32-bit libraries installed.${NC}" diff --git a/modules/gpu.sh b/modules/gpu.sh index cc576f9..7569d20 100644 --- a/modules/gpu.sh +++ b/modules/gpu.sh @@ -197,31 +197,47 @@ _install_nvidia_stack() { fi elif [ "$DEBIAN_VERSION" = "13" ]; then - if [ "$(is_nvidia_blackwell)" = "true" ]; then - _install_nvidia_cuda_repo - elif [ "$(is_nvidia_kepler)" = "true" ] || [ "$(is_nvidia_fermi)" = "true" ]; then - _msg "NVIDIA — Trixie" \ - "Kepler and Fermi GPUs are not supported\nin Debian 13 (Trixie).\n\nThe nvidia-legacy drivers are not available\nin this version of Debian.\n\nNo NVIDIA driver will be installed." - NVIDIA_DRIVER_MODE="" - elif [ "$(is_backports_kernel)" = "true" ]; then - if [ "$(is_nvidia_maxwell)" = "true" ] || [ "$(is_nvidia_pascal)" = "true" ]; then - local gpu_gen="Maxwell" - [ "$(is_nvidia_pascal)" = "true" ] && gpu_gen="Pascal" - _msg "NVIDIA — Trixie + Backports" \ - "INCOMPATIBILITY DETECTED: Your NVIDIA ${gpu_gen} GPU\n\ + local nv_arch + nv_arch=$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID") + case "$nv_arch" in + legacy) + _msg "NVIDIA — Trixie" \ + "Kepler and Fermi GPUs are not supported\nin Debian 13 (Trixie).\n\nThe nvidia-legacy drivers are not available\nin this version of Debian.\n\nNo NVIDIA driver will be installed." + NVIDIA_DRIVER_MODE="" + ;; + blackwell) + _install_nvidia_cuda_repo + ;; + maxwell|pascal|volta) + if [ "$(is_backports_kernel)" = "true" ]; then + local gpu_gen="Maxwell" + [ "$nv_arch" = "pascal" ] && gpu_gen="Pascal" + [ "$nv_arch" = "volta" ] && gpu_gen="Volta" + _msg "NVIDIA — Trixie + Backports" \ + "INCOMPATIBILITY DETECTED: Your NVIDIA ${gpu_gen} GPU\n\ is NOT supported by the modern v590 driver.\n\n\ To run NVIDIA safely on Debian 13 (Trixie), you MUST use\n\ the official Debian v550 driver, which requires the\n\ standard STABLE Kernel.\n\n\ Forcing the stable driver path." 14 70 + _install_nvidia_standard + NVIDIA_DRIVER_MODE="stable" + else + _install_nvidia_standard + fi + ;; + turing|ampere|ada) + NVIDIA_DRIVER_MODE="open" _install_nvidia_standard - NVIDIA_DRIVER_MODE="stable" - else - _install_nvidia_cuda_repo - fi - else - _install_nvidia_standard - fi + ;; + *) + if [ "$(is_backports_kernel)" = "true" ]; then + _install_nvidia_cuda_repo + else + _install_nvidia_standard + fi + ;; + esac else _install_nvidia_standard diff --git a/modules/gpu/_helpers.sh b/modules/gpu/_helpers.sh index 743ac2a..9104dd7 100644 --- a/modules/gpu/_helpers.sh +++ b/modules/gpu/_helpers.sh @@ -1,116 +1,54 @@ #!/usr/bin/env bash # Shared helpers for GPU submodules -is_nvidia_kepler() { - local dev_id - dev_id=$(timeout 2 lspci -nn | grep -iE "VGA|3D" | grep -i nvidia | grep -oP '10de:\K[0-9a-fA-F]+' | head -n1) - [ -z "$dev_id" ] && { echo false; return; } +declare -A NVIDIA_FAMILY_MAP=( + # Fermi / Kepler (Legacy: el shim se encarga de separarlos) + ["06"]="legacy" ["0D"]="legacy" ["0E"]="legacy" + ["0F"]="legacy" ["10"]="legacy" ["11"]="legacy" ["12"]="legacy" + # Maxwell + ["13"]="maxwell" ["14"]="maxwell" ["16"]="maxwell" ["17"]="maxwell" + # Pascal + Volta (Misma política de driver clásico) + ["15"]="pascal" ["1B"]="pascal" ["1C"]="pascal" ["1D"]="pascal" + # Turing + ["1E"]="turing" ["1F"]="turing" ["21"]="turing" + # Ampere + ["20"]="ampere" ["22"]="ampere" ["24"]="ampere" ["25"]="ampere" + # Hopper + ["23"]="hopper" + # Ada Lovelace + ["26"]="ada" ["27"]="ada" ["28"]="ada" + # Blackwell + ["29"]="blackwell" ["2B"]="blackwell" ["2C"]="blackwell" + ["2D"]="blackwell" ["2E"]="blackwell" ["31"]="blackwell" +) - local dev_int - dev_int=$((16#${dev_id,,})) - - # Bloque 1: GK107 (escritorio + móvil) — 0x0FC0..0x0FFF - if [ "$dev_int" -ge $((16#0FC0)) ] && [ "$dev_int" -le $((16#0FFF)) ]; then echo true; return; fi - # Bloque 2: GK110/GK110B/GK210 acotado puro — 0x1000..0x103F - if [ "$dev_int" -ge $((16#1000)) ] && [ "$dev_int" -le $((16#103F)) ]; then echo true; return; fi - # Bloque 3: GK104/GK106 (completo) — 0x1180..0x11FF - if [ "$dev_int" -ge $((16#1180)) ] && [ "$dev_int" -le $((16#11FF)) ]; then echo true; return; fi - # Bloque 4: GK208/GK208B (completo) — 0x1280..0x12BF - if [ "$dev_int" -ge $((16#1280)) ] && [ "$dev_int" -le $((16#12BF)) ]; then echo true; return; fi - - echo false +detect_nvidia_arch() { + local pci_id="$1" + local prefix="${pci_id:0:2}" + echo "${NVIDIA_FAMILY_MAP[$prefix]:-unknown}" } -is_nvidia_fermi() { - local dev_id - dev_id=$(timeout 2 lspci -nn | grep -iE "VGA|3D" | grep -i nvidia | grep -oP '10de:\K[0-9a-fA-F]+' | head -n1) - [ -z "$dev_id" ] && { echo false; return; } - - local dev_int - dev_int=$((16#${dev_id,,})) - - # GF100 / GF110 — GTX 480, GTX 580, Quadro 6000, Tesla C2050 - if [ "$dev_int" -ge $((16#06C0)) ] && [ "$dev_int" -le $((16#06DF)) ]; then echo true; return; fi - # GF104 / GF114 — GTS 450, GTX 460M, GT 555M - if [ "$dev_int" -ge $((16#0DC0)) ] && [ "$dev_int" -le $((16#0DCF)) ]; then echo true; return; fi - # GF104 / GF108 — GT 445M, GT 435M, GT 550M - if [ "$dev_int" -ge $((16#0DD0)) ] && [ "$dev_int" -le $((16#0DDF)) ]; then echo true; return; fi - # GF108 — GT 440, GT 430, GT 520, GT 610, GT 620M, NVS 5400M - if [ "$dev_int" -ge $((16#0DE0)) ] && [ "$dev_int" -le $((16#0DEF)) ]; then echo true; return; fi - # GF108 — GT 525M, GT 540M, GT 550M, Quadro 600, Quadro 500M - if [ "$dev_int" -ge $((16#0DF0)) ] && [ "$dev_int" -le $((16#0DFF)) ]; then echo true; return; fi - # GF104 / GF114 — GTX 460, GTX 470M, GTX 485M - if [ "$dev_int" -ge $((16#0E22)) ] && [ "$dev_int" -le $((16#0E31)) ]; then echo true; return; fi - # GF119 — GT 520M, GT 610M, NVS 4200M - if [ "$dev_int" -ge $((16#1050)) ] && [ "$dev_int" -le $((16#105F)) ]; then echo true; return; fi - # GF110 — GTX 580, GTX 570, GTX 560 Ti, GTX 590 - if [ "$dev_int" -ge $((16#1080)) ] && [ "$dev_int" -le $((16#108F)) ]; then echo true; return; fi - # GF110 — Tesla M2090, Quadro 5010M, Quadro 7000 - if [ "$dev_int" -ge $((16#1090)) ] && [ "$dev_int" -le $((16#109F)) ]; then echo true; return; fi - # GF116 / GF119 — GTX 560, GTX 460 v2, GTX 555, GT 645 - if [ "$dev_int" -ge $((16#1200)) ] && [ "$dev_int" -le $((16#120F)) ]; then echo true; return; fi - # GF116 / GF108 — GTX 550 Ti, GTS 450 rev, GT 545, GT 640 (Fermi) - if [ "$dev_int" -ge $((16#1240)) ] && [ "$dev_int" -le $((16#124F)) ]; then echo true; return; fi - echo false +_is_nvidia_kepler_id() { + local dev_id="$1" + [ -z "$dev_id" ] && return 1 + local dev_int=$((16#${dev_id,,})) + [ "$dev_int" -ge $((16#0FC0)) ] && [ "$dev_int" -le $((16#0FFF)) ] && return 0 + [ "$dev_int" -ge $((16#1000)) ] && [ "$dev_int" -le $((16#103F)) ] && return 0 + [ "$dev_int" -ge $((16#1180)) ] && [ "$dev_int" -le $((16#11FF)) ] && return 0 + [ "$dev_int" -ge $((16#1280)) ] && [ "$dev_int" -le $((16#12BF)) ] && return 0 + return 1 } -is_nvidia_maxwell() { - local dev_id - dev_id=$(timeout 2 lspci -nn | grep -iE "VGA|3D" | grep -i nvidia | grep -oP '10de:\K[0-9a-fA-F]+' | head -n1) - [ -z "$dev_id" ] && { echo false; return; } - - local dev_int - dev_int=$((16#${dev_id,,})) - - # GM108/GM107/GM204 — gama media/baja + Quadros M (incluye 980M/970M) - if [ "$dev_int" -ge $((16#1340)) ] && [ "$dev_int" -le $((16#13FF)) ]; then echo true; return; fi - # GM206 — GTX 960, GTX 950, Quadro M2000 - if [ "$dev_int" -ge $((16#1400)) ] && [ "$dev_int" -le $((16#14FF)) ]; then echo true; return; fi - # GM200 — TITAN X, GTX 980 Ti - if [ "$dev_int" -ge $((16#17C0)) ] && [ "$dev_int" -le $((16#17CF)) ]; then echo true; return; fi - # GM200 profesional — Quadro M6000, Tesla M40 - if [ "$dev_int" -ge $((16#17F0)) ] && [ "$dev_int" -le $((16#17FF)) ]; then echo true; return; fi - - echo false -} - -is_nvidia_pascal() { - local dev_id - dev_id=$(timeout 2 lspci -nn | grep -iE "VGA|3D" | grep -i nvidia | grep -oP '10de:\K[0-9a-fA-F]+' | head -n1) - [ -z "$dev_id" ] && { echo false; return; } - - local dev_int - dev_int=$((16#${dev_id,,})) - - # GP100 — Tesla P100, Quadro GP100 - if [ "$dev_int" -ge $((16#15F0)) ] && [ "$dev_int" -le $((16#15FF)) ]; then echo true; return; fi - # GP102 — TITAN Xp, GTX 1080 Ti, Tesla P40, Quadro P6000 - if [ "$dev_int" -ge $((16#1B00)) ] && [ "$dev_int" -le $((16#1B3F)) ]; then echo true; return; fi - # GP104 — GTX 1080, GTX 1070, Quadro P5000/P4000/P5200/P4200 - if [ "$dev_int" -ge $((16#1B80)) ] && [ "$dev_int" -le $((16#1BBF)) ]; then echo true; return; fi - # GP106 + GP107 — GTX 1060, GTX 1050 Ti, GTX 1050, Quadro P2000/P1000/P620/P600 - if [ "$dev_int" -ge $((16#1C00)) ] && [ "$dev_int" -le $((16#1CFF)) ]; then echo true; return; fi - # GP108 — GT 1030, GT 1010, MX150/250/350/330, Quadro P520 - if [ "$dev_int" -ge $((16#1D00)) ] && [ "$dev_int" -le $((16#1D7F)) ]; then echo true; return; fi - - echo false -} - -is_nvidia_blackwell() { - local dev_id - dev_id=$(timeout 2 lspci -nn | grep -iE "VGA|3D" | grep -i nvidia | grep -oP '10de:\K[0-9a-fA-F]+' | head -n1) - [ -z "$dev_id" ] && { echo false; return; } - - local dev_int - dev_int=$((16#${dev_id,,})) - - # Blackwell (GB20x) rango bajo: 0x2900 – 0x29BF - if [ "$dev_int" -ge $((16#2900)) ] && [ "$dev_int" -le $((16#29BF)) ]; then echo true; return; fi - # Blackwell (GB20x) rango alto: 0x2B80 – 0x31DF - if [ "$dev_int" -ge $((16#2B80)) ] && [ "$dev_int" -le $((16#31DF)) ]; then echo true; return; fi - - echo false -} +is_nvidia_kepler() { [ -n "$NVIDIA_GPU_DEVICE_ID" ] && [[ "$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID")" == "legacy" ]] && _is_nvidia_kepler_id "$NVIDIA_GPU_DEVICE_ID" && echo true || echo false; } +is_nvidia_fermi() { [ -n "$NVIDIA_GPU_DEVICE_ID" ] && [[ "$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID")" == "legacy" ]] && ! _is_nvidia_kepler_id "$NVIDIA_GPU_DEVICE_ID" && echo true || echo false; } +is_nvidia_legacy() { [ -n "$NVIDIA_GPU_DEVICE_ID" ] && [[ "$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID")" == "legacy" ]] && echo true || echo false; } +is_nvidia_maxwell() { [ -n "$NVIDIA_GPU_DEVICE_ID" ] && [[ "$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID")" == "maxwell" ]] && echo true || echo false; } +is_nvidia_pascal() { [ -n "$NVIDIA_GPU_DEVICE_ID" ] && [[ "$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID")" == "pascal" ]] && echo true || echo false; } +is_nvidia_volta() { [ -n "$NVIDIA_GPU_DEVICE_ID" ] && [[ "$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID")" == "volta" ]] && echo true || echo false; } +is_nvidia_turing() { [ -n "$NVIDIA_GPU_DEVICE_ID" ] && [[ "$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID")" == "turing" ]] && echo true || echo false; } +is_nvidia_ampere() { [ -n "$NVIDIA_GPU_DEVICE_ID" ] && [[ "$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID")" == "ampere" ]] && echo true || echo false; } +is_nvidia_ada() { [ -n "$NVIDIA_GPU_DEVICE_ID" ] && [[ "$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID")" == "ada" ]] && echo true || echo false; } +is_nvidia_blackwell(){ [ -n "$NVIDIA_GPU_DEVICE_ID" ] && [[ "$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID")" == "blackwell" ]] && echo true || echo false; } is_amd_legacy_gcn() { local dev_id diff --git a/modules/gpu/nvidia.sh b/modules/gpu/nvidia.sh index 952f31c..ceb6757 100644 --- a/modules/gpu/nvidia.sh +++ b/modules/gpu/nvidia.sh @@ -11,7 +11,8 @@ install_nvidia_driver() { NVIDIA_DRIVER_MODE="" local is_bpo_kernel; is_bpo_kernel=$(is_backports_kernel) - local is_kepler; is_kepler=$(is_nvidia_kepler) + local nv_arch; nv_arch=$(detect_nvidia_arch "$NVIDIA_GPU_DEVICE_ID") + local is_kepler="false"; [[ "$nv_arch" == "legacy" ]] && _is_nvidia_kepler_id "$NVIDIA_GPU_DEVICE_ID" && is_kepler="true" local is_maxwell; is_maxwell=$(is_nvidia_maxwell) local is_pascal; is_pascal=$(is_nvidia_pascal) local is_blackwell; is_blackwell=$(is_nvidia_blackwell) @@ -264,50 +265,32 @@ _install_nvidia_bookworm_kepler() { # CASE C: Kernel stable (any distro) → Debian stable, optional backports # ------------------------------------------------------------------- _install_nvidia_standard() { - local nv_pkg="" + # --- 1. DETERMINAR PAQUETES BASADO EN LA SEÑAL --- + local nv_pkg="nvidia-driver" + local kernel_pkg="" local use_bpo=false - local is_kepler - is_kepler=$(is_nvidia_kepler) - if [ "$is_kepler" = "true" ]; then - if [ "$DEBIAN_CODENAME" = "trixie" ]; then - _msg "NVIDIA Kepler" \ - "Your GPU is NVIDIA Kepler architecture.\n\nThe nvidia-tesla-470 driver is not available\nin Debian 13 (Trixie).\n\nOptions:\n 1. Use Debian 12 (Bookworm) with nvidia-tesla-470\n 2. Use open-source Nouveau driver (limited)\n\nNo NVIDIA driver will be installed." 14 65 - return 1 - fi - nv_pkg="nvidia-tesla-470-driver" - echo -e "${YELLOW}Kepler GPU detected. Will use ${nv_pkg}.${NC}" - else - local nd_ver - nd_ver=$(apt-cache policy nvidia-detect 2>/dev/null | awk 'NR==3 {print $2; exit}') || true - if _confirm "NVIDIA Detect" "Install nvidia-detect to determine the correct driver?\n\n nvidia-detect ${nd_ver:-unknown}" 12 70; then - _run_cmd "NVIDIA" "sudo apt install -y nvidia-detect" "Installing nvidia-detect..." - else - echo "Skipping NVIDIA driver detection." - return 0 - fi - local recommended - recommended=$(nvidia-detect 2>/dev/null | grep -oP 'nvidia[\w-]+(?= package)') || true - if [ -z "$recommended" ]; then - echo -e "${RED}nvidia-detect could not determine a suitable driver.${NC}" - return 1 - fi - if [[ "$recommended" =~ legacy-390|legacy-340 ]]; then - echo -e "${RED}Your GPU requires $recommended, which is not available.${NC}" - return 1 - fi - nv_pkg="$recommended" - fi + case "${NVIDIA_DRIVER_MODE:-auto}" in + open) + kernel_pkg="nvidia-open-kernel-dkms" + ;; + classic|stable|backports) + kernel_pkg="nvidia-kernel-dkms" + ;; + auto) + kernel_pkg="$(nvidia-detect 2>/dev/null | grep -oP 'nvidia-kernel-dkms' || echo "")" + [ -z "$kernel_pkg" ] && kernel_pkg="nvidia-kernel-dkms" + ;; + esac + + # --- 2. DIÁLOGO DE BACKPORTS --- + if [ "$(is_backports_enabled)" == "true" ] && [ "${NVIDIA_DRIVER_MODE:-auto}" != "stable" ]; then + local stable_nv_ver bpo_nv_ver msg + stable_nv_ver=$(apt-cache policy "$nv_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') || true + bpo_nv_ver=$(apt-cache madison "$nv_pkg" 2>/dev/null | grep "${DEBIAN_CODENAME}-backports" | awk '{print $3}' | head -1) || true - # Check for backports (optional, if repo enabled) - local stable_nv_ver - stable_nv_ver=$(apt-cache policy "$nv_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') || true - if [ "$(is_backports_enabled)" == "true" ]; then - local bpo_nv_ver - bpo_nv_ver=$(apt-cache madison "$nv_pkg" 2>/dev/null | \ - grep "${DEBIAN_CODENAME}-backports" | awk '{print $3}' | head -1) || true if [ -n "$bpo_nv_ver" ]; then - local msg="Source: Debian ${DEBIAN_CODENAME^} (Backports available)\n" + msg="Source: Debian ${DEBIAN_CODENAME^} (Backports available)\n" msg+="NVIDIA Driver: ${nv_pkg}\n\n" msg+=" Backports: ${bpo_nv_ver}\n" msg+=" Stable: ${stable_nv_ver:-unknown}\n\n" @@ -318,12 +301,18 @@ _install_nvidia_standard() { fi fi + # --- 3. MENSAJE DE CONFIRMACIÓN --- local src_label="Debian ${DEBIAN_CODENAME^} Stable" $use_bpo && src_label="Debian ${DEBIAN_CODENAME^}-Backports" - local msg="Source: ${src_label}\n" + local stable_nv_ver kernel_ver msg + stable_nv_ver=$(apt-cache policy "$nv_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') || true + kernel_ver=$(apt-cache policy "$kernel_pkg" 2>/dev/null | awk 'NR==3 {print $2; exit}') || true + + msg="Source: ${src_label}\n" msg+="NVIDIA Driver: ${nv_pkg} ${stable_nv_ver:-unknown}\n" - msg+="[+] firmware-misc-nonfree\n" + msg+="Kernel Module: ${kernel_pkg} ${kernel_ver:-unknown}\n" + msg+="[+] firmware-misc-nonfree (o firmware-nvidia-gsp en Trixie)\n" msg+="[+] nvidia-vaapi-driver\n" msg+="[+] mesa-vdpau-drivers" @@ -332,29 +321,25 @@ _install_nvidia_standard() { return 0 fi + # --- 4. EJECUCIÓN --- local extra_pkgs="firmware-misc-nonfree nvidia-vaapi-driver mesa-vdpau-drivers" + local install_pkgs="$kernel_pkg $nv_pkg $extra_pkgs" + if $use_bpo; then - _run_cmd "NVIDIA" "sudo apt install -y -t ${DEBIAN_CODENAME}-backports $nv_pkg $extra_pkgs" \ + _run_cmd "NVIDIA" "sudo apt install -y -t ${DEBIAN_CODENAME}-backports $install_pkgs" \ "Installing NVIDIA driver from backports..." NVIDIA_DRIVER_MODE="backports" else - _run_cmd "NVIDIA" "sudo apt install -y $nv_pkg $extra_pkgs" \ + _run_cmd "NVIDIA" "sudo apt install -y $install_pkgs" \ "Installing NVIDIA driver from stable..." NVIDIA_DRIVER_MODE="stable" fi + # --- 5. VERIFICACIÓN DKMS --- echo -e "${GREEN}NVIDIA driver installed. Reboot required.${NC}" - - echo "" echo "──────────────────────────────────────────────" echo "Verifying DKMS module compilation:" - if command -v dkms &>/dev/null; then - dkms status 2>/dev/null | grep nvidia || echo "(no nvidia DKMS module found)" - else - echo "(dkms not installed)" - fi - echo "" + command -v dkms &>/dev/null && dkms status 2>/dev/null | grep nvidia || echo "(no nvidia DKMS module found)" echo "If the line ends with 'installed' → module is OK." - echo "Otherwise check: dmesg | grep nvidia" echo "──────────────────────────────────────────────" }