diff --git a/openclaw-setup-copilot/README.md b/openclaw-setup-copilot/README.md index 0ed06a0..af10023 100644 --- a/openclaw-setup-copilot/README.md +++ b/openclaw-setup-copilot/README.md @@ -73,6 +73,21 @@ bash ./scripts/finalize_copilot_setup.sh openclaw status --deep ``` +Optional custom install locations: + +```bash +# Move OpenClaw runtime data (~/.openclaw) to another path +OPENCLAW_DATA_TARGET=/Volumes/Data/openclaw-copilot bash ./setup/setup_openclaw_copilot.sh + +# Install global npm CLIs into a custom prefix/bin +NPM_GLOBAL_PREFIX="$HOME/.npm-global" bash ./setup/setup_openclaw_copilot.sh + +# Use both +OPENCLAW_DATA_TARGET=/Volumes/Data/openclaw-copilot \ +NPM_GLOBAL_PREFIX="$HOME/.npm-global" \ +bash ./setup/setup_openclaw_copilot.sh +``` + Order and dependency (important): 1. `setup/setup_openclaw_copilot.sh` installs tooling only (`openclaw`, `copilot`, Node). @@ -91,6 +106,12 @@ Why: bash ./setup/setup_openclaw_copilot.sh ``` +If using a custom location: + +```bash +OPENCLAW_DATA_TARGET=/Volumes/Data/openclaw-copilot bash ./setup/setup_openclaw_copilot.sh +``` + 2. Finalize in one command (recommended): ```bash diff --git a/openclaw-setup-copilot/docs/context/TOOLS.md b/openclaw-setup-copilot/docs/context/TOOLS.md index e3a6aa0..cd8f234 100644 --- a/openclaw-setup-copilot/docs/context/TOOLS.md +++ b/openclaw-setup-copilot/docs/context/TOOLS.md @@ -8,6 +8,13 @@ Primary setup script: bash ./setup/setup_openclaw_copilot.sh ``` +Custom locations (optional): + +```bash +OPENCLAW_DATA_TARGET=/Volumes/Data/openclaw-copilot bash ./setup/setup_openclaw_copilot.sh +NPM_GLOBAL_PREFIX="$HOME/.npm-global" bash ./setup/setup_openclaw_copilot.sh +``` + Install: ```bash diff --git a/openclaw-setup-copilot/docs/operations/WORK_SETUP_CHECKLIST.md b/openclaw-setup-copilot/docs/operations/WORK_SETUP_CHECKLIST.md index ce32a31..a9146bf 100644 --- a/openclaw-setup-copilot/docs/operations/WORK_SETUP_CHECKLIST.md +++ b/openclaw-setup-copilot/docs/operations/WORK_SETUP_CHECKLIST.md @@ -28,6 +28,13 @@ which npm || echo "npm missing" bash ./setup/setup_openclaw_copilot.sh ``` +Optional custom locations: + +```bash +OPENCLAW_DATA_TARGET=/Volumes/Data/openclaw-copilot bash ./setup/setup_openclaw_copilot.sh +NPM_GLOBAL_PREFIX="$HOME/.npm-global" bash ./setup/setup_openclaw_copilot.sh +``` + Verify: ```bash diff --git a/openclaw-setup-copilot/setup/setup_openclaw_copilot.sh b/openclaw-setup-copilot/setup/setup_openclaw_copilot.sh index 582062b..5761e1d 100755 --- a/openclaw-setup-copilot/setup/setup_openclaw_copilot.sh +++ b/openclaw-setup-copilot/setup/setup_openclaw_copilot.sh @@ -2,6 +2,13 @@ set -euo pipefail +# Optional overrides: +# OPENCLAW_DATA_TARGET=/Volumes/Data/openclaw-copilot bash ./setup/setup_openclaw_copilot.sh +# NPM_GLOBAL_PREFIX="$HOME/.npm-global" bash ./setup/setup_openclaw_copilot.sh +# OPENCLAW_DATA_TARGET=/Volumes/Data/openclaw-copilot NPM_GLOBAL_PREFIX="$HOME/.npm-global" bash ./setup/setup_openclaw_copilot.sh +OPENCLAW_DATA_TARGET="${OPENCLAW_DATA_TARGET:-}" +NPM_GLOBAL_PREFIX="${NPM_GLOBAL_PREFIX:-}" + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" GREEN='\033[0;32m' @@ -25,8 +32,84 @@ node_major_version() { node -v 2>/dev/null | sed 's/^v//' | cut -d. -f1 } +expand_tilde() { + local p="$1" + if [[ "$p" == "~" ]]; then + echo "$HOME" + elif [[ "$p" == "~/"* ]]; then + echo "$HOME/${p#~/}" + else + echo "$p" + fi +} + +link_data_dir() { + local source="$1" + local target="$2" + local label="$3" + + mkdir -p "$target" + + if [ -L "$source" ]; then + local current_link + current_link="$(readlink "$source")" + if [ "$current_link" != "$target" ]; then + rm "$source" + ln -s "$target" "$source" + log_info "${label}: updated symlink ${source} -> ${target}" + else + log_info "${label}: symlink already correct (${source} -> ${target})" + fi + return 0 + fi + + if [ -d "$source" ]; then + log_warn "${label}: migrating existing ${source} data to ${target}..." + if command -v rsync >/dev/null 2>&1; then + rsync -a "$source"/ "$target"/ + else + cp -a "$source"/. "$target"/ + fi + rm -rf "$source" + elif [ -e "$source" ]; then + log_err "ERROR: ${source} exists but is not a directory/symlink. Resolve manually." + exit 1 + fi + + ln -s "$target" "$source" + log_info "${label}: symlink created ${source} -> ${target}" +} + +install_npm_global() { + local pkg="$1" + require_cmd npm + if [[ -n "$NPM_GLOBAL_PREFIX" ]]; then + mkdir -p "$NPM_GLOBAL_PREFIX" + npm install -g --prefix "$NPM_GLOBAL_PREFIX" "$pkg" + else + npm install -g "$pkg" + fi +} + +if [[ -n "$OPENCLAW_DATA_TARGET" ]]; then + OPENCLAW_DATA_TARGET="$(expand_tilde "$OPENCLAW_DATA_TARGET")" +fi +if [[ -n "$NPM_GLOBAL_PREFIX" ]]; then + NPM_GLOBAL_PREFIX="$(expand_tilde "$NPM_GLOBAL_PREFIX")" +fi + +if [[ -n "$NPM_GLOBAL_PREFIX" ]]; then + export PATH="$NPM_GLOBAL_PREFIX/bin:$PATH" +fi + echo -e "${GREEN}=== OpenClaw + GitHub Copilot CLI Setup ===${NC}" echo "Current time: $(date)" +if [[ -n "$OPENCLAW_DATA_TARGET" ]]; then + echo "OpenClaw data target: $OPENCLAW_DATA_TARGET" +fi +if [[ -n "$NPM_GLOBAL_PREFIX" ]]; then + echo "npm global prefix: $NPM_GLOBAL_PREFIX" +fi echo "" require_cmd curl @@ -57,7 +140,7 @@ log_info "Node.js ready ($(node -v))." if ! command -v openclaw >/dev/null 2>&1; then log_warn "OpenClaw not found. Installing via npm..." require_cmd npm - npm install -g openclaw + install_npm_global openclaw else log_info "OpenClaw already installed ($(openclaw --version))." fi @@ -68,16 +151,22 @@ if ! command -v copilot >/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 + install_npm_global @github/copilot-cli } else log_warn "Homebrew not found. Installing Copilot CLI via npm..." - npm install -g @github/copilot-cli + install_npm_global @github/copilot-cli fi else log_info "Copilot CLI already installed ($(copilot --version 2>/dev/null || echo present))." fi +if [[ -n "$OPENCLAW_DATA_TARGET" ]]; then + link_data_dir "$HOME/.openclaw" "$OPENCLAW_DATA_TARGET" "OpenClaw" +else + log_info "OpenClaw data location unchanged (~/.openclaw). Set OPENCLAW_DATA_TARGET to move it." +fi + FINALIZE_SCRIPT="$SCRIPT_DIR/../scripts/finalize_copilot_setup.sh" if [[ -x "$FINALIZE_SCRIPT" ]]; then if copilot auth status >/dev/null 2>&1; then @@ -105,3 +194,8 @@ echo " bash ./scripts/finalize_copilot_setup.sh" echo "3. Verify:" echo " openclaw status --deep" echo " openclaw models status" +if [[ -n "$NPM_GLOBAL_PREFIX" ]]; then + echo "" + echo "If this is a new shell, ensure PATH includes your npm prefix bin:" + echo " export PATH=\"$NPM_GLOBAL_PREFIX/bin:\$PATH\"" +fi