@echo off chcp 65001 > nul 2>&1 title Bookworm Smart Assistant - 全自动安装 (Win10 兼容) :: ─── 自动提升管理员权限 ── :: 用 goto 而非 if() 避免文件名含括号(如"(2)")导致解析崩溃 net session >nul 2>&1 if %errorlevel% equ 0 goto :IS_ADMIN echo 需要管理员权限来安装软件,正在请求... echo Set objShell = CreateObject("Shell.Application") > "%TEMP%\bw_elevate.vbs" echo objShell.ShellExecute "cmd.exe", "/k cd /d ""%~dp0"" & ""%~nx0""", "", "runas", 1 >> "%TEMP%\bw_elevate.vbs" cscript //nologo "%TEMP%\bw_elevate.vbs" del /f /q "%TEMP%\bw_elevate.vbs" 2>nul exit /b :IS_ADMIN :: ─── 初始化 ───────────────────────────────────────── setlocal EnableDelayedExpansion color 1F set "NO_PROXY=bww.letcareme.com,code.letcareme.com,letcareme.com,localhost,127.0.0.1" set "no_proxy=%NO_PROXY%" set "INSTALL_DIR=%USERPROFILE%\bookworm-boot" set "GITEA_URL=https://code.letcareme.com/bookworm/bookworm-boot.git" set "TEMP_DL=%TEMP%\bookworm-setup" set "ERRORS=0" set "NEED_PATH_REFRESH=0" echo. echo +============================================================+ echo ^| ^| echo ^| Bookworm Smart Assistant ^| echo ^| 全自动安装 v2.0 (Windows 10 兼容版) ^| echo ^| ^| echo ^| 兼容 Windows 10 1809+ / Windows 11 ^| echo ^| 无需 winget, 通过直接下载安装包实现全自动 ^| echo ^| ^| echo +============================================================+ echo. if not exist "%TEMP_DL%" mkdir "%TEMP_DL%" :: ─── 检测安装方式: winget 优先, 回退直接下载 ───────── set "HAS_WINGET=0" where winget >nul 2>nul if %errorlevel% equ 0 set "HAS_WINGET=1" if "%HAS_WINGET%"=="1" ( echo [OK] 检测到 winget, 使用 winget 安装 ) else ( echo [i] 未检测到 winget, 使用直接下载方式安装 ) echo. :: ─── 步骤 1/7: 安装 Git ──────────────────────────── echo [1/7] 检查 Git... where git >nul 2>nul if %errorlevel% neq 0 ( if "%HAS_WINGET%"=="1" ( echo [..] 通过 winget 安装 Git... winget install Git.Git --accept-source-agreements --accept-package-agreements --silent ) else ( echo [..] 下载 Git 安装包... powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; $ProgressPreference='SilentlyContinue'; Invoke-WebRequest -Uri 'https://github.com/git-for-windows/git/releases/download/v2.47.1.windows.2/Git-2.47.1.2-64-bit.exe' -OutFile '%TEMP_DL%\git-install.exe'}" if exist "%TEMP_DL%\git-install.exe" ( echo [..] 静默安装 Git... "%TEMP_DL%\git-install.exe" /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /COMPONENTS="icons,ext\reg\shellhere,assoc,assoc_sh" if !errorlevel! neq 0 ( echo [!!] Git 安装失败 ^(exit: !errorlevel!^) set /a ERRORS+=1 ) else ( echo [OK] Git 安装完成 ) ) else ( echo [!!] Git 下载失败, 请手动安装: https://git-scm.com set /a ERRORS+=1 ) ) set "NEED_PATH_REFRESH=1" ) else ( echo [OK] Git 已安装 ) echo. :: ─── 步骤 2/7: 安装 Node.js ──────────────────────── echo [2/7] 检查 Node.js... where node >nul 2>nul if %errorlevel% neq 0 ( if "%HAS_WINGET%"=="1" ( echo [..] 通过 winget 安装 Node.js LTS... winget install OpenJS.NodeJS.LTS --accept-source-agreements --accept-package-agreements --silent ) else ( echo [..] 下载 Node.js LTS 安装包... powershell -Command "& {[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; $ProgressPreference='SilentlyContinue'; Invoke-WebRequest -Uri 'https://nodejs.org/dist/v22.14.0/node-v22.14.0-x64.msi' -OutFile '%TEMP_DL%\node-install.msi'}" if exist "%TEMP_DL%\node-install.msi" ( echo [..] 静默安装 Node.js... msiexec /i "%TEMP_DL%\node-install.msi" /qn /norestart echo [OK] Node.js 安装完成 ) else ( echo [!!] Node.js 下载失败, 请手动安装: https://nodejs.org set /a ERRORS+=1 ) ) set "NEED_PATH_REFRESH=1" ) else ( echo [OK] Node.js 已安装 ) echo. :: ─── 刷新 PATH ────────────────────────────────────── if "%NEED_PATH_REFRESH%"=="1" ( echo [..] 刷新系统 PATH... for /f "tokens=2*" %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path 2^>nul') do set "SYS_PATH=%%b" for /f "tokens=2*" %%a in ('reg query "HKCU\Environment" /v Path 2^>nul') do set "USR_PATH=%%b" set "PATH=!SYS_PATH!;!USR_PATH!" set "PATH=!PATH!;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\usr\bin" set "PATH=!PATH!;%APPDATA%\npm" echo [OK] PATH 已刷新 echo. ) :: ─── 二次验证 ──────────────────────────────────────── where git >nul 2>nul if %errorlevel% neq 0 ( echo [!!] Git 仍不可用 — 可能需要重启电脑后重新运行本程序 pause exit /b 1 ) where node >nul 2>nul if %errorlevel% neq 0 ( echo [!!] Node.js 仍不可用 — 可能需要重启电脑后重新运行本程序 pause exit /b 1 ) :: ─── 步骤 3/7: 安装 Claude Code ───────────────────── echo [3/7] 检查 Claude Code... :: 国内 npm 镜像 - 淘宝源, 避免 npmjs.org 超时 call npm config set registry https://registry.npmmirror.com 2>nul where claude >nul 2>nul if %errorlevel% neq 0 ( echo [..] 通过 npm 安装 Claude Code - 淘宝镜像加速... call npm i -g @anthropic-ai/claude-code 2>&1 if !errorlevel! neq 0 ( echo [!!] Claude Code 安装失败 set /a ERRORS+=1 ) else ( echo [OK] Claude Code 安装成功 ) ) else ( echo [OK] Claude Code 已安装 ) echo. :: ─── 步骤 4/7: 代理检测 ────────────────── echo [4/7] 检测网络代理... :: 纯 batch 实现, 不依赖 PowerShell, 不含括号 set "PROXY_FOUND=" netstat -an 2>nul | findstr "LISTENING" | findstr ":7890 :7893 :7891 :10792 :1080 :8118" >nul 2>nul if !errorlevel! equ 0 set "PROXY_FOUND=1" if defined PROXY_FOUND echo [OK] 检测到本地代理端口 if not defined PROXY_FOUND echo [!] 未检测到代理, Claude Code 在国内可能无法启动 if not defined PROXY_FOUND echo 请确保代理软件已启动 echo. :: ─── 步骤 5/7: 克隆/更新 Bookworm ────────────────── echo [5/7] 同步 Bookworm 配置... git config --global credential.helper manager 2>nul if exist "%INSTALL_DIR%\.git" ( echo 已有安装, 更新到最新版... pushd "%INSTALL_DIR%" git pull 2>&1 popd ) else ( if exist "%INSTALL_DIR%" rmdir /s /q "%INSTALL_DIR%" 2>nul echo 首次下载 - 需输入 Gitea 用户名密码... git clone "%GITEA_URL%" "%INSTALL_DIR%" 2>&1 if !errorlevel! neq 0 ( echo [!!] 下载失败, 请检查网络和 Gitea 凭证 pause exit /b 1 ) ) echo [OK] Bookworm 文件已就绪 echo. :: ─── 步骤 6/7: 执行安装配置 ──────────────────────── echo [6/7] 执行安装配置... echo. echo 首次安装需要输入主密码来解密 API 凭证 echo - 主密码由管理员提供, 区分大小写 echo. where pwsh >nul 2>nul if !errorlevel! equ 0 ( pwsh -NoLogo -ExecutionPolicy Bypass -File "%INSTALL_DIR%\install.ps1" ) else ( powershell -NoLogo -ExecutionPolicy Bypass -File "%INSTALL_DIR%\install.ps1" ) echo. :: ─── 步骤 7/7: 桌面快捷方式 + 完成 ───────────────── echo [7/7] 创建桌面快捷方式... :: 用 VBScript 创建快捷方式, 避免 PowerShell 花括号被 cmd 截获 echo Set ws = CreateObject("WScript.Shell") > "%TEMP%\bw_shortcut.vbs" echo Set sc = ws.CreateShortcut(ws.SpecialFolders("Desktop") ^& "\Bookworm.lnk") >> "%TEMP%\bw_shortcut.vbs" echo sc.TargetPath = "%INSTALL_DIR%\启动Bookworm.bat" >> "%TEMP%\bw_shortcut.vbs" echo sc.WorkingDirectory = "%INSTALL_DIR%" >> "%TEMP%\bw_shortcut.vbs" echo sc.Description = "Bookworm Smart Assistant" >> "%TEMP%\bw_shortcut.vbs" echo sc.Save >> "%TEMP%\bw_shortcut.vbs" echo Set sc = ws.CreateShortcut(ws.SpecialFolders("Desktop") ^& "\更新Bookworm.lnk") >> "%TEMP%\bw_shortcut.vbs" echo sc.TargetPath = "%INSTALL_DIR%\更新并启动Bookworm.bat" >> "%TEMP%\bw_shortcut.vbs" echo sc.WorkingDirectory = "%INSTALL_DIR%" >> "%TEMP%\bw_shortcut.vbs" echo sc.Save >> "%TEMP%\bw_shortcut.vbs" cscript //nologo "%TEMP%\bw_shortcut.vbs" 2>nul if !errorlevel! equ 0 echo [OK] 桌面快捷方式已创建 del /f /q "%TEMP%\bw_shortcut.vbs" 2>nul if exist "%INSTALL_DIR%\guide.html" start "" "%INSTALL_DIR%\guide.html" :: 清理临时文件 if exist "%TEMP_DL%" rmdir /s /q "%TEMP_DL%" 2>nul echo. echo +============================================================+ echo ^| ^| echo ^| 安装完成! ^| echo ^| ^| echo ^| 已安装: ^| echo ^| [v] Node.js LTS [v] Git ^| echo ^| [v] Claude Code [v] Bookworm - 92 Skills ^| echo ^| ^| echo ^| 桌面快捷方式: ^| echo ^| Bookworm — 日常启动 ^| echo ^| 更新Bookworm — 同步最新版后启动 ^| echo ^| ^| echo +============================================================+ echo. if %ERRORS% gtr 0 ( echo [注意] 安装过程中有 %ERRORS% 个警告, 请查看上方日志 echo. ) echo 按任意键启动 Bookworm... pause > nul cd /d "%INSTALL_DIR%" if exist "启动Bookworm.bat" ( call "启动Bookworm.bat" ) else ( where pwsh >nul 2>nul if !errorlevel! equ 0 ( pwsh -NoLogo -ExecutionPolicy Bypass -File install.ps1 -StartOnly -AutoAccept ) else ( powershell -NoLogo -ExecutionPolicy Bypass -File install.ps1 -StartOnly -AutoAccept ) ) endlocal :: ─── 兜底: 任何情况下窗口不自动关闭 ── echo. echo 如看到此消息说明流程已结束,按任意键关闭窗口... pause > nul