#!/usr/bin/env bash set -euo pipefail BASE="/home/ubuntu/.openclaw/workspace/preview-apps" RUN="$BASE/.run" mkdir -p "$BASE" "$RUN" trim_line() { tr '\r' '\n' | sed '/^[[:space:]]*$/d' | head -n 1 | cut -c1-120 } escape_html() { /home/linuxbrew/.linuxbrew/bin/python3 -c 'import html,sys; print(html.escape(sys.stdin.read()), end="")' } codex_tagline() { local out out="$(/home/linuxbrew/.linuxbrew/bin/codex exec --json --color never --sandbox read-only --skip-git-repo-check "Return only a short catchy tagline (max 8 words) for a demo website named codex-demo." 2>/dev/null || true)" printf '%s\n' "$out" | /usr/bin/jq -r 'select(.type=="item.completed" and .item.type=="agent_message") | .item.text' 2>/dev/null | trim_line } gemini_tagline() { /home/ubuntu/.local/bin/gemini-cli-openclaw "Return only a short catchy tagline (max 8 words) for a demo website named gemini-demo." 2>/dev/null | trim_line } deepseek_tagline() { /home/ubuntu/.local/bin/deepseek-code-openclaw "Return only a short catchy tagline (max 8 words) for a demo website named deepseek-demo." 2>/dev/null | trim_line } write_site() { local name="$1" local label="$2" local accent="$3" local tagline="$4" local dir="$BASE/$name" mkdir -p "$dir" local safe_tagline safe_tagline="$(printf '%s' "${tagline:-Built and deployed}" | escape_html)" cat >"$dir/index.html" < $label Demo
$label

$name

$safe_tagline

/preview/$name/
EOF } start_server() { local name="$1" local port="$2" local dir="$BASE/$name" local pidfile="$RUN/$name.pid" local logfile="$RUN/$name.log" if [ -f "$pidfile" ]; then local old_pid old_pid="$(cat "$pidfile" 2>/dev/null || true)" if [ -n "${old_pid:-}" ] && kill -0 "$old_pid" 2>/dev/null; then kill "$old_pid" 2>/dev/null || true sleep 1 fi fi nohup /home/linuxbrew/.linuxbrew/bin/python3 -m http.server "$port" --bind 127.0.0.1 --directory "$dir" >"$logfile" 2>&1 & echo $! >"$pidfile" } deploy_site() { local port="$1" local name="$2" /home/ubuntu/.local/bin/pipo-deploy "$port" "$name" >/dev/null } codex_result="$RUN/codex.tagline" gemini_result="$RUN/gemini.tagline" deepseek_result="$RUN/deepseek.tagline" ( codex_tagline >"$codex_result" ) & pid1=$! ( gemini_tagline >"$gemini_result" ) & pid2=$! ( deepseek_tagline >"$deepseek_result" ) & pid3=$! wait "$pid1" "$pid2" "$pid3" write_site "codex-demo" "Codex" "#38bdf8" "$(cat "$codex_result" 2>/dev/null || echo "Built with Codex")" write_site "gemini-demo" "Gemini" "#fbbf24" "$(cat "$gemini_result" 2>/dev/null || echo "Built with Gemini")" write_site "deepseek-demo" "DeepSeek" "#34d399" "$(cat "$deepseek_result" 2>/dev/null || echo "Built with DeepSeek")" start_server "codex-demo" 3001 start_server "gemini-demo" 3002 start_server "deepseek-demo" 3003 sleep 1 deploy_site 3001 codex-demo deploy_site 3002 gemini-demo deploy_site 3003 deepseek-demo printf '%s\n' \ "https://miopenclaw-vnic.tail9799d2.ts.net/preview/codex-demo/" \ "https://miopenclaw-vnic.tail9799d2.ts.net/preview/gemini-demo/" \ "https://miopenclaw-vnic.tail9799d2.ts.net/preview/deepseek-demo/"