Files
u-claw/portable/advanced/setup.sh
zheng 08f22edf44
All checks were successful
Tests / test (push) Successful in 1m8s
fix(ci): align Node v22.22.3 pins and unblock pre-push tests
Sync install scripts and CI container image with NODE_VERSION, regenerate
Electron Config.html, and skip gitignored portable/app in origin scan.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-18 18:47:41 +08:00

197 lines
7.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ============================================================
# U-Claw Portable — 开发环境搭建脚本
# 用法: bash setup.sh
# 作用: 下载 Node.js 运行时 + Installing OpenClaw 到 app/ 目录
# ============================================================
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
APP_DIR="$SCRIPT_DIR/app"
CORE_DIR="$APP_DIR/core"
RUNTIME_DIR="$APP_DIR/runtime"
MIRROR="https://registry.npmjs.org"
NODE_MIRROR="https://nodejs.org/dist"
NODE_VERSION="$(tr -d "[:space:]" < "$SCRIPT_DIR/NODE_VERSION" 2>/dev/null || tr -d "[:space:]" < "$SCRIPT_DIR/../NODE_VERSION" 2>/dev/null || echo v22.22.3)"
ALL_PLATFORMS=false
[ "$1" = "--all-platforms" ] && ALL_PLATFORMS=true
GREEN='\033[0;32m'
CYAN='\033[0;36m'
RED='\033[0;31m'
NC='\033[0m'
echo ""
echo -e "${CYAN}╔══════════════════════════════════════╗${NC}"
echo -e "${CYAN}║ 🦞 U-Claw Portable Setup ║${NC}"
echo -e "${CYAN}╚══════════════════════════════════════╝${NC}"
echo ""
# ---- Detect OS & Arch ----
OS=$(uname -s)
ARCH=$(uname -m)
if [ "$OS" = "Darwin" ]; then
if [ "$ARCH" = "arm64" ]; then
PLATFORM="darwin-arm64"
NODE_DIR_NAME="node-mac-arm64"
else
PLATFORM="darwin-x64"
NODE_DIR_NAME="node-mac-x64"
fi
else
echo -e "${RED}Run this on a Mac. On Windows, use setup.bat instead.${NC}"
exit 1
fi
echo -e " System: ${GREEN}$OS $ARCH${NC}"
echo ""
# ---- 1. Download Node.js (Current Platform) ----
NODE_TARGET="$RUNTIME_DIR/$NODE_DIR_NAME"
if [ -f "$NODE_TARGET/bin/node" ]; then
echo -e " ${GREEN}${NC} Node.js ($PLATFORM) already downloaded, skipping"
else
echo -e " ${CYAN}${NC} Downloading Node.js $NODE_VERSION ($PLATFORM)"
mkdir -p "$NODE_TARGET"
NODE_URL="$NODE_MIRROR/$NODE_VERSION/node-$NODE_VERSION-$PLATFORM.tar.gz"
echo " $NODE_URL"
curl -fSL "$NODE_URL" | tar xz -C "$NODE_TARGET" --strip-components=1
if [ -f "$NODE_TARGET/bin/node" ]; then
echo -e " ${GREEN}${NC} Node.js ($PLATFORM) downloaded"
else
echo -e " ${RED}✗ Node.js Download failed${NC}"
exit 1
fi
fi
# ---- 1b. Download Node.js for Windows (only with --all-platforms) ----
if [ "$ALL_PLATFORMS" = "true" ]; then
WIN_NODE_TARGET="$RUNTIME_DIR/node-win-x64"
if [ -f "$WIN_NODE_TARGET/node.exe" ]; then
echo -e " ${GREEN}${NC} Node.js (win-x64) already downloaded, skipping"
else
echo -e " ${CYAN}${NC} Downloading Node.js $NODE_VERSION (win-x64) for Windows"
mkdir -p "$WIN_NODE_TARGET"
WIN_NODE_URL="$NODE_MIRROR/$NODE_VERSION/node-$NODE_VERSION-win-x64.zip"
echo " $WIN_NODE_URL"
TMP_ZIP="/tmp/node-win-x64-$$.zip"
curl -fSL "$WIN_NODE_URL" -o "$TMP_ZIP"
if command -v unzip >/dev/null 2>&1; then
unzip -q "$TMP_ZIP" -d "/tmp/node-win-extract-$$"
cp -r "/tmp/node-win-extract-$$"/node-$NODE_VERSION-win-x64/* "$WIN_NODE_TARGET/"
rm -rf "/tmp/node-win-extract-$$"
else
echo -e " ${RED}✗ unzip not found, skipping Windows runtime${NC}"
fi
rm -f "$TMP_ZIP"
if [ -f "$WIN_NODE_TARGET/node.exe" ]; then
echo -e " ${GREEN}${NC} Node.js (win-x64) downloaded"
else
echo -e " ${CYAN}${NC} Windows runtime download failed — this platform still works"
fi
fi
fi
# ---- 2. Install OpenClaw ----
if [ -d "$CORE_DIR/node_modules/openclaw" ]; then
echo -e " ${GREEN}${NC} OpenClaw already installed, skipping"
else
echo -e " ${CYAN}${NC} Installing OpenClaw..."
mkdir -p "$CORE_DIR"
# Init package.json if not exists (pinned OpenClaw version from OPENCLAW_VERSION)
OPENCLAW_VERSION_FILE="$(dirname "$0")/OPENCLAW_VERSION"
if [ ! -f "$OPENCLAW_VERSION_FILE" ]; then
OPENCLAW_VERSION_FILE="$(dirname "$0")/../OPENCLAW_VERSION"
fi
OPENCLAW_VERSION="2026.7.1-2"
if [ -f "$OPENCLAW_VERSION_FILE" ]; then
OPENCLAW_VERSION="$(tr -d '[:space:]' < "$OPENCLAW_VERSION_FILE")"
# Copy version file into portable/ so USB users can read it without repo root
cp "$OPENCLAW_VERSION_FILE" "$(dirname "$0")/OPENCLAW_VERSION" 2>/dev/null || true
fi
if [ ! -f "$CORE_DIR/package.json" ]; then
cat > "$CORE_DIR/package.json" << PKGJSON
{
"name": "u-claw-core",
"version": "1.0.0",
"private": true,
"dependencies": {
"openclaw": "$OPENCLAW_VERSION"
}
}
PKGJSON
fi
# Install with China mirror缓存留盘内拔盘不留痕
# --ignore-scripts 必须加openclaw 的 preinstall 脚本会调系统 `node`,但便携版
# 用的是 app/runtime 下的 node不在 PATH未装 Node 的 Mac 用户会因
# "node: command not found" 安装失败 (code 127)。与 START HERE - Mac.command 的 fallback 对齐。
NODE_BIN="$NODE_TARGET/bin/node"
NPM_BIN="$NODE_TARGET/bin/npm"
npm_config_cache="$APP_DIR/.npm-cache" "$NODE_BIN" "$NPM_BIN" install --prefix "$CORE_DIR" --registry="$MIRROR" --ignore-scripts --no-audit --no-fund --omit=dev
echo -e " ${GREEN}${NC} OpenClaw installed"
fi
# ---- 3. Install QQ Plugin ----
if [ -d "$CORE_DIR/node_modules/@sliverp/qqbot" ]; then
echo -e " ${GREEN}${NC} QQ plugin already installed, skipping"
else
echo -e " ${CYAN}${NC} Installing the QQ plugin..."
NODE_BIN="$NODE_TARGET/bin/node"
NPM_BIN="$NODE_TARGET/bin/npm"
npm_config_cache="$APP_DIR/.npm-cache" "$NODE_BIN" "$NPM_BIN" install @sliverp/qqbot@latest --prefix "$CORE_DIR" --registry="$MIRROR" --ignore-scripts --no-audit --no-fund --omit=dev 2>/dev/null || true
echo -e " ${GREEN}${NC} QQ plugin installed"
fi
# ---- 3b. Stage what the drive needs to stand alone ----
# release.yml puts these on the drive; a locally built drive has to match, or the
# first-run wizard cannot install skills and the drive cannot switch locale offline.
for VERSION_FILE in OPENCLAW_VERSION NODE_VERSION; do
[ -f "$SCRIPT_DIR/$VERSION_FILE" ] || cp "$SCRIPT_DIR/../$VERSION_FILE" "$SCRIPT_DIR/$VERSION_FILE" 2>/dev/null || true
done
if [ -d "$SCRIPT_DIR/../skills" ] && [ ! -d "$SCRIPT_DIR/skills" ]; then
cp -R "$SCRIPT_DIR/../skills" "$SCRIPT_DIR/skills"
fi
mkdir -p "$SCRIPT_DIR/lib"
[ -f "$SCRIPT_DIR/lib/install-skills.mjs" ] || cp "$SCRIPT_DIR/../lib/install-skills.mjs" "$SCRIPT_DIR/lib/install-skills.mjs" 2>/dev/null || true
# ---- 4. Install skills from the manifest ----
# Content lives in ../skills (see skills/README.md); this script carries none.
SKILLS_TARGET="$CORE_DIR/node_modules/openclaw/skills"
SKILL_INSTALLER="$SCRIPT_DIR/lib/install-skills.mjs"
[ -f "$SKILL_INSTALLER" ] || SKILL_INSTALLER="$SCRIPT_DIR/../lib/install-skills.mjs"
if [ -f "$SKILL_INSTALLER" ] && [ -d "$SKILLS_TARGET" ]; then
echo -e " ${CYAN}\u2193${NC} Installing skills..."
"$NODE_TARGET/bin/node" "$SKILL_INSTALLER" --target "$SKILLS_TARGET" --locale "${UCLAW_LOCALE:-en}"
fi
# ---- Done ----
echo ""
echo -e "${GREEN}════════════════════════════════════════${NC}"
echo -e "${GREEN} Done.${NC}"
echo ""
echo -e " To start it:"
echo -e " Mac: ${CYAN}double-click \"START HERE - Mac.command\"${NC}"
echo -e " Windows: double-click ${CYAN}START HERE - Windows.bat${NC}"
echo ""
echo -e " Layout:"
echo -e " app/core/ OpenClaw and its dependencies"
echo -e " app/runtime/ ← Node.js $NODE_VERSION"
echo -e " data/ created on first run"
echo ""
echo -e " ${CYAN}Tip: use --all-platforms to prepare a drive that works on both Mac and Windows${NC}"
echo -e "${GREEN}════════════════════════════════════════${NC}"