#!/usr/bin/env bash set -euo pipefail export PROXY_PORT="${PROXY_PORT:-7860}" export OPENCLAW_PORT="${OPENCLAW_PORT:-8080}" export PORT="${OPENCLAW_PORT}" export HOST="0.0.0.0" export OPENCLAW_HOST="0.0.0.0" export OPENCLAW_PORT 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}}" 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}" cat > /root/.openclaw/openclaw.json < {api_root!r}') else: print(f'Telegram apiRoot already set to {api_root}') path.write_text(json.dumps(data, indent=2) + '\n') PY /app/sync-root-data.sh reconcile /app/sync-root-data.sh loop & run_openclaw() { while true; do echo "Starting OpenClaw on 127.0.0.1:${OPENCLAW_PORT}..." if [ -n "${OPENCLAW_CMD:-}" ]; then sh -lc "$OPENCLAW_CMD" else openclaw gateway --port "${OPENCLAW_PORT}" --allow-unconfigured fi echo "OpenClaw exited; restarting in 2 seconds..." sleep 2 done } run_nginx() { while true; do envsubst '${PROXY_PORT} ${OPENCLAW_PORT}' < /app/nginx.conf.template > /tmp/nginx.conf nginx -c /tmp/nginx.conf -g 'daemon off;' echo "Nginx exited; restarting in 2 seconds..." sleep 2 done } run_openclaw & run_nginx & wait -n exit 1