11#! /bin/bash
2+ # ─────────────────────────────────────────────────────────────
3+ # TriOS GPU Driver Installer (v4.1)
4+ # Safely installs and maintains up-to-date GPU drivers
5+ # Designed for Debian 13 "Trixie" (Stable)
6+ # Only GPU-related packages are allowed from Debian Testing
7+ # ─────────────────────────────────────────────────────────────
28
3- # --- TriOS Updater Script ---
4- # Downloads and runs the appropriate TriOS update archive.
5- # All output is logged for safety and review.
9+ set -e
610
7- _LOGFILE=~ /trios_updater.log
8-
9- # Redirect all stdout and stderr to the log file
10- exec > >( tee -a " $_LOGFILE " ) 2>&1
11-
12- echo " ========================================"
13- echo " Welcome to the TriOS Updater"
14- echo " ========================================"
15- echo
16- echo " This tool will update your TriOS installation to the latest version."
17- echo
18- echo " It is strongly recommended that you create a system backup before proceeding."
11+ echo " === TriOS GPU Driver Installer v4.1 ==="
1912echo
20- echo " → You can easily create one using Timeshift:"
21- echo " sudo timeshift --create"
22- echo
23- echo " Creating a Timeshift snapshot lets you restore your system if something goes wrong."
24- echo
25- echo " I PROMISE you it is worth it."
13+ echo " Safely installs optional proprietary or open-source GPU drivers."
14+ echo " Only GPU-related packages will ever be pulled from Debian Testing."
2615echo
16+ read -rp " Press any key to continue, or Ctrl+C to cancel... " -n1 -s
17+ echo -e " \n"
2718
28- read -p " Have you created a Timeshift backup? (y/N): " _backup_confirm
29- _backup_confirm=${_backup_confirm,,} # to lowercase
30- if [ " $_backup_confirm " != " y" ] && [ " $_backup_confirm " != " yes" ]; then
31- echo " Please create a backup with Timeshift before continuing."
32- echo " Aborting update for safety."
19+ # ─── Root Check ──────────────────────────────────────────────
20+ if [ " $EUID " -ne 0 ]; then
21+ echo " Please run as root (or with sudo)."
3322 exit 1
3423fi
3524
36- echo
37- echo " Proceeding with TriOS update..."
38- echo " ----------------------------------------"
39-
40- # --- Root Check ---
41- if [ " $( id -u) " -ne 0 ]; then
42- echo " Error: This updater must be run as root."
43- echo " Please switch to root (e.g., using 'sudo -i') and try again."
44- exit 1
25+ # ─── Enable 32-bit Multiarch for Gaming ──────────────────────
26+ if ! dpkg --print-foreign-architectures | grep -q i386; then
27+ echo " [*] Enabling 32-bit multiarch support..."
28+ dpkg --add-architecture i386
29+ apt-get update
4530fi
4631
47- # --- Read release info ---
48- if [ ! -f /etc/trios/release ]; then
49- echo " Error: /etc/trios/release not found. Cannot determine release version."
50- exit 1
32+ # ─── Setup Core Debian Repositories ───────────────────────────
33+ 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
36+ 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
39+
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
5145fi
5246
53- _RELEASE=$( cat /etc/trios/release)
54- _URL=" https://triangulardev.github.io/TriOS/trios/updater/${_RELEASE} .tar.gz"
55- _TMPDIR=" /tmp/trios_update_${_RELEASE} "
56- _ARCHIVE=" ${_TMPDIR} .tar.gz"
57-
58- echo " Detected release: ${_RELEASE} "
59- echo " Updater archive URL: ${_URL} "
60- echo " ----------------------------------------"
61-
62- # --- Ask for confirmation ---
63- read -p " Do you want to proceed with the update now? (y/N): " _confirm
64- _confirm=${_confirm,,}
65-
66- if [ " $_confirm " != " y" ] && [ " $_confirm " != " yes" ]; then
67- echo " Update canceled by user."
68- exit 0
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
6954fi
7055
71- # --- Clean up previous temp directory if exists ---
72- rm -rf " $_TMPDIR " " $_ARCHIVE "
73-
74- echo " Starting update process..."
75- echo " Downloading updater archive from ${_URL} ..."
76-
77- # --- Download the archive ---
78- _http_status=$( curl -w " %{http_code}" -L -o " $_ARCHIVE " " $_URL " --silent)
79-
80- echo " Download HTTP status: ${_http_status} "
81-
82- if [ " $_http_status " == " 404" ]; then
83- echo " -----------------------------------------------------------"
84- echo " It appears you are on a development or nightly build."
85- echo " Official TriOS updater tools are not available for this version."
86- echo " Please reinstall from the latest production build."
87- echo " -----------------------------------------------------------"
88- exit 1
89- elif [ " $_http_status " != " 200" ]; then
90- echo " Unexpected HTTP status code (${_http_status} )."
91- echo " Update aborted."
92- exit 1
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
9361fi
9462
95- # --- Verify archive ---
96- if [ ! -s " $_ARCHIVE " ]; then
97- echo " Download failed or resulted in an empty file."
98- exit 1
63+ # ─── Strict APT Pinning ───────────────────────────────────────
64+ cat > /etc/apt/preferences.d/gpu-drivers.pref << 'EOF '
65+ # ────────────────────────────────────────────────
66+ # APT Pinning Rules for TriOS GPU Driver Installer
67+ # ────────────────────────────────────────────────
68+
69+ # Default: Debian Stable (Trixie)
70+ Package: *
71+ Pin: release a=trixie
72+ Pin-Priority: 990
73+
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
89+ Package: *
90+ Pin: release a=testing
91+ Pin-Priority: 100
92+
93+ # GPU-related packages explicitly allowed from Testing
94+ Package: nvidia-driver nvidia-settings nvidia-kernel-dkms libnvidia-gl* \
95+ libnvidia-egl* libnvidia-compute* libnvidia-encode* libnvidia-decode* \
96+ mesa* libgl1-mesa* libegl* libgbm* vulkan* firmware-amd* firmware-linux* \
97+ intel-media* xserver-xorg-video-intel libvulkan* libdrm* clinfo \
98+ amd64-microcode intel-microcode
99+ Pin: release a=testing
100+ Pin-Priority: 900
101+ EOF
102+
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
113+ curl -fsSL https://download.opensuse.org/repositories/home:/nicoo:/mesa:/debian/Debian_Trixie/Release.key \
114+ | gpg --dearmor -o /etc/apt/trusted.gpg.d/mesa-git.gpg
115+ apt-get update
99116fi
100117
101- # --- Extract the archive ---
102- mkdir -p " $_TMPDIR "
103- echo " Extracting updater archive..."
104- tar -xzf " $_ARCHIVE " -C " $_TMPDIR "
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' )
121+ echo " Detected GPU(s):"
122+ echo " $GPU_INFO "
123+ echo
105124
106- if [ $? -ne 0 ]; then
107- echo " Error: Failed to extract archive."
108- exit 1
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
109134fi
110135
111- # --- Check for update.sh inside extracted directory ---
112- if [ ! -f " $_TMPDIR /update.sh" ]; then
113- echo " Error: update.sh not found in archive."
114- exit 1
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
151+ fi
152+ done
153+
154+ echo " [*] Installing 32-bit NVIDIA libraries for gaming..."
155+ apt-get install -y libnvidia-gl:i386 libnvidia-egl-gbm1:i386 || true
115156fi
116157
117- # --- Make update.sh executable ---
118- chmod +x " $_TMPDIR /update.sh"
119-
120- # --- Run updater script ---
121- echo " Running TriOS updater script..."
122- echo " ----------------------------------------"
158+ # AMD
159+ if echo " $GPU_INFO " | grep -qi amd; then
160+ echo " [*] AMD GPU detected."
161+ apt-get install -y -t testing mesa-vulkan-drivers mesa-opencl-icd clinfo \
162+ vulkan-validationlayers mesa-vulkan-drivers:i386 mesa-opencl-icd:i386 \
163+ firmware-amd-graphics
164+ fi
123165
124- cd " $_TMPDIR "
125- bash ./update.sh
126- _result=$?
166+ # Intel
167+ if echo " $GPU_INFO " | grep -qi intel; then
168+ echo " [*] Intel GPU detected."
169+ apt-get install -y -t testing xserver-xorg-video-intel \
170+ intel-media-va-driver-non-free intel-gpu-tools \
171+ mesa-vulkan-drivers mesa-vulkan-drivers:i386
172+ fi
127173
128- echo " ----------------------------------------"
129- if [ $_result -eq 0 ]; then
130- echo " TriOS update completed successfully."
131- else
132- echo " TriOS updater encountered an error (exit code $_result )."
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
133178fi
134179
135- echo " ----------------------------------------"
136- echo " Log saved to $_LOGFILE "
180+ # ─── Cleanup ─────────────────────────────────────────────────
181+ apt-get autoremove -y
182+ apt-get clean
137183
184+ echo
185+ echo " === GPU Driver Installation Complete ==="
186+ echo " Stable base system preserved — only GPU drivers updated from Testing."
187+ echo " Reboot to apply changes."
0 commit comments