sunshine-entrypoint.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/bin/bash
  2. set -euo pipefail
  3. echo "=============================================================="
  4. echo " Sunshine Gaming Desktop"
  5. echo "=============================================================="
  6. echo
  7. echo "Starting existing desktop stack..."
  8. # On conserve temporairement tout le mécanisme Selkies existant :
  9. # Xorg NVIDIA, XFCE, PipeWire, WirePlumber, D-Bus, etc.
  10. /usr/bin/supervisord -c /etc/supervisord.conf &
  11. SUPERVISOR_PID=$!
  12. cleanup() {
  13. echo "Stopping supervisor..."
  14. kill "${SUPERVISOR_PID}" 2>/dev/null || true
  15. wait "${SUPERVISOR_PID}" 2>/dev/null || true
  16. }
  17. trap cleanup EXIT TERM INT
  18. echo
  19. echo "Waiting for Xorg on ${DISPLAY}..."
  20. for i in $(seq 1 60); do
  21. if xdpyinfo -display "${DISPLAY}" >/dev/null 2>&1; then
  22. echo "Xorg is ready."
  23. break
  24. fi
  25. if ! kill -0 "${SUPERVISOR_PID}" 2>/dev/null; then
  26. echo "ERROR: supervisord exited before Xorg became available."
  27. exit 1
  28. fi
  29. if [ "${i}" -eq 60 ]; then
  30. echo "ERROR: Xorg did not become ready."
  31. exit 1
  32. fi
  33. sleep 1
  34. done
  35. echo
  36. echo "GPU:"
  37. nvidia-smi --query-gpu=name,driver_version --format=csv,noheader || true
  38. echo
  39. echo "Display:"
  40. xdpyinfo -display "${DISPLAY}" \
  41. | grep -E 'dimensions:|resolution:' \
  42. || true
  43. mkdir -p "${HOME}/.config/sunshine"
  44. cat > "${HOME}/.config/sunshine/sunshine.conf" <<'EOF'
  45. system_tray = disabled
  46. capture = nvfbc
  47. encoder = nvenc
  48. EOF
  49. echo "Sunshine configuration:"
  50. cat "${HOME}/.config/sunshine/sunshine.conf"
  51. echo
  52. echo "Starting Sunshine..."
  53. /usr/bin/sunshine &
  54. SUNSHINE_PID=$!
  55. cleanup() {
  56. echo "Stopping Sunshine..."
  57. kill "${SUNSHINE_PID}" 2>/dev/null || true
  58. wait "${SUNSHINE_PID}" 2>/dev/null || true
  59. echo "Stopping supervisor..."
  60. kill "${SUPERVISOR_PID}" 2>/dev/null || true
  61. wait "${SUPERVISOR_PID}" 2>/dev/null || true
  62. }
  63. trap cleanup EXIT TERM INT
  64. echo
  65. echo "Waiting for Sunshine virtual input devices..."
  66. for i in $(seq 1 30); do
  67. if grep -q 'Name="Mouse passthrough"' /proc/bus/input/devices \
  68. && grep -q 'Name="Keyboard passthrough"' /proc/bus/input/devices; then
  69. echo "Sunshine virtual mouse and keyboard detected."
  70. break
  71. fi
  72. if ! kill -0 "${SUNSHINE_PID}" 2>/dev/null; then
  73. echo "ERROR: Sunshine exited before creating input devices."
  74. wait "${SUNSHINE_PID}"
  75. exit $?
  76. fi
  77. sleep 1
  78. done
  79. echo
  80. echo "Restarting Xorg so it picks up Sunshine virtual input devices..."
  81. supervisorctl stop entrypoint || true
  82. pkill -TERM -x Xorg || true
  83. for i in $(seq 1 20); do
  84. if ! pgrep -x Xorg >/dev/null; then
  85. break
  86. fi
  87. sleep 0.5
  88. done
  89. if pgrep -x Xorg >/dev/null; then
  90. echo "Xorg did not stop cleanly, sending SIGKILL..."
  91. pkill -KILL -x Xorg || true
  92. sleep 1
  93. fi
  94. echo "Starting desktop/Xorg again..."
  95. supervisorctl start entrypoint
  96. echo "Waiting for restarted Xorg..."
  97. for i in $(seq 1 60); do
  98. if xdpyinfo -display "${DISPLAY}" >/dev/null 2>&1; then
  99. echo "Restarted Xorg is ready."
  100. break
  101. fi
  102. sleep 1
  103. done
  104. echo
  105. echo "Checking Sunshine input devices in Xorg log..."
  106. grep -Ei \
  107. 'Mouse passthrough|Keyboard passthrough|libinput' \
  108. /home/ubuntu/.local/share/xorg/Xorg.20.log \
  109. | tail -30 \
  110. || true
  111. echo
  112. echo "Sunshine Gaming Desktop ready."
  113. wait "${SUNSHINE_PID}"