#!/bin/sh set -eu # Ephemeral container: /data is typically tmpfs; never require a host mount. DATA_DIR="${PTS_DATA_DIR:-/data}" mkdir -p "$DATA_DIR" # Empty local files only inside the container (discarded when container is removed). if [ ! -f "$DATA_DIR/.env" ]; then touch "$DATA_DIR/.env" fi if [ ! -f "$DATA_DIR/dates.txt" ]; then touch "$DATA_DIR/dates.txt" fi # Virtual display + noVNC so Teams MFA can be completed interactively in Docker. # Chromium runs headed on DISPLAY; user opens :6080 in browser to click/type. DISPLAY_NUM="${DISPLAY#:}" DISPLAY_NUM="${DISPLAY_NUM:-99}" export DISPLAY=":${DISPLAY_NUM}" VNC_PORT="${TEAMS_VNC_PORT:-6080}" RFB_PORT="${TEAMS_RFB_PORT:-5900}" NOVNC_WEB="" for d in /usr/share/novnc /usr/share/novnc/web /usr/share/webapps/novnc; do if [ -d "$d" ] && { [ -f "$d/vnc.html" ] || [ -f "$d/vnc_lite.html" ]; }; then NOVNC_WEB="$d" break fi done if [ -z "$NOVNC_WEB" ] && [ -d /usr/share/novnc ]; then NOVNC_WEB=/usr/share/novnc fi start_vnc_stack() { if ! command -v Xvfb >/dev/null 2>&1; then echo "WARN: Xvfb not installed — Teams MFA interactive view unavailable" return 0 fi # Already running (container restart of app only) if [ -S "/tmp/.X11-unix/X${DISPLAY_NUM}" ] 2>/dev/null || \ pgrep -x Xvfb >/dev/null 2>&1; then : else echo "==> Xvfb ${DISPLAY} (Teams MFA virtual display)" Xvfb "${DISPLAY}" -screen 0 1400x900x24 -ac +extension RANDR -nolisten tcp >/tmp/xvfb.log 2>&1 & sleep 0.5 fi if command -v fluxbox >/dev/null 2>&1; then if ! pgrep -x fluxbox >/dev/null 2>&1; then fluxbox >/tmp/fluxbox.log 2>&1 & fi fi if command -v x11vnc >/dev/null 2>&1; then if ! pgrep -x x11vnc >/dev/null 2>&1; then echo "==> x11vnc :${RFB_PORT}" x11vnc -display "${DISPLAY}" -forever -shared -rfbport "${RFB_PORT}" \ -nopw -xkb -listen 0.0.0.0 -ncache 10 -ncache_cr \ >/tmp/x11vnc.log 2>&1 & sleep 0.3 fi fi if command -v websockify >/dev/null 2>&1; then if ! pgrep -f "websockify.*${VNC_PORT}" >/dev/null 2>&1; then echo "==> noVNC http://0.0.0.0:${VNC_PORT}/ (interactive Chrome for MFA)" if [ -n "$NOVNC_WEB" ]; then websockify --web="${NOVNC_WEB}" "${VNC_PORT}" "localhost:${RFB_PORT}" \ >/tmp/websockify.log 2>&1 & else websockify "${VNC_PORT}" "localhost:${RFB_PORT}" >/tmp/websockify.log 2>&1 & fi fi fi } start_vnc_stack exec "$@"