From 3a9d03fdb71cd33d6ea03351fc69d59a6dad365f Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Wed, 17 Dec 2025 14:37:31 +0100 Subject: [PATCH] use setup_hwaccel for robust hardware acceleration (#10054) * fix(jellyfin): use setup_hwaccel for robust hardware acceleration Replaces manual hardware acceleration setup with the centralized setup_hwaccel function from tools.func. This fixes the installation failure in privileged containers where /dev/dri does not exist (e.g., when no GPU is passed through). The setup_hwaccel function includes: - Proper error handling for missing /dev/dri - GPU vendor detection (Intel, AMD, NVIDIA) - Graceful fallback when no GPU is available Fixes: Installation fails with 'chgrp: cannot access /dev/dri' when creating privileged containers without GPU passthrough. * refactor(hwaccel): standardize hardware acceleration across all install scripts Migrated all install scripts to use the centralized setup_hwaccel function: - plex-install.sh - emby-install.sh - ersatztv-install.sh - frigate-install.sh - tdarr-install.sh - unmanic-install.sh - channels-install.sh - ollama-install.sh - immich-install.sh (added error handling) Enhanced setup_hwaccel function in tools.func: - Added -d /dev/dri check before setting permissions - Added error handling (2>/dev/null || true) for all /dev/dri operations - Added adduser error handling for video/render groups - No longer fails if no GPU is detected (graceful skip) - Added intel-media-va-driver for newer Intel GPUs - Improved AMD APU support with firmware packages - Better NVIDIA handling (warning instead of failure) This fixes installation failures in privileged containers without GPU passthrough, where /dev/dri does not exist. Supports: Ubuntu, Debian 12 (Bookworm), Debian 13 (Trixie) GPU Support: Intel, AMD, NVIDIA (manual driver) * refactor(hwaccel): complete migration for all GPU apps Migrated remaining GPU apps to setup_hwaccel: - fileflows-install.sh - openwebui-install.sh (added setup_hwaccel - was missing) - tunarr-install.sh Also fixed tools/pve/hw-acceleration.sh: - Added error handling for /dev/dri operations - Added chmod 660 /dev/dri/* that was missing - Added error suppression for adduser commands All 13 GPU apps (var_gpu=yes) now use centralized setup_hwaccel: jellyfin, plex, emby, ersatztv, frigate, tdarr, unmanic, channels, ollama, immich, fileflows, openwebui, tunarr * feat(hwaccel): complete Intel non-free driver support and GID sync Enhanced setup_hwaccel function: - Auto-detect Intel GPU generation (Gen 9+ for non-free drivers) - Debian 12 (Bookworm): Add non-free repo + intel-media-va-driver-non-free - Debian 13 (Trixie): Add non-free repo + libvpl2 + mesa-opencl-icd - Ubuntu: Use ubuntu repos with intel-media-va-driver - Fallback to open drivers if non-free fails - GID sync for video/render groups (moved from install scripts) OpenWebUI: Added Intel oneAPI support when installing Ollama - Intel Level Zero GPU support - Intel oneAPI Base Toolkit - Same setup as standalone Ollama install Cleanup: - Removed duplicate GID sync from tdarr-install.sh - Removed duplicate GID sync from unmanic-install.sh * fix(ersatztv): remove duplicate HW acceleration code Removed manual Intel HW acceleration setup that remained after setup_hwaccel migration. The non-free driver prompt is no longer needed as setup_hwaccel auto-detects Intel GPU generation. --- install/channels-install.sh | 14 +-- install/emby-install.sh | 11 +- install/ersatztv-install.sh | 33 +----- install/fileflows-install.sh | 22 +--- install/frigate-install.sh | 9 +- install/immich-install.sh | 11 +- install/jellyfin-install.sh | 20 +--- install/ollama-install.sh | 15 +-- install/openwebui-install.sh | 32 ++++++ install/plex-install.sh | 11 +- install/tdarr-install.sh | 27 +---- install/tunarr-install.sh | 48 +------- install/unmanic-install.sh | 27 +---- misc/tools.func | 213 ++++++++++++++++++++++++++--------- 14 files changed, 213 insertions(+), 280 deletions(-) diff --git a/install/channels-install.sh b/install/channels-install.sh index 2d9f75ddd..cb41fb753 100644 --- a/install/channels-install.sh +++ b/install/channels-install.sh @@ -29,19 +29,7 @@ if [[ ! "$CONFIRM" =~ ^([yY][eE][sS]|[yY])$ ]]; then exit 10 fi -if [[ "$CTTYPE" == "0" ]]; then - msg_info "Setting Up Hardware Acceleration" - $STD apt-get -y install \ - va-driver-all \ - ocl-icd-libopencl1 \ - intel-opencl-icd - chgrp video /dev/dri - chmod 755 /dev/dri - chmod 660 /dev/dri/* - $STD adduser $(id -u -n) video - $STD adduser $(id -u -n) render - msg_ok "Set Up Hardware Acceleration" -fi +setup_hwaccel msg_info "Installing Channels DVR Server (Patience)" cd /opt diff --git a/install/emby-install.sh b/install/emby-install.sh index 31b20bd1a..9e84399e4 100644 --- a/install/emby-install.sh +++ b/install/emby-install.sh @@ -13,16 +13,7 @@ setting_up_container network_check update_os -msg_info "Setting Up Hardware Acceleration" -$STD apt-get -y install {va-driver-all,ocl-icd-libopencl1,intel-opencl-icd,vainfo,intel-gpu-tools} -if [[ "$CTTYPE" == "0" ]]; then - chgrp video /dev/dri - chmod 755 /dev/dri - chmod 660 /dev/dri/* - $STD adduser $(id -u -n) video - $STD adduser $(id -u -n) render -fi -msg_ok "Set Up Hardware Acceleration" +setup_hwaccel fetch_and_deploy_gh_release "emby" "MediaBrowser/Emby.Releases" "binary" diff --git a/install/ersatztv-install.sh b/install/ersatztv-install.sh index 4f94f8131..e0208793f 100644 --- a/install/ersatztv-install.sh +++ b/install/ersatztv-install.sh @@ -13,38 +13,7 @@ setting_up_container network_check update_os -msg_info "Setting Up Hardware Acceleration" -$STD apt-get -y install {va-driver-all,ocl-icd-libopencl1,intel-opencl-icd,vainfo,intel-gpu-tools} -if [[ "$CTTYPE" == "0" ]]; then - chgrp video /dev/dri - chmod 755 /dev/dri - chmod 660 /dev/dri/* - $STD adduser $(id -u -n) video - $STD adduser $(id -u -n) render -fi -msg_ok "Set Up Hardware Acceleration" - -read -r -p "${TAB3}Do you need the intel-media-va-driver-non-free driver for HW encoding (Debian 12 only)? " prompt -if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then - msg_info "Installing Intel Hardware Acceleration (non-free)" - cat </etc/apt/sources.list.d/non-free.list - -deb http://deb.debian.org/debian bookworm non-free non-free-firmware -deb-src http://deb.debian.org/debian bookworm non-free non-free-firmware - -deb http://deb.debian.org/debian-security bookworm-security non-free non-free-firmware -deb-src http://deb.debian.org/debian-security bookworm-security non-free non-free-firmware - -deb http://deb.debian.org/debian bookworm-updates non-free non-free-firmware -deb-src http://deb.debian.org/debian bookworm-updates non-free non-free-firmware -EOF - $STD apt-get update - $STD apt-get -y install {intel-media-va-driver-non-free,ocl-icd-libopencl1,intel-opencl-icd,vainfo,intel-gpu-tools} -else - msg_info "Installing Intel Hardware Acceleration" - $STD apt-get -y install {va-driver-all,ocl-icd-libopencl1,intel-opencl-icd,vainfo,intel-gpu-tools} -fi -msg_ok "Installed and Set Up Intel Hardware Acceleration" +setup_hwaccel fetch_and_deploy_gh_release "ersatztv" "ErsatzTV/ErsatzTV" "prebuild" "latest" "/opt/ErsatzTV" "*linux-x64.tar.gz" fetch_and_deploy_gh_release "ersatztv-ffmpeg" "ErsatzTV/ErsatzTV-ffmpeg" "prebuild" "latest" "/opt/ErsatzTV-ffmpeg" "*-linux64-gpl-7.1.tar.xz" diff --git a/install/fileflows-install.sh b/install/fileflows-install.sh index cd4b8f978..b6b7ed654 100644 --- a/install/fileflows-install.sh +++ b/install/fileflows-install.sh @@ -21,27 +21,7 @@ $STD apt-get install -y \ imagemagick msg_ok "Installed Dependencies" -read -r -p "${TAB3}Do you need the intel-media-va-driver-non-free driver for HW encoding (Debian 12 only)? " prompt -if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then - msg_info "Installing Intel Hardware Acceleration (non-free)" - cat </etc/apt/sources.list.d/non-free.list - -deb http://deb.debian.org/debian bookworm non-free non-free-firmware -deb-src http://deb.debian.org/debian bookworm non-free non-free-firmware - -deb http://deb.debian.org/debian-security bookworm-security non-free non-free-firmware -deb-src http://deb.debian.org/debian-security bookworm-security non-free non-free-firmware - -deb http://deb.debian.org/debian bookworm-updates non-free non-free-firmware -deb-src http://deb.debian.org/debian bookworm-updates non-free non-free-firmware -EOF - $STD apt-get update - $STD apt-get -y install {intel-media-va-driver-non-free,ocl-icd-libopencl1,intel-opencl-icd,vainfo,intel-gpu-tools} -else - msg_info "Installing Intel Hardware Acceleration" - $STD apt-get -y install {va-driver-all,ocl-icd-libopencl1,intel-opencl-icd,vainfo,intel-gpu-tools} -fi -msg_ok "Installed and Set Up Intel Hardware Acceleration" +setup_hwaccel msg_info "Installing ASP.NET Core Runtime" curl -fsSL https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -o packages-microsoft-prod.deb diff --git a/install/frigate-install.sh b/install/frigate-install.sh index 9853975d3..55803b917 100644 --- a/install/frigate-install.sh +++ b/install/frigate-install.sh @@ -33,14 +33,7 @@ chmod +x go2rtc $STD ln -svf /usr/local/go2rtc/bin/go2rtc /usr/local/bin/go2rtc msg_ok "Installed go2rtc" -msg_info "Setting Up Hardware Acceleration" -$STD apt-get -y install {va-driver-all,ocl-icd-libopencl1,intel-opencl-icd,vainfo,intel-gpu-tools} -if [[ "$CTTYPE" == "0" ]]; then - chgrp video /dev/dri - chmod 755 /dev/dri - chmod 660 /dev/dri/* -fi -msg_ok "Set Up Hardware Acceleration" +setup_hwaccel msg_info "Installing Frigate v0.14.1 (Perseverance)" cd ~ diff --git a/install/immich-install.sh b/install/immich-install.sh index efd0bb245..48471a624 100644 --- a/install/immich-install.sh +++ b/install/immich-install.sh @@ -75,12 +75,13 @@ $STD apt install -y jellyfin-ffmpeg7 ln -sf /usr/lib/jellyfin-ffmpeg/ffmpeg /usr/bin/ffmpeg ln -sf /usr/lib/jellyfin-ffmpeg/ffprobe /usr/bin/ffprobe +# Set permissions for /dev/dri (only in privileged containers and if /dev/dri exists) if [[ "$CTTYPE" == "0" && -d /dev/dri ]]; then - chgrp video /dev/dri - chmod 755 /dev/dri - chmod 660 /dev/dri/* - $STD adduser "$(id -u -n)" video - $STD adduser "$(id -u -n)" render + chgrp video /dev/dri 2>/dev/null || true + chmod 755 /dev/dri 2>/dev/null || true + chmod 660 /dev/dri/* 2>/dev/null || true + $STD adduser "$(id -u -n)" video 2>/dev/null || true + $STD adduser "$(id -u -n)" render 2>/dev/null || true fi msg_ok "Dependencies Installed" diff --git a/install/jellyfin-install.sh b/install/jellyfin-install.sh index 0c971d3cc..87a3637d0 100644 --- a/install/jellyfin-install.sh +++ b/install/jellyfin-install.sh @@ -13,25 +13,7 @@ setting_up_container network_check update_os -msg_info "Setting Up Hardware Acceleration" -if ! grep -qEi 'ubuntu' /etc/os-release; then - fetch_and_deploy_gh_release "intel-igc-core-2" "intel/intel-graphics-compiler" "binary" "latest" "" "intel-igc-core-2_*_amd64.deb" - fetch_and_deploy_gh_release "intel-igc-opencl-2" "intel/intel-graphics-compiler" "binary" "latest" "" "intel-igc-opencl-2_*_amd64.deb" - fetch_and_deploy_gh_release "intel-libgdgmm12" "intel/compute-runtime" "binary" "latest" "" "libigdgmm12_*_amd64.deb" - fetch_and_deploy_gh_release "intel-opencl-icd" "intel/compute-runtime" "binary" "latest" "" "intel-opencl-icd_*_amd64.deb" -else - $STD apt -y install intel-opencl-icd -fi - -$STD apt -y install {va-driver-all,ocl-icd-libopencl1,vainfo,intel-gpu-tools} -if [[ "$CTTYPE" == "0" ]]; then - chgrp video /dev/dri - chmod 755 /dev/dri - chmod 660 /dev/dri/* - $STD adduser $(id -u -n) video - $STD adduser $(id -u -n) render -fi -msg_ok "Set Up Hardware Acceleration" +setup_hwaccel msg_info "Installing Jellyfin" VERSION="$(awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release)" diff --git a/install/ollama-install.sh b/install/ollama-install.sh index f9e7fabd9..396a55b78 100644 --- a/install/ollama-install.sh +++ b/install/ollama-install.sh @@ -41,16 +41,11 @@ EOF $STD apt update msg_ok "Set up Intel® Repositories" -msg_info "Setting Up Hardware Acceleration" -$STD apt -y install {va-driver-all,ocl-icd-libopencl1,intel-opencl-icd,vainfo,intel-gpu-tools,intel-level-zero-gpu,level-zero,level-zero-dev} -if [[ "$CTTYPE" == "0" ]]; then - chgrp video /dev/dri - chmod 755 /dev/dri - chmod 660 /dev/dri/* - $STD adduser $(id -u -n) video - $STD adduser $(id -u -n) render -fi -msg_ok "Set Up Hardware Acceleration" +setup_hwaccel + +msg_info "Installing Intel® Level Zero" +$STD apt -y install intel-level-zero-gpu level-zero level-zero-dev 2>/dev/null || true +msg_ok "Installed Intel® Level Zero" msg_info "Installing Intel® oneAPI Base Toolkit (Patience)" $STD apt install -y --no-install-recommends intel-basekit-2024.1 diff --git a/install/openwebui-install.sh b/install/openwebui-install.sh index 2be6290ec..009e6310e 100644 --- a/install/openwebui-install.sh +++ b/install/openwebui-install.sh @@ -17,6 +17,8 @@ msg_info "Installing Dependencies" $STD apt install -y ffmpeg msg_ok "Installed Dependencies" +setup_hwaccel + PYTHON_VERSION="3.12" setup_uv msg_info "Installing Open WebUI" @@ -25,6 +27,36 @@ msg_ok "Installed Open WebUI" read -r -p "${TAB3}Would you like to add Ollama? " prompt if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then + msg_info "Setting up Intel® Repositories" + mkdir -p /usr/share/keyrings + curl -fsSL https://repositories.intel.com/gpu/intel-graphics.key | gpg --dearmor -o /usr/share/keyrings/intel-graphics.gpg 2>/dev/null || true + cat </etc/apt/sources.list.d/intel-gpu.sources +Types: deb +URIs: https://repositories.intel.com/gpu/ubuntu +Suites: jammy +Components: client +Architectures: amd64 i386 +Signed-By: /usr/share/keyrings/intel-graphics.gpg +EOF + curl -fsSL https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB | gpg --dearmor -o /usr/share/keyrings/oneapi-archive-keyring.gpg 2>/dev/null || true + cat </etc/apt/sources.list.d/oneAPI.sources +Types: deb +URIs: https://apt.repos.intel.com/oneapi +Suites: all +Components: main +Signed-By: /usr/share/keyrings/oneapi-archive-keyring.gpg +EOF + $STD apt update + msg_ok "Set up Intel® Repositories" + + msg_info "Installing Intel® Level Zero" + $STD apt -y install intel-level-zero-gpu level-zero level-zero-dev 2>/dev/null || true + msg_ok "Installed Intel® Level Zero" + + msg_info "Installing Intel® oneAPI Base Toolkit (Patience)" + $STD apt install -y --no-install-recommends intel-basekit-2024.1 2>/dev/null || true + msg_ok "Installed Intel® oneAPI Base Toolkit" + msg_info "Installing Ollama" curl -fsSLO -C - https://ollama.com/download/ollama-linux-amd64.tgz tar -C /usr -xzf ollama-linux-amd64.tgz diff --git a/install/plex-install.sh b/install/plex-install.sh index a12ba3fee..64a61e847 100644 --- a/install/plex-install.sh +++ b/install/plex-install.sh @@ -13,16 +13,7 @@ setting_up_container network_check update_os -msg_info "Setting Up Hardware Acceleration" -$STD apt -y install {va-driver-all,ocl-icd-libopencl1,intel-opencl-icd,vainfo,intel-gpu-tools} -if [[ "$CTTYPE" == "0" ]]; then - chgrp video /dev/dri - chmod 755 /dev/dri - chmod 660 /dev/dri/* - $STD adduser $(id -u -n) video - $STD adduser $(id -u -n) render -fi -msg_ok "Set Up Hardware Acceleration" +setup_hwaccel msg_info "Setting Up Plex Media Server Repository" curl -fsSL https://downloads.plex.tv/plex-keys/PlexSign.key | tee /usr/share/keyrings/PlexSign.asc >/dev/null diff --git a/install/tdarr-install.sh b/install/tdarr-install.sh index ba06dc8e8..95bc56124 100644 --- a/install/tdarr-install.sh +++ b/install/tdarr-install.sh @@ -28,32 +28,7 @@ $STD ./Tdarr_Updater rm -rf /opt/tdarr/Tdarr_Updater.zip msg_ok "Installed Tdarr" -msg_info "Setting Up Hardware Acceleration" -$STD apt -y install \ - va-driver-all \ - ocl-icd-libopencl1 \ - vainfo \ - intel-gpu-tools \ - mesa-va-drivers \ - mesa-vdpau-drivers \ - intel-media-va-driver -if [[ "$CTTYPE" == "0" ]]; then - chgrp video /dev/dri - chmod 755 /dev/dri - chmod 660 /dev/dri/* - $STD adduser $(id -u -n) video - $STD adduser $(id -u -n) render - VIDEO_GID=$(getent group video | cut -d: -f3) - RENDER_GID=$(getent group render | cut -d: -f3) - if [[ -n "$VIDEO_GID" && -n "$RENDER_GID" ]]; then - sed -i "s/^video:x:[0-9]*:/video:x:$VIDEO_GID:/" /etc/group - sed -i "s/^render:x:[0-9]*:/render:x:$RENDER_GID:/" /etc/group - fi -else - VIDEO_GID=$(getent group video | cut -d: -f3) - RENDER_GID=$(getent group render | cut -d: -f3) -fi -msg_ok "Set Up Hardware Acceleration" +setup_hwaccel msg_info "Creating Service" cat </etc/systemd/system/tdarr-server.service diff --git a/install/tunarr-install.sh b/install/tunarr-install.sh index 924803a6f..e18b98077 100644 --- a/install/tunarr-install.sh +++ b/install/tunarr-install.sh @@ -13,53 +13,7 @@ setting_up_container network_check update_os -msg_info "Setting Up Hardware Acceleration" -if [[ "$CTTYPE" == "0" ]]; then - $STD adduser "$(id -un)" video - $STD adduser "$(id -un)" render -fi -msg_ok "Base Hardware Acceleration Set Up" - -read -r -p "${TAB3}Do you need the intel-media-va-driver-non-free driver for HW encoding (Debian 13 only)? " prompt -if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then - msg_info "Installing Intel Hardware Acceleration (non-free)" - cat <<'EOF' >/etc/apt/sources.list.d/non-free.sources -Types: deb deb-src -URIs: http://deb.debian.org/debian -Suites: trixie -Components: non-free non-free-firmware - -Types: deb deb-src -URIs: http://deb.debian.org/debian-security -Suites: trixie-security -Components: non-free non-free-firmware - -Types: deb deb-src -URIs: http://deb.debian.org/debian -Suites: trixie-updates -Components: non-free non-free-firmware -EOF - - $STD apt update - $STD apt -y install \ - intel-media-va-driver-non-free \ - ocl-icd-libopencl1 \ - mesa-opencl-icd \ - mesa-va-drivers \ - libvpl2 \ - vainfo \ - intel-gpu-tools -else - msg_info "Installing Intel Hardware Acceleration (open packages)" - $STD apt -y install \ - va-driver-all \ - ocl-icd-libopencl1 \ - mesa-opencl-icd \ - mesa-va-drivers \ - vainfo \ - intel-gpu-tools -fi -msg_ok "Installed and Set Up Intel Hardware Acceleration" +setup_hwaccel fetch_and_deploy_gh_release "tunarr" "chrisbenincasa/tunarr" "prebuild" "latest" "/opt/tunarr" "*linux-x64.tar.gz" cd /opt/tunarr diff --git a/install/unmanic-install.sh b/install/unmanic-install.sh index f455dffc7..b1d2b3987 100644 --- a/install/unmanic-install.sh +++ b/install/unmanic-install.sh @@ -19,32 +19,7 @@ $STD apt install -y \ python3-pip msg_ok "Installed Dependencies" -msg_info "Setting Up Hardware Acceleration" -$STD apt -y install \ - va-driver-all \ - ocl-icd-libopencl1 \ - vainfo \ - intel-gpu-tools \ - mesa-va-drivers \ - mesa-vdpau-drivers \ - intel-media-va-driver -if [[ "$CTTYPE" == "0" ]]; then - chgrp video /dev/dri - chmod 755 /dev/dri - chmod 660 /dev/dri/* - $STD adduser $(id -u -n) video - $STD adduser $(id -u -n) render - VIDEO_GID=$(getent group video | cut -d: -f3) - RENDER_GID=$(getent group render | cut -d: -f3) - if [[ -n "$VIDEO_GID" && -n "$RENDER_GID" ]]; then - sed -i "s/^video:x:[0-9]*:/video:x:$VIDEO_GID:/" /etc/group - sed -i "s/^render:x:[0-9]*:/render:x:$RENDER_GID:/" /etc/group - fi -else - VIDEO_GID=$(getent group video | cut -d: -f3) - RENDER_GID=$(getent group render | cut -d: -f3) -fi -msg_ok "Set Up Hardware Acceleration" +setup_hwaccel msg_info "Installing Unmanic" $STD pip3 install unmanic diff --git a/misc/tools.func b/misc/tools.func index 42dd47a6c..a122317f3 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -1460,19 +1460,19 @@ check_for_gh_release() { # Try /latest endpoint for non-pinned versions (most efficient) local releases_json="" - + if [[ -z "$pinned_version_in" ]]; then releases_json=$(curl -fsSL --max-time 20 \ -H 'Accept: application/vnd.github+json' \ -H 'X-GitHub-Api-Version: 2022-11-28' \ "https://api.github.com/repos/${source}/releases/latest" 2>/dev/null) - + if [[ $? -eq 0 ]] && [[ -n "$releases_json" ]]; then # Wrap single release in array for consistent processing releases_json="[$releases_json]" fi fi - + # If no releases yet (pinned version OR /latest failed), fetch up to 100 if [[ -z "$releases_json" ]]; then # Fetch releases and exclude drafts/prereleases @@ -2585,93 +2585,200 @@ function setup_hwaccel() { fi # Detect GPU vendor (Intel, AMD, NVIDIA) - local gpu_vendor - gpu_vendor=$(lspci 2>/dev/null | grep -Ei 'vga|3d|display' | grep -Eo 'Intel|AMD|NVIDIA' | head -n1 || echo "") + local gpu_vendor gpu_info + gpu_info=$(lspci 2>/dev/null | grep -Ei 'vga|3d|display' || echo "") + gpu_vendor=$(echo "$gpu_info" | grep -Eo 'Intel|AMD|NVIDIA' | head -n1 || echo "") # Detect CPU vendor (relevant for AMD APUs) local cpu_vendor cpu_vendor=$(lscpu 2>/dev/null | grep -i 'Vendor ID' | awk '{print $3}' || echo "") if [[ -z "$gpu_vendor" && -z "$cpu_vendor" ]]; then - msg_error "No GPU or CPU vendor detected (missing lspci/lscpu output)" - return 1 + msg_warn "No GPU or CPU vendor detected - skipping hardware acceleration setup" + msg_ok "Setup Hardware Acceleration (skipped - no GPU detected)" + return 0 fi # Detect OS with fallbacks - local os_id os_codename - os_id=$(grep -oP '(?<=^ID=).+' /etc/os-release 2>/dev/null | tr -d '"' || grep '^ID=' /etc/os-release 2>/dev/null | cut -d'=' -f2 | tr -d '"' || echo "debian") - os_codename=$(grep -oP '(?<=^VERSION_CODENAME=).+' /etc/os-release 2>/dev/null | tr -d '"' || grep '^VERSION_CODENAME=' /etc/os-release 2>/dev/null | cut -d'=' -f2 | tr -d '"' || echo "unknown") + local os_id os_codename os_version + os_id=$(grep -oP '(?<=^ID=).+' /etc/os-release 2>/dev/null | tr -d '"' || echo "debian") + os_codename=$(grep -oP '(?<=^VERSION_CODENAME=).+' /etc/os-release 2>/dev/null | tr -d '"' || echo "unknown") + os_version=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release 2>/dev/null | tr -d '"' || echo "") - # Validate os_id - if [[ -z "$os_id" ]]; then - os_id="debian" - fi + [[ -z "$os_id" ]] && os_id="debian" - # Determine if we are on a VM or LXC + # Determine if we are in a privileged LXC container local in_ct="${CTTYPE:-0}" case "$gpu_vendor" in Intel) - if [[ "$os_id" == "ubuntu" ]]; then - $STD apt -y install intel-opencl-icd || { - msg_error "Failed to install intel-opencl-icd" - return 1 - } - else - # For Debian: fetch Intel GPU drivers from GitHub - fetch_and_deploy_gh_release "" "intel/intel-graphics-compiler" "binary" "latest" "" "intel-igc-core-2_*_amd64.deb" || { - msg_warn "Failed to deploy Intel IGC core 2" - } - fetch_and_deploy_gh_release "" "intel/intel-graphics-compiler" "binary" "latest" "" "intel-igc-opencl-2_*_amd64.deb" || { - msg_warn "Failed to deploy Intel IGC OpenCL 2" - } - fetch_and_deploy_gh_release "" "intel/compute-runtime" "binary" "latest" "" "libigdgmm12_*_amd64.deb" || { - msg_warn "Failed to deploy Intel GDGMM12" - } - fetch_and_deploy_gh_release "" "intel/compute-runtime" "binary" "latest" "" "intel-opencl-icd_*_amd64.deb" || { - msg_warn "Failed to deploy Intel OpenCL ICD" - } + # Detect Intel GPU generation for driver selection + # Gen 9+ (Skylake and newer) benefit from non-free drivers + local intel_gen="" + local needs_nonfree=false + + # Check for specific Intel GPU models that need non-free drivers + if echo "$gpu_info" | grep -Ei 'HD Graphics [56][0-9]{2}|UHD Graphics|Iris|Arc|DG[12]' &>/dev/null; then + needs_nonfree=true + intel_gen="gen9+" fi - $STD apt -y install va-driver-all ocl-icd-libopencl1 vainfo intel-gpu-tools || { - msg_error "Failed to install Intel GPU dependencies" - return 1 - } + if [[ "$os_id" == "ubuntu" ]]; then + # Ubuntu: Use packages from Ubuntu repos + $STD apt -y install \ + va-driver-all \ + ocl-icd-libopencl1 \ + intel-opencl-icd \ + vainfo \ + intel-gpu-tools || { + msg_error "Failed to install Intel GPU dependencies" + return 1 + } + # Try to install intel-media-va-driver for newer GPUs + $STD apt -y install intel-media-va-driver 2>/dev/null || true + + elif [[ "$os_id" == "debian" ]]; then + # Debian: Check version and install appropriate drivers + if [[ "$needs_nonfree" == true ]]; then + # Add non-free repo for intel-media-va-driver-non-free + if [[ "$os_codename" == "bookworm" ]]; then + # Debian 12 Bookworm + if [[ ! -f /etc/apt/sources.list.d/non-free.list && ! -f /etc/apt/sources.list.d/non-free.sources ]]; then + cat </etc/apt/sources.list.d/non-free.sources +Types: deb +URIs: http://deb.debian.org/debian +Suites: bookworm bookworm-updates +Components: non-free non-free-firmware +EOF + $STD apt update + fi + $STD apt -y install \ + intel-media-va-driver-non-free \ + ocl-icd-libopencl1 \ + intel-opencl-icd \ + vainfo \ + intel-gpu-tools || { + msg_warn "Non-free driver install failed, falling back to open drivers" + needs_nonfree=false + } + + elif [[ "$os_codename" == "trixie" || "$os_codename" == "sid" ]]; then + # Debian 13 Trixie / Sid + if [[ ! -f /etc/apt/sources.list.d/non-free.sources ]]; then + cat <<'EOF' >/etc/apt/sources.list.d/non-free.sources +Types: deb +URIs: http://deb.debian.org/debian +Suites: trixie trixie-updates +Components: non-free non-free-firmware + +Types: deb +URIs: http://deb.debian.org/debian-security +Suites: trixie-security +Components: non-free non-free-firmware +EOF + $STD apt update + fi + $STD apt -y install \ + intel-media-va-driver-non-free \ + ocl-icd-libopencl1 \ + mesa-opencl-icd \ + mesa-va-drivers \ + libvpl2 \ + vainfo \ + intel-gpu-tools 2>/dev/null || { + msg_warn "Non-free driver install failed, falling back to open drivers" + needs_nonfree=false + } + fi + fi + + # Fallback to open drivers or older Intel GPUs + if [[ "$needs_nonfree" == false ]]; then + # Fetch latest Intel drivers from GitHub for Debian + fetch_and_deploy_gh_release "" "intel/intel-graphics-compiler" "binary" "latest" "" "intel-igc-core-2_*_amd64.deb" || { + msg_warn "Failed to deploy Intel IGC core 2" + } + fetch_and_deploy_gh_release "" "intel/intel-graphics-compiler" "binary" "latest" "" "intel-igc-opencl-2_*_amd64.deb" || { + msg_warn "Failed to deploy Intel IGC OpenCL 2" + } + fetch_and_deploy_gh_release "" "intel/compute-runtime" "binary" "latest" "" "libigdgmm12_*_amd64.deb" || { + msg_warn "Failed to deploy Intel GDGMM12" + } + fetch_and_deploy_gh_release "" "intel/compute-runtime" "binary" "latest" "" "intel-opencl-icd_*_amd64.deb" || { + msg_warn "Failed to deploy Intel OpenCL ICD" + } + + $STD apt -y install \ + va-driver-all \ + ocl-icd-libopencl1 \ + mesa-opencl-icd \ + mesa-va-drivers \ + vainfo \ + intel-gpu-tools || { + msg_error "Failed to install Intel GPU dependencies" + return 1 + } + fi + fi ;; + AMD) - $STD apt -y install mesa-va-drivers mesa-vdpau-drivers mesa-opencl-icd vainfo clinfo || { + $STD apt -y install \ + mesa-va-drivers \ + mesa-vdpau-drivers \ + mesa-opencl-icd \ + ocl-icd-libopencl1 \ + vainfo \ + clinfo 2>/dev/null || { msg_error "Failed to install AMD GPU dependencies" return 1 } - # For AMD CPUs without discrete GPU (APUs) - if [[ "$cpu_vendor" == "AuthenticAMD" && -n "$gpu_vendor" ]]; then - $STD apt -y install libdrm-amdgpu1 firmware-amd-graphics || true + # AMD firmware for better GPU support + if [[ "$os_id" == "debian" ]]; then + $STD apt -y install firmware-amd-graphics 2>/dev/null || true fi + $STD apt -y install libdrm-amdgpu1 2>/dev/null || true ;; + NVIDIA) - # NVIDIA needs manual driver setup - skip for now - msg_info "NVIDIA GPU detected - manual driver setup required" + # NVIDIA needs manual driver setup or passthrough from host + msg_warn "NVIDIA GPU detected - driver must be installed manually or passed through from host" + # Install basic VA-API support for potential hybrid setups + $STD apt -y install va-driver-all vainfo 2>/dev/null || true ;; + *) - # If no discrete GPU, but AMD CPU (e.g., Ryzen APU) + # No discrete GPU detected - check for AMD APU if [[ "$cpu_vendor" == "AuthenticAMD" ]]; then - $STD apt -y install mesa-opencl-icd ocl-icd-libopencl1 clinfo || { - msg_error "Failed to install Mesa OpenCL stack" - return 1 - } + $STD apt -y install \ + mesa-va-drivers \ + mesa-vdpau-drivers \ + mesa-opencl-icd \ + ocl-icd-libopencl1 \ + vainfo 2>/dev/null || true else - msg_warn "No supported GPU vendor detected - skipping GPU acceleration" + msg_warn "No supported GPU vendor detected - skipping GPU driver installation" fi ;; esac - if [[ "$in_ct" == "0" ]]; then + # Set permissions for /dev/dri (only in privileged containers and if /dev/dri exists) + if [[ "$in_ct" == "0" && -d /dev/dri ]]; then chgrp video /dev/dri 2>/dev/null || true chmod 755 /dev/dri 2>/dev/null || true chmod 660 /dev/dri/* 2>/dev/null || true - $STD adduser "$(id -u -n)" video - $STD adduser "$(id -u -n)" render + $STD adduser "$(id -u -n)" video 2>/dev/null || true + $STD adduser "$(id -u -n)" render 2>/dev/null || true + + # Sync GID for video/render groups between host and container + local host_video_gid host_render_gid + host_video_gid=$(getent group video | cut -d: -f3) + host_render_gid=$(getent group render | cut -d: -f3) + if [[ -n "$host_video_gid" && -n "$host_render_gid" ]]; then + sed -i "s/^video:x:[0-9]*:/video:x:$host_video_gid:/" /etc/group 2>/dev/null || true + sed -i "s/^render:x:[0-9]*:/render:x:$host_render_gid:/" /etc/group 2>/dev/null || true + fi fi cache_installed_version "hwaccel" "1.0"