rdesign/studio/start.sh

77 lines
2.0 KiB
Bash

#!/bin/bash
set -e
VNC_PASSWORD="${VNC_PASSWORD:-changeme}"
DISPLAY_WIDTH="${DISPLAY_WIDTH:-1920}"
DISPLAY_HEIGHT="${DISPLAY_HEIGHT:-1080}"
# TigerVNC on Ubuntu 24.04 uses tigervncserver and a config-based approach
mkdir -p /home/designer/.vnc
# Create VNC password using a Python one-liner (tigervnc has no standalone vncpasswd)
python3 -c "
import struct, hashlib, os
pw = '${VNC_PASSWORD}'[:8].ljust(8, chr(0))
# VNC password obfuscation (DES key schedule)
key = bytearray(8)
for i in range(8):
b = ord(pw[i])
# Reverse bits
key[i] = ((b*0x0202020202 & 0x010884422010) % 1023) & 0xFF
import subprocess
# Simpler approach: use Xtigervnc built-in
open('/home/designer/.vnc/passwd_raw', 'w').write(pw)
" 2>/dev/null || true
# Write VNC config for tigervncserver
cat > /home/designer/.vnc/config <<EOF
geometry=${DISPLAY_WIDTH}x${DISPLAY_HEIGHT}
depth=24
localhost=no
SecurityTypes=None
EOF
# Create xstartup
cat > /home/designer/.vnc/xstartup <<'EOF'
#!/bin/bash
export DISPLAY=:1
dbus-launch --exit-with-session openbox-session &
sleep 1
scribus &
EOF
chmod +x /home/designer/.vnc/xstartup
chown -R designer:designer /home/designer/.vnc
# Start Xtigervnc directly (simpler than tigervncserver for containers)
su - designer -c "Xtigervnc :1 \
-geometry ${DISPLAY_WIDTH}x${DISPLAY_HEIGHT} \
-depth 24 \
-rfbport 5901 \
-SecurityTypes None \
-AlwaysShared \
-AcceptKeyEvents \
-AcceptPointerEvents \
-SendCutText \
-AcceptCutText" &
sleep 2
# Start window manager and Scribus
export DISPLAY=:1
su - designer -c "export DISPLAY=:1 && dbus-launch openbox-session" &
sleep 1
su - designer -c "export DISPLAY=:1 && scribus" &
# Create index.html redirect for noVNC
cat > /usr/share/novnc/index.html <<'INDEXEOF'
<!DOCTYPE html>
<html><head><meta http-equiv="refresh" content="0;url=vnc.html?autoconnect=true&resize=scale&path=vnc/websockify"></head></html>
INDEXEOF
# Start noVNC (websockify bridge)
/usr/share/novnc/utils/novnc_proxy \
--vnc localhost:5901 \
--listen 6080 \
--web /usr/share/novnc