fix: replace setup.bat with complete version (add QQ plugin + --all-platforms)

PR #13 (luckylibin) version includes:
- QQ plugin installation step (was missing)
- --all-platforms flag to download Mac Node.js runtimes
- More robust error handling

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hfshfg
2026-04-04 22:28:36 +08:00
parent 974a59d3ba
commit 70fc030e8e

View File

@@ -1,117 +1,176 @@
@echo off @echo off
setlocal EnableDelayedExpansion setlocal EnableDelayedExpansion
chcp 65001 >nul 2>&1 chcp 65001 >nul 2>&1
title U-Claw Portable Setup title U-Claw Portable Setup
echo.
echo ========================================
echo U-Claw Portable Setup
echo 下载 Node.js + 安装 OpenClaw
echo ========================================
echo.
set "SCRIPT_DIR=%~dp0" set "SCRIPT_DIR=%~dp0"
set "APP_DIR=%SCRIPT_DIR%app" set "APP_DIR=%SCRIPT_DIR%app"
set "CORE_DIR=%APP_DIR%\core" set "CORE_DIR=%APP_DIR%\core"
set "RUNTIME_DIR=%APP_DIR%\runtime" set "RUNTIME_DIR=%APP_DIR%\runtime"
set "NODE_DIR=%RUNTIME_DIR%\node-win-x64"
set "NODE_BIN=%NODE_DIR%\node.exe"
set "NPM_BIN=%NODE_DIR%\npm.cmd"
set "MIRROR=https://registry.npmmirror.com" set "MIRROR=https://registry.npmmirror.com"
set "NODE_MIRROR=https://npmmirror.com/mirrors/node" set "NODE_MIRROR=https://npmmirror.com/mirrors/node"
set "NODE_VER=v22.22.1" set "NODE_VERSION=v22.22.1"
set "ALL_PLATFORMS=false"
if "%~1"=="--all-platforms" set "ALL_PLATFORMS=true"
REM ---- Step 1: Node.js ---- echo.
echo [1/3] 检查 Node.js... echo ========================================
echo U-Claw Portable Setup
if exist "%NODE_BIN%" ( echo ========================================
for /f "tokens=*" %%v in ('"%NODE_BIN%" --version') do echo Node.js (win-x64) 已存在: %%v
goto :install_openclaw
)
echo 从国内镜像下载 Node.js %NODE_VER%...
set "NODE_ZIP=node-%NODE_VER%-win-x64.zip"
set "NODE_URL=%NODE_MIRROR%/%NODE_VER%/%NODE_ZIP%"
echo %NODE_URL%
echo. echo.
curl -# -L "%NODE_URL%" -o "%TEMP%\%NODE_ZIP%" echo 系统: Windows x64
if !errorlevel! neq 0 ( echo.
echo.
echo [ERROR] 下载失败,请检查网络连接
pause
exit /b 1
)
echo 解压中... REM ---- 1. Download Node.js (Current Platform - Windows) ----
mkdir "%NODE_DIR%" 2>nul set "NODE_DIR_NAME=node-win-x64"
powershell -command "Expand-Archive -Path '%TEMP%\%NODE_ZIP%' -DestinationPath '%TEMP%\node-extract' -Force" set "NODE_TARGET=%RUNTIME_DIR%\%NODE_DIR_NAME%"
xcopy /s /e /q /y "%TEMP%\node-extract\node-%NODE_VER%-win-x64\*" "%NODE_DIR%\" >nul
if exist "%NODE_TARGET%\node.exe" goto skip_node_download
echo [DOWNLOAD] Downloading Node.js %NODE_VERSION% (win-x64)...
if not exist "%NODE_TARGET%" mkdir "%NODE_TARGET%" 2>nul
set "NODE_URL=%NODE_MIRROR%/%NODE_VERSION%/node-%NODE_VERSION%-win-x64.zip"
echo URL: %NODE_URL%
set "TMP_ZIP=%TEMP%\node-win-x64-%RANDOM%.zip"
curl -fSL "%NODE_URL%" -o "%TMP_ZIP%"
set "DOWNLOAD_OK=0"
if %errorlevel% equ 0 set "DOWNLOAD_OK=1"
if "%DOWNLOAD_OK%"=="0" goto node_download_fail
echo Extracting...
powershell -command "Expand-Archive -Path '%TMP_ZIP%' -DestinationPath '%TEMP%\node-extract' -Force" >nul 2>&1
xcopy /s /e /q /y "%TEMP%\node-extract\node-%NODE_VERSION%-win-x64\*" "%NODE_TARGET%\" >nul
rmdir /s /q "%TEMP%\node-extract" 2>nul rmdir /s /q "%TEMP%\node-extract" 2>nul
del "%TEMP%\%NODE_ZIP%" 2>nul del /f /q "%TMP_ZIP%" 2>nul
if not exist "%NODE_BIN%" ( if not exist "%NODE_TARGET%\node.exe" goto node_download_fail
echo [ERROR] Node.js 解压失败
pause
exit /b 1
)
for /f "tokens=*" %%v in ('"%NODE_BIN%" --version') do echo Node.js %%v 安装完成
:install_openclaw echo [OK] Node.js (win-x64) downloaded
echo. goto node_download_done
echo [2/3] 安装 OpenClaw...
if exist "%CORE_DIR%\node_modules\openclaw" ( :node_download_fail
echo OpenClaw 已安装,跳过 echo [ERROR] Node.js download failed
goto :install_skills pause
exit /b 1
:skip_node_download
echo [OK] Node.js (win-x64) exists, skipping
:node_download_done
REM ---- 1b. Download Node.js for Mac (only with --all-platforms) ----
if not "%ALL_PLATFORMS%"=="true" goto skip_mac_download
for %%p in (arm64 x64) do (
set "MAC_NODE_TARGET=%RUNTIME_DIR%\node-mac-%%p"
if exist "!MAC_NODE_TARGET!\bin\node" (
echo [OK] Node.js (mac-%%p) exists, skipping
) else (
echo [DOWNLOAD] Downloading Node.js %NODE_VERSION% (mac-%%p) for Mac support...
if not exist "!MAC_NODE_TARGET!" mkdir "!MAC_NODE_TARGET!" 2>nul
set "MAC_NODE_URL=%NODE_MIRROR%/%NODE_VERSION%/node-%NODE_VERSION%-darwin-%%p.tar.gz"
echo URL: !MAC_NODE_URL!
set "TMP_TAR=%TEMP%\node-mac-%%p-%RANDOM%.tar.gz"
curl -fSL "!MAC_NODE_URL!" -o "!TMP_TAR!"
if !errorlevel! equ 0 (
echo Extracting...
powershell -command "tar -xzf '!TMP_TAR!' -C '!MAC_NODE_TARGET!' --strip-components 1" >nul 2>&1
del /f /q "!TMP_TAR!" 2>nul
if exist "!MAC_NODE_TARGET!\bin\node" (
echo [OK] Node.js (mac-%%p) downloaded
) else (
echo [WARNING] Mac runtime download failed (does not affect current platform)
)
) else (
echo [WARNING] Mac runtime download failed (does not affect current platform)
)
)
) )
mkdir "%CORE_DIR%" 2>nul :skip_mac_download
REM ---- 2. Install OpenClaw ----
if exist "%CORE_DIR%\node_modules\openclaw" goto skip_openclaw_install
echo [INSTALL] Installing OpenClaw...
if not exist "%CORE_DIR%" mkdir "%CORE_DIR%" 2>nul
if not exist "%CORE_DIR%\package.json" ( if not exist "%CORE_DIR%\package.json" (
echo {"name":"u-claw-core","version":"1.0.0","private":true,"dependencies":{"openclaw":"latest"}} > "%CORE_DIR%\package.json" echo { "name": "u-claw-core", "version": "1.0.0", "private": true, "dependencies": { "openclaw": "latest" } } > "%CORE_DIR%\package.json"
) )
set "NPM_BIN=%NODE_TARGET%\npm.cmd"
cd /d "%CORE_DIR%" cd /d "%CORE_DIR%"
call "%NPM_BIN%" install --registry=%MIRROR% call "%NPM_BIN%" install --prefix "%CORE_DIR%" --registry="%MIRROR%"
if !errorlevel! neq 0 (
echo [ERROR] OpenClaw 安装失败
pause
exit /b 1
)
echo OpenClaw 安装完成
:install_skills echo [OK] OpenClaw installed
echo. goto openclaw_install_done
echo [3/3] 安装中国优化技能...
:skip_openclaw_install
echo [OK] OpenClaw exists, skipping
:openclaw_install_done
REM ---- 3. Install QQ Plugin ----
if exist "%CORE_DIR%\node_modules\@sliverp\qqbot" goto skip_qq_install
echo [INSTALL] Installing QQ Plugin...
set "NPM_BIN=%NODE_TARGET%\npm.cmd"
cd /d "%CORE_DIR%"
call "%NPM_BIN%" install @sliverp/qqbot@latest --prefix "%CORE_DIR%" --registry="%MIRROR%" >nul 2>&1
echo [OK] QQ Plugin installed
goto qq_install_done
:skip_qq_install
echo [OK] QQ Plugin exists, skipping
:qq_install_done
REM ---- 4. Install China-optimized skills ----
set "SKILLS_CN=%SCRIPT_DIR%skills-cn" set "SKILLS_CN=%SCRIPT_DIR%skills-cn"
set "SKILLS_TARGET=%CORE_DIR%\node_modules\openclaw\skills" set "SKILLS_TARGET=%CORE_DIR%\node_modules\openclaw\skills"
set "SKILL_COUNT=0"
if exist "%SKILLS_CN%" if exist "%SKILLS_TARGET%" ( if not exist "%SKILLS_CN%" goto skip_skills_install
for /d %%d in ("%SKILLS_CN%\*") do ( if not exist "%SKILLS_TARGET%" goto skip_skills_install
if not exist "%SKILLS_TARGET%\%%~nxd" (
xcopy /s /e /q /y "%%d" "%SKILLS_TARGET%\%%~nxd\" >nul 2>nul echo [COPY] Installing China-optimized skills (skills-cn)...
set "SKILL_COUNT=0"
for /d %%s in ("%SKILLS_CN%\*") do (
set "skill_name=%%~nxs"
if not exist "%SKILLS_TARGET%\!skill_name!" (
xcopy /s /e /q /y "%%s" "%SKILLS_TARGET%\!skill_name!\" >nul
set /a SKILL_COUNT+=1 set /a SKILL_COUNT+=1
) )
)
echo 中国技能安装完成 ^(+!SKILL_COUNT! 个^)
) else (
echo 跳过技能安装
) )
echo [OK] China skills installed (+%SKILL_COUNT% skills)
:skip_skills_install
REM ---- Done ---- REM ---- Done ----
echo. echo.
echo ======================================== echo ========================================
echo 搭建完成! echo Setup Complete!
echo ======================================== echo ========================================
echo. echo.
echo 启动方式: echo To start:
echo 双击 Windows-Start.bat echo Mac: bash Mac-Start.command
echo Windows: Double-click Windows-Start.bat
echo. echo.
echo 目录结构: echo Directory structure:
echo app\core\ - OpenClaw + 依赖 echo app\core\ - OpenClaw + dependencies
echo app\runtime\ - Node.js %NODE_VER% echo app\runtime\ - Node.js %NODE_VERSION%
echo data\ - 运行后自动生成 echo data\ - Auto-generated after first run
echo.
if "%ALL_PLATFORMS%"=="true" (
echo Note: All platform runtimes downloaded, ready for cross-platform USB
) else (
echo Note: For cross-platform USB use setup.bat --all-platforms
)
echo. echo.
pause pause