#!/bin/bash set -euo pipefail # ============================================================ # NVIDIA driver version check # ============================================================ if command -v nvidia-smi >/dev/null 2>&1; then ACTUAL_NVIDIA_DRIVER_VERSION="$( nvidia-smi \ --query-gpu=driver_version \ --format=csv,noheader \ | head -n1 \ | tr -d '[:space:]' )" if [ -n "${EXPECTED_NVIDIA_DRIVER_VERSION:-}" ]; then if [ "${ACTUAL_NVIDIA_DRIVER_VERSION}" != "${EXPECTED_NVIDIA_DRIVER_VERSION}" ]; then echo echo "============================================================" echo "[sunshine] WARNING: NVIDIA DRIVER VERSION MISMATCH" echo "============================================================" echo "[sunshine] GPU Operator driver : ${ACTUAL_NVIDIA_DRIVER_VERSION}" echo "[sunshine] Image expects : ${EXPECTED_NVIDIA_DRIVER_VERSION}" echo "[sunshine] i386 packages : ${NVIDIA_I386_PACKAGE_VERSION:-unknown}" echo echo "[sunshine] 32-bit OpenGL/Vulkan may not work correctly." echo "[sunshine] Update the NVIDIA versions at the top of the Dockerfile" echo "[sunshine] and rebuild this image." echo "============================================================" echo else echo "[sunshine] NVIDIA driver version OK: ${ACTUAL_NVIDIA_DRIVER_VERSION}" fi fi else echo "[sunshine] WARNING: nvidia-smi not found; unable to check NVIDIA driver version." fi echo "==============================================================" echo " Sunshine Gaming Desktop" echo "==============================================================" echo echo "Starting existing desktop stack..." # On conserve temporairement tout le mécanisme Selkies existant : # Xorg NVIDIA, XFCE, PipeWire, WirePlumber, D-Bus, etc. /usr/bin/supervisord -c /etc/supervisord.conf & SUPERVISOR_PID=$! cleanup() { echo "Stopping supervisor..." kill "${SUPERVISOR_PID}" 2>/dev/null || true wait "${SUPERVISOR_PID}" 2>/dev/null || true } trap cleanup EXIT TERM INT echo echo "Waiting for Xorg on ${DISPLAY}..." for i in $(seq 1 60); do if xdpyinfo -display "${DISPLAY}" >/dev/null 2>&1; then echo "Xorg is ready." break fi if ! kill -0 "${SUPERVISOR_PID}" 2>/dev/null; then echo "ERROR: supervisord exited before Xorg became available." exit 1 fi if [ "${i}" -eq 60 ]; then echo "ERROR: Xorg did not become ready." exit 1 fi sleep 1 done # Restore NVIDIA 32-bit userspace libraries after NVIDIA Container Toolkit # has performed its runtime driver injection. if [ ! -e /usr/lib/i386-linux-gnu/libGLX_nvidia.so.0 ] \ && [ -d /opt/nvidia-i386/usr/lib/i386-linux-gnu ]; then echo "[sunshine] Restoring NVIDIA i386 userspace libraries..." sudo mkdir -p /usr/lib/i386-linux-gnu sudo cp -a \ /opt/nvidia-i386/usr/lib/i386-linux-gnu/. \ /usr/lib/i386-linux-gnu/ sudo /sbin/ldconfig fi echo echo "GPU:" nvidia-smi --query-gpu=name,driver_version --format=csv,noheader || true echo echo "Display:" xdpyinfo -display "${DISPLAY}" \ | grep -E 'dimensions:|resolution:' \ || true mkdir -p "${HOME}/.config/sunshine" cat > "${HOME}/.config/sunshine/sunshine.conf" <<'EOF' system_tray = disabled capture = nvfbc encoder = nvenc EOF echo "Sunshine configuration:" cat "${HOME}/.config/sunshine/sunshine.conf" echo echo "Starting Sunshine..." /usr/bin/sunshine & SUNSHINE_PID=$! cleanup() { echo "Stopping Sunshine..." kill "${SUNSHINE_PID}" 2>/dev/null || true wait "${SUNSHINE_PID}" 2>/dev/null || true echo "Stopping supervisor..." kill "${SUPERVISOR_PID}" 2>/dev/null || true wait "${SUPERVISOR_PID}" 2>/dev/null || true } trap cleanup EXIT TERM INT echo echo "Waiting for Sunshine virtual input devices..." for i in $(seq 1 30); do if grep -q 'Name="Mouse passthrough"' /proc/bus/input/devices \ && grep -q 'Name="Keyboard passthrough"' /proc/bus/input/devices; then echo "Sunshine virtual mouse and keyboard detected." break fi if ! kill -0 "${SUNSHINE_PID}" 2>/dev/null; then echo "ERROR: Sunshine exited before creating input devices." wait "${SUNSHINE_PID}" exit $? fi sleep 1 done echo echo "Restarting Xorg so it picks up Sunshine virtual input devices..." supervisorctl stop entrypoint || true pkill -TERM -x Xorg || true for i in $(seq 1 20); do if ! pgrep -x Xorg >/dev/null; then break fi sleep 0.5 done if pgrep -x Xorg >/dev/null; then echo "Xorg did not stop cleanly, sending SIGKILL..." pkill -KILL -x Xorg || true sleep 1 fi echo "Starting desktop/Xorg again..." supervisorctl start entrypoint echo "Waiting for restarted Xorg..." for i in $(seq 1 60); do if xdpyinfo -display "${DISPLAY}" >/dev/null 2>&1; then echo "Restarted Xorg is ready." break fi sleep 1 done echo echo "Checking Sunshine input devices in Xorg log..." grep -Ei \ 'Mouse passthrough|Keyboard passthrough|libinput' \ /home/ubuntu/.local/share/xorg/Xorg.20.log \ | tail -30 \ || true # No more sudo privilege sudo rm -f /etc/sudoers.d/ubuntu echo echo "Sunshine Gaming Desktop ready." wait "${SUNSHINE_PID}"