#!/bin/sh set -eu : "${BROWSER_USERNAME:?Set BROWSER_USERNAME as a Hugging Face Space Secret}" : "${BROWSER_PASSWORD:?Set BROWSER_PASSWORD as a Hugging Face Space Secret}" case "${BROWSER_WIDTH:-1920}" in ''|*[!0-9]*) echo "BROWSER_WIDTH must be numeric" >&2; exit 64 ;; esac case "${BROWSER_HEIGHT:-1080}" in ''|*[!0-9]*) echo "BROWSER_HEIGHT must be numeric" >&2; exit 64 ;; esac if [ "${BROWSER_WIDTH}" -lt 640 ] || [ "${BROWSER_WIDTH}" -gt 3840 ]; then echo "BROWSER_WIDTH must be between 640 and 3840" >&2 exit 64 fi if [ "${BROWSER_HEIGHT}" -lt 640 ] || [ "${BROWSER_HEIGHT}" -gt 2160 ]; then echo "BROWSER_HEIGHT must be between 640 and 2160" >&2 exit 64 fi # Use paid Hugging Face persistent storage when /data is writable; otherwise # fall back to ephemeral container storage and warn clearly. if [ -d /data ] && [ -w /data ]; then BROWSER_PROFILE=/data/manual-browser/chromium-profile mkdir -p /data/manual-browser "$BROWSER_PROFILE" chmod 700 /data/manual-browser "$BROWSER_PROFILE" 2>/dev/null || true echo "Browser profile: persistent /data/manual-browser/chromium-profile" else BROWSER_PROFILE=/home/user/browser-data/chromium-profile mkdir -p "$BROWSER_PROFILE" chmod 700 "$BROWSER_PROFILE" echo "WARNING: /data is unavailable; browser profile is ephemeral." fi export BROWSER_PROFILE export START_URL="${START_URL:-https://arena.ai/text/direct}" export XDG_RUNTIME_DIR=/tmp/runtime-user mkdir -p "$XDG_RUNTIME_DIR" chmod 700 "$XDG_RUNTIME_DIR" # Read the password through stdin so it is not exposed in the htpasswd process argv. printf '%s\n' "$BROWSER_PASSWORD" | htpasswd -iBc /home/user/.browser.htpasswd "$BROWSER_USERNAME" >/dev/null chmod 600 /home/user/.browser.htpasswd # Do not pass credentials to Chromium, noVNC, or other child processes. unset BROWSER_PASSWORD BROWSER_USERNAME exec /usr/bin/supervisord -n -c /home/user/app/supervisord.conf