#!/bin/bash # ══════════════════════════════════════════════════ # THE Z AI — Computer Mode Startup (FIXED v4) # ══════════════════════════════════════════════════ echo "🖥️ Starting Z Computer Mode Server v4..." # ── 1. Start Virtual Display ───────────────────── pkill Xvfb 2>/dev/null || true sleep 0.5 Xvfb :1 -screen 0 1920x1080x24 -ac +extension GLX +render -noreset & XVFB_PID=$! echo "✅ Xvfb started (PID: $XVFB_PID)" sleep 2 # ── 2. Export DISPLAY ───────────────────────────── export DISPLAY=:1 export XAUTHORITY=/root/.Xauthority # إنشاء ملف xauthority بطريقة آمنة touch $XAUTHORITY MCOOKIE_VAL=$(mcookie 2>/dev/null || cat /proc/sys/kernel/random/uuid | tr -d '-' | head -c 32) xauth add :1 . $MCOOKIE_VAL 2>/dev/null || true echo "✅ DISPLAY=$DISPLAY" # ── 3. Dark background ──────────────────────────── xsetroot -solid "#0d0d0d" 2>/dev/null || true # ── 4. Start Fluxbox WM ─────────────────────────── pkill fluxbox 2>/dev/null || true fluxbox & FLUX_PID=$! echo "✅ Fluxbox started (PID: $FLUX_PID)" sleep 2 # ── 5. Verify display works ─────────────────────── echo "🔍 Testing display..." if xdotool getdisplaygeometry 2>/dev/null; then echo "✅ Display working!" else echo "⚠️ xdotool test failed — continuing anyway" fi # ── 6. Test screenshot ──────────────────────────── scrot -q 80 /tmp/test_shot.png 2>/dev/null && \ echo "✅ Screenshot test: OK" || \ echo "⚠️ scrot test failed" # ── 7. Detect browser (firefox-esr أولاً) ───────── if command -v firefox-esr &>/dev/null; then echo "✅ Browser: firefox-esr" BROWSER="firefox-esr" elif command -v firefox &>/dev/null; then echo "✅ Browser: firefox" BROWSER="firefox" elif command -v chromium-browser &>/dev/null; then echo "✅ Browser: chromium-browser" BROWSER="chromium-browser" else echo "⚠️ No browser found" BROWSER="" fi # Export browser name so app.py can use it export DEFAULT_BROWSER="$BROWSER" echo "🚀 Starting Python API on port ${PORT:-7860}..." cd /app exec python3 app.py