File size: 1,906 Bytes
ac2af53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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