OpenClaw-Setup/openclaw-setup-copilot/setup/setup_openclaw_copilot.sh

108 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
log_info() { echo -e "${GREEN}$*${NC}"; }
log_warn() { echo -e "${YELLOW}$*${NC}"; }
log_err() { echo -e "${RED}$*${NC}"; }
require_cmd() {
local cmd="$1"
if ! command -v "$cmd" >/dev/null 2>&1; then
log_err "ERROR: Missing required command: $cmd"
exit 1
fi
}
node_major_version() {
node -v 2>/dev/null | sed 's/^v//' | cut -d. -f1
}
echo -e "${GREEN}=== OpenClaw + GitHub Copilot CLI Setup ===${NC}"
echo "Current time: $(date)"
echo ""
require_cmd curl
# Step 1: Install / verify Node.js >= 22
need_node_install=false
if ! command -v node >/dev/null 2>&1; then
need_node_install=true
else
node_major="$(node_major_version || true)"
if ! echo "$node_major" | grep -Eq '^[0-9]+$' || [ "$node_major" -lt 22 ]; then
need_node_install=true
fi
fi
if [ "$need_node_install" = true ]; then
log_warn "Node.js >= 22 not found. Installing via Homebrew..."
if ! command -v brew >/dev/null 2>&1; then
log_err "Homebrew not found. Install it first:"
echo '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
exit 1
fi
brew install node
fi
log_info "Node.js ready ($(node -v))."
# Step 2: Install / verify OpenClaw
if ! command -v openclaw >/dev/null 2>&1; then
log_warn "OpenClaw not found. Installing via npm..."
require_cmd npm
npm install -g openclaw
else
log_info "OpenClaw already installed ($(openclaw --version))."
fi
# Step 3: Install / verify GitHub Copilot CLI
if ! command -v copilot >/dev/null 2>&1; then
if command -v brew >/dev/null 2>&1; then
log_warn "Copilot CLI not found. Installing prerelease via Homebrew..."
brew install copilot-cli@prerelease || {
log_warn "Homebrew install failed, falling back to npm package..."
npm install -g @github/copilot-cli
}
else
log_warn "Homebrew not found. Installing Copilot CLI via npm..."
npm install -g @github/copilot-cli
fi
else
log_info "Copilot CLI already installed ($(copilot --version 2>/dev/null || echo present))."
fi
FINALIZE_SCRIPT="$SCRIPT_DIR/../scripts/finalize_copilot_setup.sh"
if [[ -x "$FINALIZE_SCRIPT" ]]; then
if copilot auth status >/dev/null 2>&1; then
log_info "Copilot auth already active. Running finalize flow now..."
if ! bash "$FINALIZE_SCRIPT"; then
log_warn "Finalize flow failed. Re-run manually after checking auth/models:"
echo " bash ./scripts/finalize_copilot_setup.sh"
fi
else
log_warn "Final setup step still needed after login:"
echo " bash ./scripts/finalize_copilot_setup.sh"
fi
fi
echo ""
log_info "Setup complete (Copilot-first)."
echo ""
echo "Next steps (target machine):"
echo "1. Run one-command finalize (recommended):"
echo " bash ./scripts/finalize_copilot_setup.sh"
echo "2. If finalize cannot open browser login, authenticate first:"
echo " copilot auth login"
echo " copilot auth status"
echo " bash ./scripts/finalize_copilot_setup.sh"
echo "3. Verify:"
echo " openclaw status --deep"
echo " openclaw models status"