From ce042333c43b3c2a1c2384af7edfc58d739ba521 Mon Sep 17 00:00:00 2001 From: wangbolhr Date: Fri, 10 Apr 2026 16:31:44 +0800 Subject: [PATCH] =?UTF-8?q?docs(win):=20=E5=88=86=E8=A1=8C=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E4=B8=80=E9=94=AE=E9=83=A8=E7=BD=B2=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=20git=20=E8=AF=AF=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - README: Windows 克隆与启动改为分行,补充单行安全写法与说明 - start.ps1: 无 Git 时 winget/choco 自动安装、PATH 刷新、UTF-8 BOM 与文件头使用说明 Made-with: Cursor --- README.md | 28 +++++++++---- start.ps1 | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 129 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 62628a2..4268948 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,23 @@ git clone https://git.51easyai.com/wangbo/easyai.git && cd easyai && chmod +x st ### Windows +在 PowerShell 中**分行执行**下面三行(不要与 `git clone` 粘成一行且漏掉分号,否则 `-ExecutionPolicy` 可能被当成 `git` 的参数,出现 `error: unknown switch 'E'`): + ```powershell -git clone https://git.51easyai.com/wangbo/easyai.git; cd easyai; powershell -ExecutionPolicy Bypass -File .\start.ps1 +git clone "https://git.51easyai.com/wangbo/easyai.git" "easyai" +Set-Location ".\easyai" +powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" +``` + +若必须单行粘贴,请用分号分隔整条命令链: + +```powershell +git clone "https://git.51easyai.com/wangbo/easyai.git" "easyai"; Set-Location "easyai"; powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" ``` > **Windows 脚本权限说明**:PowerShell 默认禁止运行脚本,直接双击 `start.ps1` 会闪退。 > -> - **推荐**:使用 `powershell -ExecutionPolicy Bypass -File .\start.ps1` 执行,无需修改系统策略 +> - **推荐**:使用 `powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1"` 执行,无需修改系统策略 > - **或**:以管理员身份打开 PowerShell,执行 `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`,之后可直接运行 `.\start.ps1` --- @@ -438,7 +448,7 @@ PowerShell 默认可能禁止运行脚本,需先执行以下任一方式: **方式一:临时允许本次运行(推荐)** ```powershell -powershell -ExecutionPolicy Bypass -File .\start.ps1 +powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" ``` **方式二:为当前用户永久放开脚本执行权限** @@ -449,19 +459,21 @@ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser ### 启动步骤 -1. 克隆并进入目录 +1. 克隆并进入目录(**请分行执行**,避免把后续命令当成 `git` 的参数) + ```powershell -git clone https://git.51easyai.com/wangbo/easyai.git -cd easyai +git clone "https://git.51easyai.com/wangbo/easyai.git" "easyai" +Set-Location ".\easyai" ``` 2. 在 PowerShell 或 CMD 中运行(二选一) + ```powershell # 若已设置 ExecutionPolicy,可直接执行 .\start.ps1 -# 未设置时使用 Bypass 方式 -powershell -ExecutionPolicy Bypass -File .\start.ps1 +# 未设置时使用 Bypass 方式(推荐带引号的路径) +powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" ``` 3. 按提示选择 [1] 本地访问 或 [2] 局域网访问,脚本将自动配置并启动 Docker 服务。 diff --git a/start.ps1 b/start.ps1 index e5911db..4a495e3 100644 --- a/start.ps1 +++ b/start.ps1 @@ -1,4 +1,17 @@ #Requires -Version 5.1 +# +# 从 Git 克隆后首次部署(推荐分行复制执行,避免参数被误传给 git): +# git clone "https://git.51easyai.com/wangbo/easyai.git" "easyai" +# Set-Location ".\easyai" +# powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" +# +# 若必须一行,请用分号分隔整条链,且 -File 后必须是带引号的脚本路径(不要用 Istart.ps1,应为 .\start.ps1): +# git clone "https://git.51easyai.com/wangbo/easyai.git" "easyai"; Set-Location "easyai"; powershell.exe -NoProfile -ExecutionPolicy Bypass -File ".\start.ps1" +# +# 若出现 error: unknown switch 'E':说明 -ExecutionPolicy 被交给了 git(可复现:git clone URL -ExecutionPolicy)。 +# 常见原因:整段命令未用分号分隔、或把 powershell 与 git 写在同一行且参数被 git 解析。 +# "Istart.ps1" 多为把 ".\start.ps1" 复制错(点反斜杠被看成字母 I)。 +# [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $OutputEncoding = [System.Text.Encoding]::UTF8 @@ -138,6 +151,81 @@ function Setup-EnvFiles { Ok ".env configured for IP=$($script:DeployIP)" } +function Test-GitInstalled { + $git = Get-Command git -ErrorAction SilentlyContinue + if (-not $git) { return $false } + try { & git --version *> $null; return $true } catch { return $false } +} + +function Refresh-SessionPath { + try { + $machine = [Environment]::GetEnvironmentVariable("Path", "Machine") + $user = [Environment]::GetEnvironmentVariable("Path", "User") + $parts = @($machine, $user) | Where-Object { $_ } + if ($parts.Count -gt 0) { $env:Path = ($parts -join ";") } + } catch { } +} + +function Install-Git { + if (Get-Command winget -ErrorAction SilentlyContinue) { + Step "Installing Git via winget..." + Write-Log "winget install Git.Git" + winget install --id Git.Git -e --accept-source-agreements --accept-package-agreements + if ($LASTEXITCODE -eq 0) { + Start-Sleep -Seconds 2 + Refresh-SessionPath + if (Test-GitInstalled) { + Ok "Git installed" + Write-Log "Git available after winget (PATH refreshed)" + return + } + Ok "Git installed. Close this terminal, open a new one, then run this script again." + Write-Log "Git installed via winget, user must refresh shell" + exit 0 + } + } + if (Get-Command choco -ErrorAction SilentlyContinue) { + Step "Installing Git via Chocolatey..." + Write-Log "choco install git" + choco install git -y + if ($LASTEXITCODE -eq 0) { + Start-Sleep -Seconds 2 + Refresh-SessionPath + if (Test-GitInstalled) { + Ok "Git installed" + Write-Log "Git available after choco (PATH refreshed)" + return + } + Ok "Git installed. Close this terminal, open a new one, then run this script again." + Write-Log "Git installed via choco, user must refresh shell" + exit 0 + } + } + Warn "Could not install Git automatically. Please install manually:" + Write-Host " https://git-scm.com/download/win" + Write-Log "Git auto-install failed, user must install manually" + Wait-ForExit + exit 1 +} + +function Ensure-Git { + if ($env:DEPLOY_SKIP_GIT -eq "1") { return } + if ($env:CI -eq "true") { return } + if ($script:DeployDryRun) { return } + if (Test-GitInstalled) { + Ok "Git installed" + return + } + Write-Host "" + Write-Host "================================" + Write-Host " Git Check" + Write-Host "================================" + Write-Host "" + Warn "Git not found. Attempting automatic install..." + Write-Log "Git missing, running Install-Git" + Install-Git +} + function Test-DockerInstalled { $docker = Get-Command docker -ErrorAction SilentlyContinue if (-not $docker) { return $false } @@ -258,6 +346,7 @@ function Start-Services { function Main { Init-ProjectDir + Ensure-Git if ((Test-Path ".env") -and -not $env:DEPLOY_FORCE_RECONFIG -and -not $env:DEPLOY_IP) { $answer = (Read-Host "Existing .env found. Reconfigure? [y/N]").Trim().ToLower() @@ -288,12 +377,26 @@ function Main { $ip = if ($script:DeployIP) { $script:DeployIP } else { "127.0.0.1" } Write-Host "" - Write-Host "================================" - Write-Host " Deployment Done" - Write-Host "================================" - Write-Host "URL: http://${ip}:3010" - Write-Host "User: admin" - Write-Host "Password: 123456" + if ($script:DeployDryRun) { + Write-Host "================================" -ForegroundColor Yellow + Write-Host " 配置已生成(未启动 Docker 服务)" -ForegroundColor Yellow + Write-Host "================================" -ForegroundColor Yellow + Write-Host "" + Write-Host " 预期访问: " -NoNewline; Write-Host "http://${ip}:3010" -ForegroundColor Cyan + Write-Host "" + Write-Host " 默认管理员: admin / 123456(启动服务后用于登录)" -ForegroundColor DarkGray + } else { + Write-Host "================================" -ForegroundColor Green + Write-Host " 部署成功" -ForegroundColor Green + Write-Host "================================" -ForegroundColor Green + Write-Host "" + Write-Host " 访问地址: " -NoNewline; Write-Host "http://${ip}:3010" -ForegroundColor Cyan + Write-Host "" + Write-Host " -------- 默认管理员(首次登录后请修改密码)--------" -ForegroundColor Yellow + Write-Host " 账号: " -NoNewline; Write-Host "admin" -ForegroundColor White + Write-Host " 密码: " -NoNewline; Write-Host "123456" -ForegroundColor White + } + Write-Host "" Wait-ForExit }