Skip to content

Commit 73ae9b0

Browse files
committed
Fix GPU installer bug
1 parent a24af0e commit 73ae9b0

File tree

1 file changed

+117
-108
lines changed

1 file changed

+117
-108
lines changed
Lines changed: 117 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/bin/bash
22
# ─────────────────────────────────────────────────────────────
3-
# TriOS GPU Driver Installer (v4.1)
3+
# TriOS GPU Driver Installer (v6 - Hybrid Smart Edition)
44
# Safely installs and maintains up-to-date GPU drivers
5+
# Supports all hybrid GPU setups (Intel+NVIDIA, AMD+NVIDIA, AMD+Intel)
56
# Designed for Debian 13 "Trixie" (Stable)
67
# Only GPU-related packages are allowed from Debian Testing
78
# ─────────────────────────────────────────────────────────────
89

910
set -e
1011

11-
echo "=== TriOS GPU Driver Installer v4.1 ==="
12+
echo "=== TriOS GPU Driver Installer v6 ==="
1213
echo
13-
echo "Safely installs optional proprietary or open-source GPU drivers."
14-
echo "Only GPU-related packages will ever be pulled from Debian Testing."
14+
echo "Supports NVIDIA, AMD, Intel, and all hybrid combinations."
15+
echo "Stable base preserved; GPU drivers sourced safely from Testing."
1516
echo
1617
read -rp "Press any key to continue, or Ctrl+C to cancel... " -n1 -s
1718
echo -e "\n"
@@ -22,75 +23,66 @@ if [ "$EUID" -ne 0 ]; then
2223
exit 1
2324
fi
2425

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

32-
# ─── Setup Core Debian Repositories ───────────────────────────
56+
# ─── Repositories ────────────────────────────────────────────
3357
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
58+
add_repo "trixie" "deb.debian.org/debian trixie" \
59+
"deb http://deb.debian.org/debian trixie main contrib non-free non-free-firmware
3660
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
61+
deb http://deb.debian.org/debian trixie-updates main contrib non-free non-free-firmware"
3962

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
63+
add_repo "backports" "trixie-backports" \
64+
"deb http://deb.debian.org/debian trixie-backports main contrib non-free non-free-firmware"
4665

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-fasttrack trixie-backports-staging main contrib non-free non-free-firmware
53-
EOF
54-
fi
66+
add_repo "fasttrack" "fasttrack.debian.net" \
67+
"deb http://fasttrack.debian.net/debian-fasttrack trixie-fasttrack main contrib non-free non-free-firmware
68+
deb http://fasttrack.debian.net/debian trixie-backports-staging main contrib non-free non-free-firmware"
5569

56-
# ─── Add Debian Testing (for GPU drivers only) ────────────────
57-
if ! grep -Rq "deb.debian.org/debian 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
70+
add_repo "testing" "deb.debian.org/debian testing" \
71+
"deb http://deb.debian.org/debian testing main contrib non-free non-free-firmware"
6272

63-
# ─── Strict APT Pinning ──────────────────────────────────────
73+
# ─── Strict APT Pinning ──────────────────────────────────────
6474
cat >/etc/apt/preferences.d/gpu-drivers.pref <<'EOF'
65-
# ────────────────────────────────────────────────
66-
# APT Pinning Rules for TriOS GPU Driver Installer
67-
# ────────────────────────────────────────────────
68-
6975
# Default: Debian Stable (Trixie)
7076
Package: *
7177
Pin: release a=trixie
7278
Pin-Priority: 990
7379
74-
# Debian Backports (used when explicitly targeted)
75-
Package: *
76-
Pin: release a=trixie-backports
77-
Pin-Priority: 800
78-
79-
# Debian FastTrack (preferred for NVIDIA)
80-
Package: *
81-
Pin: release a=trixie-fasttrack
82-
Pin-Priority: 850
83-
84-
Package: *
85-
Pin: release a=trixie-backports-staging
86-
Pin-Priority: 825
87-
88-
# Debian Testing: Disabled by default
80+
# Testing disabled by default
8981
Package: *
9082
Pin: release a=testing
9183
Pin-Priority: 100
9284
93-
# GPU-related packages explicitly allowed from Testing
85+
# GPU packages allowed from Testing
9486
Package: nvidia-driver nvidia-settings nvidia-kernel-dkms libnvidia-gl* \
9587
libnvidia-egl* libnvidia-compute* libnvidia-encode* libnvidia-decode* \
9688
mesa* libgl1-mesa* libegl* libgbm* vulkan* firmware-amd* firmware-linux* \
@@ -100,81 +92,98 @@ Pin: release a=testing
10092
Pin-Priority: 900
10193
EOF
10294

103-
echo "[*] Repository setup complete. Updating package lists..."
104-
apt-get update
105-
106-
# ─── Optional Mesa Git (Experimental AMD/Intel) ───────────────
107-
read -rp "Enable experimental Mesa Git repository for AMD/Intel? [y/N]: " _mesa_git
108-
if [[ "$_mesa_git" =~ ^[Yy]$ ]]; then
109-
echo "[*] Adding Mesa Git repository..."
110-
cat >/etc/apt/sources.list.d/mesa-git.list <<'EOF'
111-
deb http://download.opensuse.org/repositories/home:/nicoo:/mesa:/debian/Debian_Trixie/ ./
112-
EOF
95+
# ─── Optional Mesa Git Repo ──────────────────────────────────
96+
if prompt_yn "Enable experimental Mesa Git repository for AMD/Intel?"; then
97+
add_repo "mesa-git" "home:/nicoo:/mesa" \
98+
"deb http://download.opensuse.org/repositories/home:/nicoo:/mesa:/debian/Debian_Trixie/ ./"
11399
curl -fsSL https://download.opensuse.org/repositories/home:/nicoo:/mesa:/debian/Debian_Trixie/Release.key \
114100
| gpg --dearmor -o /etc/apt/trusted.gpg.d/mesa-git.gpg
115-
apt-get update
116101
fi
117102

118-
# ─── Detect GPU ───────────────────────────────────────────────
119-
apt-get install -y --no-install-recommends pciutils curl lsb-release nvidia-detect >/dev/null 2>&1 || true
120-
GPU_INFO=$(lspci | grep -Ei 'vga|3d|display')
103+
# ─── Update Once ─────────────────────────────────────────────
104+
if [ "$_needs_update" = true ]; then
105+
echo "[*] Updating package lists..."
106+
apt-get update -y
107+
fi
108+
109+
# ─── Base Utilities ──────────────────────────────────────────
110+
install_pkg pciutils
111+
install_pkg curl
112+
install_pkg lsb-release
113+
install_pkg nvidia-detect
114+
115+
# ─── GPU Detection ───────────────────────────────────────────
116+
GPU_INFO=$(lspci | awk '/VGA|3D|Display/ {print tolower($0)}')
117+
HAS_NVIDIA=false
118+
HAS_AMD=false
119+
HAS_INTEL=false
120+
121121
echo "Detected GPU(s):"
122122
echo "$GPU_INFO"
123123
echo
124124

125-
# ─── Upgrade-Only Mode ────────────────────────────────────────
126-
if [ "$1" == "--upgrade-drivers" ]; then
127-
echo "[*] Upgrading GPU driver packages (Testing/FastTrack/Backports)..."
128-
apt-get install -y -t trixie-fasttrack -t trixie-backports -t testing \
129-
nvidia-driver nvidia-settings nvidia-kernel-dkms libnvidia-gl* \
130-
mesa-vulkan-drivers mesa-opencl-icd vulkan-tools \
131-
firmware-linux-nonfree firmware-amd-graphics intel-media-va-driver-non-free
132-
echo "[✓] GPU drivers updated successfully."
133-
exit 0
134-
fi
125+
grep -q nvidia <<< "$GPU_INFO" && HAS_NVIDIA=true
126+
grep -q amd <<< "$GPU_INFO" && HAS_AMD=true
127+
grep -q intel <<< "$GPU_INFO" && HAS_INTEL=true
128+
129+
# ─── Install Functions ───────────────────────────────────────
130+
install_nvidia() {
131+
echo "[*] Installing NVIDIA drivers..."
132+
local _driver
133+
_driver=$(nvidia-detect | awk '/recommended/ {print $3}' | head -n1)
134+
_driver=${_driver:-nvidia-driver}
135135

136-
# ─── Install Drivers ──────────────────────────────────────────
137-
_apt_targets=("trixie-fasttrack" "trixie-backports" "testing" "trixie")
138-
139-
# NVIDIA
140-
if echo "$GPU_INFO" | grep -qi nvidia; then
141-
echo "[*] NVIDIA GPU detected."
142-
RECOMMENDED=$(nvidia-detect 2>/dev/null | awk '/recommended/ {print $3}' | head -n1)
143-
_driver=${RECOMMENDED:-nvidia-driver}
144-
145-
for _target in "${_apt_targets[@]}"; do
146-
if grep -Rq "$_target" /etc/apt/sources.list*; then
147-
echo "[*] Attempting NVIDIA install from $_target..."
148-
if apt-get install -y -t "$_target" "$_driver" nvidia-settings nvidia-prime; then
149-
break
150-
fi
136+
for _target in fasttrack trixie-backports testing; do
137+
if apt-get install -y -t "$_target" "$_driver" nvidia-settings nvidia-prime; then
138+
break
151139
fi
152140
done
153141

154-
echo "[*] Installing 32-bit NVIDIA libraries for gaming..."
155142
apt-get install -y libnvidia-gl:i386 libnvidia-egl-gbm1:i386 || true
156-
fi
143+
}
157144

158-
# AMD
159-
if echo "$GPU_INFO" | grep -qi amd; then
160-
echo "[*] AMD GPU detected."
145+
install_amd() {
146+
echo "[*] Installing AMD drivers..."
161147
apt-get install -y -t testing mesa-vulkan-drivers mesa-opencl-icd clinfo \
162148
vulkan-validationlayers mesa-vulkan-drivers:i386 mesa-opencl-icd:i386 \
163149
firmware-amd-graphics
164-
fi
150+
}
165151

166-
# Intel
167-
if echo "$GPU_INFO" | grep -qi intel; then
168-
echo "[*] Intel GPU detected."
152+
install_intel() {
153+
echo "[*] Installing Intel drivers..."
169154
apt-get install -y -t testing xserver-xorg-video-intel \
170155
intel-media-va-driver-non-free intel-gpu-tools \
171156
mesa-vulkan-drivers mesa-vulkan-drivers:i386
172-
fi
173-
174-
# Hybrid GPU
175-
if echo "$GPU_INFO" | grep -qi nvidia && echo "$GPU_INFO" | grep -Eqi 'amd|intel'; then
176-
echo "[*] Hybrid GPU setup detected (NVIDIA + Intel/AMD)."
177-
apt-get install -y nvidia-prime bbswitch-dkms
157+
}
158+
159+
configure_hybrid() {
160+
echo "[*] Configuring hybrid GPU environment..."
161+
162+
# Always install hybrid control tools
163+
apt-get install -y nvidia-prime switcheroo-control bbswitch-dkms
164+
165+
# Detect combo type
166+
if $HAS_NVIDIA && $HAS_INTEL; then
167+
echo "[*] Detected NVIDIA + Intel hybrid (Optimus)"
168+
echo "[i] You can switch using: sudo prime-select nvidia|intel"
169+
elif $HAS_NVIDIA && $HAS_AMD; then
170+
echo "[*] Detected NVIDIA + AMD hybrid"
171+
echo "[i] Use environment variable DRI_PRIME=1 for AMD rendering."
172+
elif $HAS_AMD && $HAS_INTEL; then
173+
echo "[*] Detected AMD + Intel hybrid"
174+
echo "[i] Use DRI_PRIME=1 or vendor-specific profiles for render offloading."
175+
fi
176+
}
177+
178+
# ─── Install in Safe Order ───────────────────────────────────
179+
# Mesa first, proprietary last
180+
if $HAS_INTEL; then install_intel; fi
181+
if $HAS_AMD; then install_amd; fi
182+
if $HAS_NVIDIA; then install_nvidia; fi
183+
184+
# ─── Hybrid Handling ─────────────────────────────────────────
185+
if ($HAS_NVIDIA && $HAS_INTEL) || ($HAS_NVIDIA && $HAS_AMD) || ($HAS_AMD && $HAS_INTEL); then
186+
configure_hybrid
178187
fi
179188

180189
# ─── Cleanup ─────────────────────────────────────────────────
@@ -183,5 +192,5 @@ apt-get clean
183192

184193
echo
185194
echo "=== GPU Driver Installation Complete ==="
186-
echo "Stable base system preserved — only GPU drivers updated from Testing."
187-
echo "Reboot to apply changes."
195+
echo "Stable base preserved — hybrid setups configured automatically."
196+
echo "Reboot to apply changes."

0 commit comments

Comments
 (0)