#!/usr/bin/env bash set -euo pipefail export PROXY_PORT="${PROXY_PORT:-7860}" export OPENCLAW_PORT="${OPENCLAW_PORT:-8080}" export CODE_PORT="${CODE_PORT:-8888}" export PORT="${OPENCLAW_PORT}" export HOST="0.0.0.0" export OPENCLAW_HOST="0.0.0.0" export OPENCLAW_PORT export OPENCLAW_GATEWAY_PASSWORD="${OPENCLAW_GATEWAY_PASSWORD:-773322}" export SYNC_INTERVAL="${SYNC_INTERVAL:-300}" export PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-/ms-playwright}" export TELEGRAM_API_ROOT="${TELEGRAM_API_ROOT:-https://tg-relay.markdevil11.workers.dev}" export OPENCLAW_TELEGRAM_API_ROOT="${OPENCLAW_TELEGRAM_API_ROOT:-${TELEGRAM_API_ROOT}}" export SPACE_URL="${SPACE_URL:-https://elysiadev11-openclaw.hf.space}" export TELEGRAM_BOT_TOKEN="${TELEGRAM_BOT_TOKEN:-}" export TELEGRAM_ALLOW_ID="${TELEGRAM_ALLOW_ID:-0}" configure_dns() { if [ -w /etc/resolv.conf ]; then cat > /etc/resolv.conf <<'EOF' nameserver 1.1.1.1 nameserver 1.0.0.1 nameserver 8.8.8.8 nameserver 8.8.4.4 options timeout:2 attempts:3 rotate EOF echo "DNS configured with Cloudflare and Google resolvers." else echo "WARN: /etc/resolv.conf is not writable; keeping existing DNS." fi } mkdir -p /root/workspace configure_dns /app/sync-root-data.sh restore mkdir -p /root/.openclaw generate_openclaw_config() { local clean_base clean_base="$(printf '%s' "${OPENAI_API_BASE:-}" | sed 's|/chat/completions||g' | sed 's|/v1/|/v1|g' | sed 's|/v1$|/v1|g')" local allow_id allow_id="${TELEGRAM_ALLOW_ID:-0}" local primary_model="kilo_gateway/kilo-auto/free" local nvidia_provider="" if [ -n "$clean_base" ] && [ -n "${OPENAI_API_KEY:-}" ]; then primary_model="nvidia/${MODEL:-gpt-5.5}" nvidia_provider=', "nvidia": { "baseUrl": "'"${clean_base}"'", "apiKey": "'"${OPENAI_API_KEY:-}"'", "api": "openai-completions", "models": [ { "id": "'"${MODEL:-gpt-5.5}"'", "name": "'"${MODEL:-gpt-5.5}"'", "contextWindow": 128000 }, { "id": "'"${VISION_MODEL:-${MODEL:-gpt-5.5}}"'", "name": "Nvidia Vision", "contextWindow": 128000, "input": ["text", "image"] } ] }' fi cat > /root/.openclaw/openclaw.json < {api_root!r}') else: print(f'Telegram apiRoot already set to {api_root}') print(f'Telegram webhookUrl set to {telegram.get("webhookUrl")}') path.write_text(json.dumps(data, indent=2) + '\n') PY /app/sync-root-data.sh reconcile /app/sync-root-data.sh loop & # ── code-server (VS Code) ───────────────────────────────────────────────────── run_code_server() { mkdir -p /root/.config/code-server cat > /root/.config/code-server/config.yaml < /tmp/nginx.conf nginx -c /tmp/nginx.conf -g 'daemon off;' echo "Nginx exited; restarting in 2 seconds..." sleep 2 done } run_simple_webhook() { while true; do echo "Starting simple webhook server on port 8787..." python3 /app/webhook_server.py & WEBHOOK_PID=$! echo "Simple webhook server started with PID: $WEBHOOK_PID" wait $WEBHOOK_PID echo "Webhook server exited; restarting in 2 seconds..." sleep 2 done } run_openclaw & run_code_server & run_nginx & # Wait for services to start echo "Waiting for services to start..." sleep 10 # Check webhook port echo "Checking webhook port 8787..." if command -v ss &> /dev/null && ss -tuln 2>/dev/null | grep -q ":8787"; then echo "Webhook server is listening on port 8787" curl -s -o /dev/null -w "Webhook test status: %{http_code}\n" http://localhost:8787/tg-webhook || true elif curl -s http://0.0.0.0:8787/tg-webhook &>/dev/null; then echo "Webhook server is accessible on port 8787" else echo "WARNING: Webhook server is NOT listening on port 8787 — starting fallback..." run_simple_webhook & fi # Check OpenClaw port echo "Checking OpenClaw port ${OPENCLAW_PORT}..." if command -v ss &> /dev/null && ss -tuln 2>/dev/null | grep -q ":${OPENCLAW_PORT}"; then echo "OpenClaw is listening on port ${OPENCLAW_PORT}" elif curl -s http://127.0.0.1:${OPENCLAW_PORT}/health &>/dev/null; then echo "OpenClaw is accessible on port ${OPENCLAW_PORT}" else echo "WARNING: OpenClaw is NOT listening on port ${OPENCLAW_PORT}" fi # Check code-server port echo "Checking code-server port ${CODE_PORT}..." if command -v ss &> /dev/null && ss -tuln 2>/dev/null | grep -q ":${CODE_PORT}"; then echo "code-server is listening on port ${CODE_PORT}" else echo "WARNING: code-server is NOT listening on port ${CODE_PORT}" fi wait -n exit 1