selkies-gstreamer-entrypoint.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/bin/bash
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at https://mozilla.org/MPL/2.0/.
  5. set -e
  6. # Wait for XDG_RUNTIME_DIR
  7. until [ -d "${XDG_RUNTIME_DIR}" ]; do sleep 0.5; done
  8. # Configure joystick interposer
  9. export SELKIES_INTERPOSER='/usr/$LIB/selkies_joystick_interposer.so'
  10. export LD_PRELOAD="${SELKIES_INTERPOSER}${LD_PRELOAD:+:${LD_PRELOAD}}"
  11. export SDL_JOYSTICK_DEVICE=/dev/input/js0
  12. # Set default display
  13. export DISPLAY="${DISPLAY:-:20}"
  14. # PipeWire-Pulse server socket path
  15. export PIPEWIRE_LATENCY="32/48000"
  16. export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/tmp}"
  17. export PIPEWIRE_RUNTIME_DIR="${PIPEWIRE_RUNTIME_DIR:-${XDG_RUNTIME_DIR:-/tmp}}"
  18. export PULSE_RUNTIME_PATH="${PULSE_RUNTIME_PATH:-${XDG_RUNTIME_DIR:-/tmp}/pulse}"
  19. export PULSE_SERVER="${PULSE_SERVER:-unix:${PULSE_RUNTIME_PATH:-${XDG_RUNTIME_DIR:-/tmp}/pulse}/native}"
  20. # Export environment variables required for Selkies-GStreamer
  21. export GST_DEBUG="${GST_DEBUG:-*:2}"
  22. export GSTREAMER_PATH=/opt/gstreamer
  23. # Source environment for GStreamer
  24. . /opt/gstreamer/gst-env
  25. export SELKIES_ENCODER="${SELKIES_ENCODER:-x264enc}"
  26. export SELKIES_ENABLE_RESIZE="${SELKIES_ENABLE_RESIZE:-false}"
  27. if ( [ -z "${SELKIES_TURN_USERNAME}" ] || [ -z "${SELKIES_TURN_PASSWORD}" ] ) && [ -z "${SELKIES_TURN_SHARED_SECRET}" ] || [ -z "${SELKIES_TURN_HOST}" ] || [ -z "${SELKIES_TURN_PORT}" ]; then
  28. export TURN_RANDOM_PASSWORD="$(tr -dc 'A-Za-z0-9' < /dev/urandom 2>/dev/null | head -c 24)"
  29. export SELKIES_TURN_HOST="${SELKIES_TURN_HOST:-$(curl -fsSL checkip.amazonaws.com 2>/dev/null || hostname -I 2>/dev/null | awk '{print $1}' || echo '127.0.0.1')}"
  30. export SELKIES_TURN_PORT="3478"
  31. export SELKIES_TURN_USERNAME="selkies"
  32. export SELKIES_TURN_PASSWORD="${TURN_RANDOM_PASSWORD}"
  33. export SELKIES_TURN_PROTOCOL="${SELKIES_TURN_PROTOCOL:-tcp}"
  34. /etc/start-turnserver.sh &
  35. fi
  36. # Wait for X server to start
  37. echo 'Waiting for X Socket' && until [ -S "/tmp/.X11-unix/X${DISPLAY#*:}" ]; do sleep 0.5; done && echo 'X Server is ready'
  38. # Configure NGINX
  39. if [ "$(echo ${SELKIES_ENABLE_BASIC_AUTH} | tr '[:upper:]' '[:lower:]')" != "false" ]; then htpasswd -bcm "${XDG_RUNTIME_DIR}/.htpasswd" "${SELKIES_BASIC_AUTH_USER:-${USER}}" "${SELKIES_BASIC_AUTH_PASSWORD:-${PASSWD}}"; fi
  40. echo "# Selkies-GStreamer NGINX Configuration
  41. server {
  42. access_log /dev/stdout;
  43. error_log /dev/stderr;
  44. listen 8080 $(if [ \"$(echo ${SELKIES_ENABLE_HTTPS} | tr '[:upper:]' '[:lower:]')\" = \"true\" ]; then echo -n "ssl"; fi);
  45. listen [::]:8080 $(if [ \"$(echo ${SELKIES_ENABLE_HTTPS} | tr '[:upper:]' '[:lower:]')\" = \"true\" ]; then echo -n "ssl"; fi);
  46. ssl_certificate ${SELKIES_HTTPS_CERT-/etc/ssl/certs/ssl-cert-snakeoil.pem};
  47. ssl_certificate_key ${SELKIES_HTTPS_KEY-/etc/ssl/private/ssl-cert-snakeoil.key};
  48. $(if [ \"$(echo ${SELKIES_ENABLE_BASIC_AUTH} | tr '[:upper:]' '[:lower:]')\" != \"false\" ]; then echo "auth_basic \"Selkies\";"; echo -n " auth_basic_user_file ${XDG_RUNTIME_DIR}/.htpasswd;"; fi)
  49. location / {
  50. root /opt/gst-web/;
  51. index index.html index.htm;
  52. }
  53. location /health {
  54. proxy_http_version 1.1;
  55. proxy_read_timeout 3600s;
  56. proxy_send_timeout 3600s;
  57. proxy_connect_timeout 3600s;
  58. proxy_buffering off;
  59. client_max_body_size 10M;
  60. proxy_pass http$(if [ \"$(echo ${SELKIES_ENABLE_HTTPS} | tr '[:upper:]' '[:lower:]')\" = \"true\" ]; then echo -n "s"; fi)://localhost:8081;
  61. }
  62. location /turn {
  63. proxy_http_version 1.1;
  64. proxy_read_timeout 3600s;
  65. proxy_send_timeout 3600s;
  66. proxy_connect_timeout 3600s;
  67. proxy_buffering off;
  68. client_max_body_size 10M;
  69. proxy_pass http$(if [ \"$(echo ${SELKIES_ENABLE_HTTPS} | tr '[:upper:]' '[:lower:]')\" = \"true\" ]; then echo -n "s"; fi)://localhost:8081;
  70. }
  71. location /ws {
  72. proxy_set_header Upgrade \$http_upgrade;
  73. proxy_set_header Connection \"upgrade\";
  74. proxy_set_header Host \$host;
  75. proxy_set_header X-Real-IP \$remote_addr;
  76. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  77. proxy_set_header X-Forwarded-Proto \$scheme;
  78. proxy_http_version 1.1;
  79. proxy_read_timeout 3600s;
  80. proxy_send_timeout 3600s;
  81. proxy_connect_timeout 3600s;
  82. proxy_buffering off;
  83. client_max_body_size 10M;
  84. proxy_pass http$(if [ \"$(echo ${SELKIES_ENABLE_HTTPS} | tr '[:upper:]' '[:lower:]')\" = \"true\" ]; then echo -n "s"; fi)://localhost:8081;
  85. }
  86. location /webrtc/signalling {
  87. proxy_set_header Upgrade \$http_upgrade;
  88. proxy_set_header Connection \"upgrade\";
  89. proxy_set_header Host \$host;
  90. proxy_set_header X-Real-IP \$remote_addr;
  91. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  92. proxy_set_header X-Forwarded-Proto \$scheme;
  93. proxy_http_version 1.1;
  94. proxy_read_timeout 3600s;
  95. proxy_send_timeout 3600s;
  96. proxy_connect_timeout 3600s;
  97. proxy_buffering off;
  98. client_max_body_size 10M;
  99. proxy_pass http$(if [ \"$(echo ${SELKIES_ENABLE_HTTPS} | tr '[:upper:]' '[:lower:]')\" = \"true\" ]; then echo -n "s"; fi)://localhost:8081;
  100. }
  101. location /metrics {
  102. proxy_http_version 1.1;
  103. proxy_read_timeout 3600s;
  104. proxy_send_timeout 3600s;
  105. proxy_connect_timeout 3600s;
  106. proxy_buffering off;
  107. client_max_body_size 10M;
  108. proxy_pass http$(if [ \"$(echo ${SELKIES_ENABLE_HTTPS} | tr '[:upper:]' '[:lower:]')\" = \"true\" ]; then echo -n "s"; fi)://localhost:9081;
  109. }
  110. error_page 500 502 503 504 /50x.html;
  111. location = /50x.html {
  112. root /opt/gst-web/;
  113. }
  114. }" | tee /etc/nginx/sites-available/default > /dev/null
  115. # Clear the cache registry
  116. rm -rf "${HOME}/.cache/gstreamer-1.0"
  117. # Start the Selkies-GStreamer WebRTC HTML5 remote desktop application
  118. selkies-gstreamer \
  119. --addr="localhost" \
  120. --port="8081" \
  121. --enable_basic_auth="false" \
  122. --enable_metrics_http="true" \
  123. --metrics_http_port="9081" \
  124. $@