cynarAI 6c7eed7580 Initial clean evOo-local from f00577b
Fresh history cut from cynarAI/evoo antigravity-handoff/project-timeline
(Voice First + project timeline). Brand docs/titles as evOo; keep @rakazo/*
packages as tech debt. Excludes node_modules, caches, secrets, voice blobs.
2026-09-20 17:15:16 +02:00

111 lines
3.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -uo pipefail
export DISPLAY="${DISPLAY:-:1}"
export HOME="${HOME:-/home/rakazo}"
AGENT_HOME="$HOME"
mkdir -p "$AGENT_HOME" "$AGENT_HOME/.local/bin" "$AGENT_HOME/.config" /tmp/rakazo /tmp/.X11-unix /tmp/fluxbox-home
export PATH="$AGENT_HOME/.local/bin:/usr/local/bin:$PATH"
export NPM_CONFIG_PREFIX="$AGENT_HOME/.local"
export PIP_USER=1
cd "$AGENT_HOME"
# This script is PID 1. Without a handler, PID 1 ignores SIGTERM and `docker stop` waits its
# full grace period before killing the container, so every stop, sleep and computer switch
# took ten seconds. Install the handler before any child starts so a stop during startup is
# honoured too: forward the signal to the desktop processes and exit promptly.
XVFB_PID=""
shutdown() {
trap - TERM INT
if [[ -n "$XVFB_PID" ]]; then
kill -TERM "$XVFB_PID" 2>/dev/null || true
fi
kill -TERM -- -1 2>/dev/null || true
if [[ -n "$XVFB_PID" ]]; then
wait "$XVFB_PID" 2>/dev/null || true
fi
exit 0
}
trap shutdown TERM INT
if [[ -n "${RAKAZO_COMPUTER_CONTROL_TOKEN:-}" ]]; then
/usr/local/bin/rakazo-computer-control >/tmp/rakazo/control.log 2>&1 &
fi
rm -f /tmp/.X1-lock /tmp/.X11-unix/X1
Xvfb :1 -screen 0 1280x800x24 -ac +extension RANDR +render -noreset >/tmp/rakazo/xvfb.log 2>&1 &
XVFB_PID=$!
ready=0
for _ in $(seq 1 100); do
if xdpyinfo -display :1 >/dev/null 2>&1; then
ready=1
break
fi
sleep 0.1
done
if [[ "$ready" -ne 1 ]]; then
echo "Xvfb failed to start" >&2
cat /tmp/rakazo/xvfb.log >&2 || true
exit 1
fi
if command -v dbus-launch >/dev/null 2>&1; then
eval "$(dbus-launch --sh-syntax)"
fi
xsetroot -solid "#111113" >/dev/null 2>&1 || true
mkdir -p /tmp/fluxbox-home/.fluxbox
cp /etc/rakazo/fluxbox/init /tmp/fluxbox-home/.fluxbox/init
cp /etc/rakazo/fluxbox/apps /tmp/fluxbox-home/.fluxbox/apps 2>/dev/null || true
cp /etc/rakazo/fluxbox/menu /tmp/fluxbox-home/.fluxbox/menu 2>/dev/null || true
cat > /tmp/fluxbox-home/.fluxbox/startup <<'EOF'
#!/bin/sh
xsetroot -solid "#111113"
exec fluxbox -rc /tmp/fluxbox-home/.fluxbox/init
EOF
chmod +x /tmp/fluxbox-home/.fluxbox/startup
HOME=/tmp/fluxbox-home /tmp/fluxbox-home/.fluxbox/startup >/tmp/rakazo/fluxbox.log 2>&1 &
register_browser_handler() {
local mime="$1"
if ! xdg-mime default rakazo-browser.desktop "$mime" >/dev/null 2>&1 \
|| [[ "$(xdg-mime query default "$mime" 2>/dev/null || true)" != "rakazo-browser.desktop" ]]; then
echo "failed to register rakazo-browser for $mime" >&2
exit 1
fi
}
register_browser_handler x-scheme-handler/http
register_browser_handler x-scheme-handler/https
register_browser_handler text/html
if ! xdg-settings set default-web-browser rakazo-browser.desktop >/dev/null 2>&1 \
|| [[ "$(xdg-settings get default-web-browser 2>/dev/null || true)" != "rakazo-browser.desktop" ]]; then
echo "failed to set default web browser to rakazo-browser" >&2
exit 1
fi
x11vnc -display :1 -forever -shared -viewonly -nopw -listen 127.0.0.1 -rfbport 5900 -xkb -ncache 0 >/tmp/rakazo/x11vnc.log 2>&1 &
NOVNC_ROOT=/usr/share/novnc
if [[ ! -d "$NOVNC_ROOT" ]]; then
echo "noVNC is missing from the computer image" >&2
exit 1
fi
if [[ ! -f "$NOVNC_ROOT/embed.html" ]]; then
echo "noVNC embed.html is missing from the computer image" >&2
exit 1
fi
if [[ ! -f "$NOVNC_ROOT/clipboard-bridge.js" ]]; then
echo "noVNC clipboard-bridge.js is missing from the computer image" >&2
exit 1
fi
if [[ ! -f "$NOVNC_ROOT/mobile-keyboard.js" ]]; then
echo "noVNC mobile-keyboard.js is missing from the computer image" >&2
exit 1
fi
websockify --heartbeat=30 --web="$NOVNC_ROOT" --token-plugin=TokenFile --token-source=/tmp/rakazo/view-target-1 0.0.0.0:6080 >/tmp/rakazo/novnc.log 2>&1 &
wait "$XVFB_PID"
echo "Xvfb exited" >&2
exit 1