#!/usr/bin/env bash set -euo pipefail mkdir -p "${CLAWDBOT_STATE_DIR:-/data}" # Moltbot looks at ~/.clawdbot for config in many setups. # Point HOME into /data so config survives restarts when HF persistent storage is enabled. export HOME="${CLAWDBOT_STATE_DIR:-/data}" mkdir -p "$HOME" CONFIG_FILE="$HOME/.clawdbot/moltbot.json" # Spaces are non-interactive. We only auto-run onboard if: # 1) no config exists yet, and # 2) we have a supported API key in env if [[ ! -f "$CONFIG_FILE" ]]; then echo "[moltbot] No config found at $CONFIG_FILE" # Gateway token is required for non-loopback binds (LAN / 0.0.0.0) if [[ -z "${CLAWDBOT_GATEWAY_TOKEN:-}" ]]; then echo "[moltbot] ERROR: Missing CLAWDBOT_GATEWAY_TOKEN (set it as a HF Secret)." exit 1 fi # Pick an auth choice based on available env vars if [[ -n "${ANTHROPIC_API_KEY:-}" ]]; then echo "[moltbot] Running non-interactive onboard (Anthropic)…" clawdbot onboard --non-interactive \ --mode local \ --auth-choice apiKey \ --anthropic-api-key "$ANTHROPIC_API_KEY" \ --gateway-port "${CLAWDBOT_GATEWAY_PORT:-7860}" \ --gateway-bind lan \ --skip-skills elif [[ -n "${GEMINI_API_KEY:-}" ]]; then echo "[moltbot] Running non-interactive onboard (Gemini)…" clawdbot onboard --non-interactive \ --mode local \ --auth-choice gemini-api-key \ --gemini-api-key "$GEMINI_API_KEY" \ --gateway-port "${CLAWDBOT_GATEWAY_PORT:-7860}" \ --gateway-bind lan \ --skip-skills else echo "[moltbot] ERROR: No supported model API key found." echo "Set one of these HF Secrets: ANTHROPIC_API_KEY or GEMINI_API_KEY" exit 1 fi else echo "[moltbot] Config found at $CONFIG_FILE (skipping onboard)" fi echo "[moltbot] Starting gateway on :${CLAWDBOT_GATEWAY_PORT:-7860} (bind: lan)" # --allow-unconfigured helps avoid hard-fail if config is partial; useful in container environments. # bind "lan" = 0.0.0.0 so HF proxy can reach it. clawdbot gateway --allow-unconfigured --port "${CLAWDBOT_GATEWAY_PORT:-7860}" --bind lan