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)
This commit is contained in:
CanbiZ
2025-12-17 08:16:50 +01:00
parent 65484b76c0
commit 2305231391
10 changed files with 47 additions and 114 deletions

View File

@ -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

View File

@ -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"

View File

@ -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
read -r -p "${TAB3}Do you need the intel-media-va-driver-non-free driver for HW encoding (Debian 12 only)? <y/N> " prompt
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then

View File

@ -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 ~

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -28,21 +28,10 @@ $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
setup_hwaccel
# Sync GID for video/render groups between host and container
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
@ -53,7 +42,6 @@ else
VIDEO_GID=$(getent group video | cut -d: -f3)
RENDER_GID=$(getent group render | cut -d: -f3)
fi
msg_ok "Set Up Hardware Acceleration"
msg_info "Creating Service"
cat <<EOF >/etc/systemd/system/tdarr-server.service

View File

@ -19,21 +19,10 @@ $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
setup_hwaccel
# Sync GID for video/render groups between host and container
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
@ -44,7 +33,6 @@ else
VIDEO_GID=$(getent group video | cut -d: -f3)
RENDER_GID=$(getent group render | cut -d: -f3)
fi
msg_ok "Set Up Hardware Acceleration"
msg_info "Installing Unmanic"
$STD pip3 install unmanic

View File

@ -2593,8 +2593,9 @@ function setup_hwaccel() {
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
@ -2607,7 +2608,7 @@ function setup_hwaccel() {
os_id="debian"
fi
# Determine if we are on a VM or LXC
# Determine if we are on a VM or LXC (privileged)
local in_ct="${CTTYPE:-0}"
case "$gpu_vendor" in
@ -2618,7 +2619,7 @@ function setup_hwaccel() {
return 1
}
else
# For Debian: fetch Intel GPU drivers from GitHub
# For Debian: fetch Intel GPU drivers from GitHub (latest releases)
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"
}
@ -2637,41 +2638,47 @@ function setup_hwaccel() {
msg_error "Failed to install Intel GPU dependencies"
return 1
}
# Install intel-media-va-driver if available (for newer Intel GPUs)
$STD apt -y install intel-media-va-driver 2>/dev/null || true
;;
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 vainfo || {
msg_error "Failed to install AMD GPU dependencies"
return 1
}
# mesa-opencl-icd and clinfo may not be available on all systems
$STD apt -y install mesa-opencl-icd ocl-icd-libopencl1 clinfo 2>/dev/null || true
# 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
if [[ "$cpu_vendor" == "AuthenticAMD" ]]; then
$STD apt -y install libdrm-amdgpu1 2>/dev/null || true
$STD apt -y install firmware-amd-graphics 2>/dev/null || true
fi
;;
NVIDIA)
# NVIDIA needs manual driver setup - skip for now
msg_info "NVIDIA GPU detected - manual driver setup required"
# NVIDIA needs manual driver setup or use of nvidia-driver packages
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)
# If no discrete GPU, but AMD CPU (e.g., Ryzen APU with integrated graphics)
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 vainfo 2>/dev/null || true
$STD apt -y install mesa-opencl-icd ocl-icd-libopencl1 clinfo 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
fi
cache_installed_version "hwaccel" "1.0"