Skip to content

Commit 50d3431

Browse files
Update GPU installer yet again
1 parent 4669cce commit 50d3431

File tree

1 file changed

+82
-72
lines changed

1 file changed

+82
-72
lines changed

Trixie/config/includes.chroot/etc/trios/Install-GPU-Drivers.sh

Lines changed: 82 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/bin/bash
22
# ─────────────────────────────────────────────────────────────
3-
# TriOS GPU Driver Installer (v4)
3+
# TriOS GPU Driver Installer (v5)
44
# Safely installs and maintains up-to-date GPU drivers
55
# Designed for Debian 13 "Trixie" (Stable)
66
# Only GPU-related packages are allowed from Debian Testing
77
# ─────────────────────────────────────────────────────────────
88

99
set -e
1010

11-
echo "=== TriOS GPU Driver Installer v4 ==="
11+
echo "=== TriOS GPU Driver Installer v5 ==="
1212
echo
1313
echo "Safely installs optional proprietary or open-source GPU drivers."
1414
echo "Only GPU-related packages will ever be pulled from Debian Testing."
@@ -22,57 +22,66 @@ if [ "$EUID" -ne 0 ]; then
2222
exit 1
2323
fi
2424

25-
# ─── Enable 32-bit Multiarch for Gaming ──────────────────────
25+
# ─── Helper Functions ────────────────────────────────────────
26+
add_repo() {
27+
local _file="$1"
28+
local _marker="$2"
29+
local _content="$3"
30+
if ! grep -Rq "$_marker" /etc/apt/sources.list*; then
31+
echo "[*] Adding repository: $_marker"
32+
echo "$_content" > "/etc/apt/sources.list.d/${_file}.list"
33+
_needs_update=true
34+
fi
35+
}
36+
37+
prompt_yn() {
38+
local _prompt="$1"
39+
read -rp "$_prompt [y/N]: " _ans
40+
[[ "$_ans" =~ ^[Yy]$ ]]
41+
}
42+
43+
install_pkg() {
44+
local _pkg="$1"
45+
dpkg -s "$_pkg" &>/dev/null || apt-get install -y "$_pkg"
46+
}
47+
48+
# ─── Enable 32-bit Multiarch ─────────────────────────────────
2649
if ! dpkg --print-foreign-architectures | grep -q i386; then
2750
echo "[*] Enabling 32-bit multiarch support..."
2851
dpkg --add-architecture i386
29-
apt-get update -y
52+
_needs_update=true
3053
fi
3154

32-
# ─── Setup Core Debian Repositories ───────────────────────────
55+
# ─── Repositories ────────────────────────────────────────────
3356
echo "[*] Ensuring Debian repositories are configured..."
34-
cat >/etc/apt/sources.list.d/trixie.list <<'EOF'
35-
deb http://deb.debian.org/debian trixie main contrib non-free non-free-firmware
57+
add_repo "trixie" "deb.debian.org/debian trixie" \
58+
"deb http://deb.debian.org/debian trixie main contrib non-free non-free-firmware
3659
deb http://security.debian.org/debian-security trixie-security main contrib non-free non-free-firmware
37-
deb http://deb.debian.org/debian trixie-updates main contrib non-free non-free-firmware
38-
EOF
60+
deb http://deb.debian.org/debian trixie-updates main contrib non-free non-free-firmware"
3961

40-
# ─── Add Backports ────────────────────────────────────────────
41-
if ! grep -Rq "trixie-backports" /etc/apt/sources.list*; then
42-
echo "[*] Adding Debian Trixie Backports..."
43-
echo "deb http://deb.debian.org/debian trixie-backports main contrib non-free non-free-firmware" \
44-
> /etc/apt/sources.list.d/backports.list
45-
fi
62+
add_repo "backports" "trixie-backports" \
63+
"deb http://deb.debian.org/debian trixie-backports main contrib non-free non-free-firmware"
4664

47-
# ─── Add Fast Track for NVIDIA Drivers ────────────────────────
48-
if ! grep -Rq "fasttrack.debian.net" /etc/apt/sources.list*; then
49-
echo "[*] Adding Debian Fast Track..."
50-
cat >/etc/apt/sources.list.d/fasttrack.list <<'EOF'
51-
deb http://fasttrack.debian.net/debian-fasttrack trixie-fasttrack main contrib non-free non-free-firmware
52-
deb http://fasttrack.debian.net/debian trixie-backports-staging main contrib non-free non-free-firmware
53-
EOF
54-
fi
65+
add_repo "fasttrack" "fasttrack.debian.net" \
66+
"deb http://fasttrack.debian.net/debian-fasttrack trixie-fasttrack main contrib non-free non-free-firmware
67+
deb http://fasttrack.debian.net/debian trixie-backports-staging main contrib non-free non-free-firmware"
5568

56-
# ─── Add Debian Testing (for GPU drivers only) ────────────────
57-
if ! grep -Rq "testing" /etc/apt/sources.list*; then
58-
echo "[*] Adding Debian Testing repository (restricted pinning)..."
59-
echo "deb http://deb.debian.org/debian testing main contrib non-free non-free-firmware" \
60-
> /etc/apt/sources.list.d/testing.list
61-
fi
69+
add_repo "testing" "deb.debian.org/debian testing" \
70+
"deb http://deb.debian.org/debian testing main contrib non-free non-free-firmware"
6271

63-
# ─── Strict APT Pinning ──────────────────────────────────────
72+
# ─── Strict APT Pinning ──────────────────────────────────────
6473
cat >/etc/apt/preferences.d/gpu-drivers.pref <<'EOF'
65-
# Default: Debian Stable (Trixie) takes precedence
74+
# Default: Debian Stable (Trixie)
6675
Package: *
6776
Pin: release a=trixie
6877
Pin-Priority: 990
6978
70-
# Debian Testing: Disabled for all but GPU-related packages
79+
# Testing disabled by default
7180
Package: *
7281
Pin: release a=testing
7382
Pin-Priority: 100
7483
75-
# GPU-related packages allowed from Testing
84+
# GPU packages allowed from Testing
7685
Package: nvidia-driver nvidia-settings nvidia-kernel-dkms libnvidia-gl* \
7786
libnvidia-egl* libnvidia-compute* libnvidia-encode* libnvidia-decode* \
7887
mesa* libgl1-mesa* libegl* libgbm* vulkan* firmware-amd* firmware-linux* \
@@ -82,31 +91,35 @@ Pin: release a=testing
8291
Pin-Priority: 900
8392
EOF
8493

85-
echo "[*] Repository setup complete. Updating package lists..."
86-
apt-get update -y
87-
88-
# ─── Optional Mesa Git (Experimental AMD/Intel) ───────────────
89-
read -rp "Enable experimental Mesa Git repository for AMD/Intel? [y/N]: " _mesa_git
90-
if [[ "$_mesa_git" =~ ^[Yy]$ ]]; then
91-
echo "[*] Adding Mesa Git repository..."
92-
cat >/etc/apt/sources.list.d/mesa-git.list <<'EOF'
93-
deb http://download.opensuse.org/repositories/home:/nicoo:/mesa:/debian/Debian_Trixie/ ./
94-
EOF
94+
# ─── Optional Mesa Git Repo ──────────────────────────────────
95+
if prompt_yn "Enable experimental Mesa Git repository for AMD/Intel?"; then
96+
add_repo "mesa-git" "home:/nicoo:/mesa" \
97+
"deb http://download.opensuse.org/repositories/home:/nicoo:/mesa:/debian/Debian_Trixie/ ./"
9598
curl -fsSL https://download.opensuse.org/repositories/home:/nicoo:/mesa:/debian/Debian_Trixie/Release.key \
9699
| gpg --dearmor -o /etc/apt/trusted.gpg.d/mesa-git.gpg
100+
fi
101+
102+
# ─── Update Once ─────────────────────────────────────────────
103+
if [ "$_needs_update" = true ]; then
104+
echo "[*] Updating package lists..."
97105
apt-get update -y
98106
fi
99107

108+
# ─── Base Utilities ──────────────────────────────────────────
109+
install_pkg pciutils
110+
install_pkg curl
111+
install_pkg lsb-release
112+
install_pkg nvidia-detect
113+
100114
# ─── Detect GPU ───────────────────────────────────────────────
101-
apt-get install -y --no-install-recommends pciutils curl lsb-release nvidia-detect
102-
GPU_INFO=$(lspci | grep -Ei 'vga|3d|display')
115+
GPU_INFO=$(lspci | awk '/VGA|3D|Display/ {print tolower($0)}')
103116
echo "Detected GPU(s):"
104117
echo "$GPU_INFO"
105118
echo
106119

107-
# ─── Upgrade-Only Mode ────────────────────────────────────────
120+
# ─── Upgrade Mode ────────────────────────────────────────────
108121
if [ "$1" == "--upgrade-drivers" ]; then
109-
echo "[*] Upgrading GPU driver packages (Testing/FastTrack/Backports)..."
122+
echo "[*] Upgrading GPU driver packages..."
110123
apt-get install -y -t fasttrack -t trixie-backports -t testing \
111124
nvidia-driver nvidia-settings nvidia-kernel-dkms libnvidia-gl* \
112125
mesa-vulkan-drivers mesa-opencl-icd vulkan-tools \
@@ -115,46 +128,44 @@ if [ "$1" == "--upgrade-drivers" ]; then
115128
exit 0
116129
fi
117130

118-
# ─── Install Drivers ──────────────────────────────────────────
119-
_apt_targets=("fasttrack" "trixie-backports" "testing" "stable")
120-
121-
# NVIDIA
122-
if echo "$GPU_INFO" | grep -qi nvidia; then
131+
# ─── Install Functions ───────────────────────────────────────
132+
install_nvidia() {
123133
echo "[*] NVIDIA GPU detected."
124-
RECOMMENDED=$(nvidia-detect | awk '/recommended/ {print $3}' | head -n1)
125-
_driver=${RECOMMENDED:-nvidia-driver}
126-
127-
for _target in "${_apt_targets[@]}"; do
128-
if apt-cache policy | grep -q "$_target"; then
129-
echo "[*] Attempting NVIDIA install from $_target..."
130-
if apt-get install -y -t "$_target" "$_driver" nvidia-settings nvidia-prime; then
131-
break
132-
fi
134+
local _driver
135+
_driver=$(nvidia-detect | awk '/recommended/ {print $3}' | head -n1)
136+
_driver=${_driver:-nvidia-driver}
137+
138+
for _target in fasttrack trixie-backports testing; do
139+
echo "[*] Attempting NVIDIA install from $_target..."
140+
if apt-get install -y -t "$_target" "$_driver" nvidia-settings nvidia-prime; then
141+
break
133142
fi
134143
done
135144

136-
echo "[*] Installing 32-bit NVIDIA libraries for gaming..."
145+
echo "[*] Installing 32-bit NVIDIA libraries..."
137146
apt-get install -y libnvidia-gl:i386 libnvidia-egl-gbm1:i386 || true
138-
fi
147+
}
139148

140-
# AMD
141-
if echo "$GPU_INFO" | grep -qi amd; then
149+
install_amd() {
142150
echo "[*] AMD GPU detected."
143151
apt-get install -y -t testing mesa-vulkan-drivers mesa-opencl-icd clinfo \
144152
vulkan-validationlayers mesa-vulkan-drivers:i386 mesa-opencl-icd:i386 \
145153
firmware-amd-graphics
146-
fi
154+
}
147155

148-
# Intel
149-
if echo "$GPU_INFO" | grep -qi intel; then
156+
install_intel() {
150157
echo "[*] Intel GPU detected."
151158
apt-get install -y -t testing xserver-xorg-video-intel \
152159
intel-media-va-driver-non-free intel-gpu-tools \
153160
mesa-vulkan-drivers mesa-vulkan-drivers:i386
154-
fi
161+
}
155162

156-
# Hybrid GPU
157-
if echo "$GPU_INFO" | grep -qi nvidia && echo "$GPU_INFO" | grep -Eqi 'amd|intel'; then
163+
# ─── GPU Installation Logic ──────────────────────────────────
164+
[[ "$GPU_INFO" == *nvidia* ]] && install_nvidia
165+
[[ "$GPU_INFO" == *amd* ]] && install_amd
166+
[[ "$GPU_INFO" == *intel* ]] && install_intel
167+
168+
if [[ "$GPU_INFO" == *nvidia* && "$GPU_INFO" =~ amd|intel ]]; then
158169
echo "[*] Hybrid GPU setup detected (NVIDIA + Intel/AMD)."
159170
apt-get install -y nvidia-prime bbswitch-dkms
160171
fi
@@ -167,4 +178,3 @@ echo
167178
echo "=== GPU Driver Installation Complete ==="
168179
echo "Stable base system preserved — only GPU drivers updated from Testing."
169180
echo "Reboot to apply changes."
170-

0 commit comments

Comments
 (0)