Last active
June 13, 2026 19:40
-
-
Save jerilkuriakose/cd0f8353aac74e47c591111b758943e9 to your computer and use it in GitHub Desktop.
setup-openclaw.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # | |
| # setup-openclaw.sh — minimal OpenClaw gateway bring-up | |
| # Companion to "Coding Agents over Telegram, Part 2: From Zero to an Agent That Answers". | |
| # | |
| # What it does: pins the runtime, fetches + builds OpenClaw, writes a minimal config | |
| # (only if you pass a bot token), and launches the gateway. It does NOT configure your | |
| # Telegram group/topic or your agent — do those from the post. | |
| # | |
| # Usage: | |
| # # 1) just install + build + launch the gateway: | |
| # ./setup-openclaw.sh | |
| # | |
| # # 2) one-shot: also write a minimal config and start polling your bot: | |
| # OPENCLAW_BOT_TOKEN="123:abc" OPENCLAW_BOT_ACCOUNT="my-bot" ./setup-openclaw.sh | |
| # | |
| # Tunables (env vars, with defaults): | |
| # NODE_VERSION pinned Node (default 24.11.1) | |
| # PNPM_VERSION pinned pnpm (default 11.2.2) | |
| # OPENCLAW_DIR checkout location (default ~/repos/openclaw) | |
| # OPENCLAW_REF optional commit/tag to pin for reproducibility (e.g. v2026.5.27) | |
| # | |
| # NOTE: This follows OpenClaw's documented flow at the time of writing. If the upstream | |
| # build/launch scripts change, check https://github.com/openclaw/openclaw README first. | |
| set -euo pipefail | |
| NODE_VERSION="${NODE_VERSION:-24.11.1}" | |
| PNPM_VERSION="${PNPM_VERSION:-11.2.2}" | |
| OPENCLAW_REPO="https://github.com/openclaw/openclaw.git" | |
| OPENCLAW_DIR="${OPENCLAW_DIR:-$HOME/repos/openclaw}" | |
| OPENCLAW_REF="${OPENCLAW_REF:-}" | |
| CONFIG="$HOME/.openclaw/openclaw.json" | |
| log() { printf '\n\033[1;34m==>\033[0m %s\n' "$*"; } | |
| die() { printf '\n\033[1;31mERROR:\033[0m %s\n' "$*" >&2; exit 1; } | |
| # --- 1. Node via nvm --------------------------------------------------------- | |
| log "Selecting Node $NODE_VERSION via nvm" | |
| export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" | |
| # shellcheck disable=SC1091 | |
| [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" || die "nvm not found at $NVM_DIR — install it first: https://github.com/nvm-sh/nvm" | |
| nvm install "$NODE_VERSION" | |
| nvm use "$NODE_VERSION" | |
| # --- 2. pnpm via corepack ---------------------------------------------------- | |
| log "Activating pnpm $PNPM_VERSION via corepack" | |
| corepack enable | |
| corepack prepare "pnpm@$PNPM_VERSION" --activate | |
| # --- 3. OpenClaw checkout ---------------------------------------------------- | |
| if [ ! -d "$OPENCLAW_DIR/.git" ]; then | |
| log "Cloning OpenClaw into $OPENCLAW_DIR" | |
| git clone "$OPENCLAW_REPO" "$OPENCLAW_DIR" | |
| fi | |
| cd "$OPENCLAW_DIR" | |
| if [ -n "$OPENCLAW_REF" ]; then | |
| log "Pinning to $OPENCLAW_REF" | |
| git fetch --tags --quiet | |
| git checkout "$OPENCLAW_REF" | |
| fi | |
| log "OpenClaw at $(git rev-parse --short HEAD)" | |
| # --- 4. install + build ------------------------------------------------------ | |
| log "Installing dependencies" | |
| pnpm install --frozen-lockfile || pnpm install | |
| log "Building (this can take a few minutes)" | |
| pnpm build | |
| # --- 5. optional minimal config --------------------------------------------- | |
| if [ ! -f "$CONFIG" ] && [ -n "${OPENCLAW_BOT_TOKEN:-}" ]; then | |
| acct="${OPENCLAW_BOT_ACCOUNT:-my-bot}" | |
| log "Writing minimal config to $CONFIG (account: $acct)" | |
| mkdir -p "$(dirname "$CONFIG")" | |
| cat > "$CONFIG" <<JSON | |
| { | |
| "channels": { | |
| "telegram": { | |
| "enabled": true, | |
| "accounts": { | |
| "$acct": { | |
| "botToken": "$OPENCLAW_BOT_TOKEN" | |
| } | |
| } | |
| } | |
| } | |
| } | |
| JSON | |
| chmod 600 "$CONFIG" | |
| python3 -c "import json; json.load(open('$CONFIG'))" || die "generated config is not valid JSON" | |
| elif [ ! -f "$CONFIG" ]; then | |
| log "No config yet — create $CONFIG with your bot token before the gateway can poll (see the post)." | |
| fi | |
| # --- 6. launch the gateway (self-manages its own tmux session) -------------- | |
| log "Launching the gateway (pnpm gateway:watch)" | |
| pnpm gateway:watch | |
| log "Gateway started. Now do the Telegram + config steps in Part 2, then run ./ready-check.sh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment