docs(win): 分行展示一键部署命令,避免 git 误解析参数

- README: Windows 克隆与启动改为分行,补充单行安全写法与说明
- start.ps1: 无 Git 时 winget/choco 自动安装、PATH 刷新、UTF-8 BOM 与文件头使用说明

Made-with: Cursor
This commit is contained in:
2026-04-10 16:31:44 +08:00
parent a59b3930bb
commit ce042333c4
2 changed files with 129 additions and 14 deletions
+109 -6
View File
@@ -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
}