#!/bin/bash
# X server + VNC in one (Xvnc), the XFCE session on it, and noVNC's websocket bridge in front.
# VNC has no password: the container's port is published on 127.0.0.1 only (see sim/desktop.py).
set -u
export DISPLAY=:1 HOME=/home/candidate USER=candidate SHELL=/bin/bash
rm -f /tmp/.X1-lock /tmp/.X11-unix/X1
Xvnc :1 -geometry "${GEOMETRY:-1600x900}" -depth 24 -rfbport 5901 -localhost \
     -SecurityTypes None -AlwaysShared -desktop "${DESKTOP_NAME:-exam}" >/tmp/xvnc.log 2>&1 &
for _ in $(seq 50); do [ -S /tmp/.X11-unix/X1 ] && break; sleep 0.1; done
cd "$HOME"
dbus-launch --exit-with-session startxfce4 >/tmp/xfce.log 2>&1 &
exec websockify --web /usr/share/novnc 6080 127.0.0.1:5901
