部署脚本不依赖本机 git,winget/choco 安装与 PATH 刷新已无必要。 Made-with: Cursor
This commit is contained in:
@@ -151,81 +151,6 @@ function Setup-EnvFiles {
|
|||||||
Ok ".env configured for IP=$($script:DeployIP)"
|
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 {
|
function Test-DockerInstalled {
|
||||||
$docker = Get-Command docker -ErrorAction SilentlyContinue
|
$docker = Get-Command docker -ErrorAction SilentlyContinue
|
||||||
if (-not $docker) { return $false }
|
if (-not $docker) { return $false }
|
||||||
@@ -346,7 +271,6 @@ function Start-Services {
|
|||||||
|
|
||||||
function Main {
|
function Main {
|
||||||
Init-ProjectDir
|
Init-ProjectDir
|
||||||
Ensure-Git
|
|
||||||
|
|
||||||
if ((Test-Path ".env") -and -not $env:DEPLOY_FORCE_RECONFIG -and -not $env:DEPLOY_IP) {
|
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()
|
$answer = (Read-Host "Existing .env found. Reconfigure? [y/N]").Trim().ToLower()
|
||||||
|
|||||||
Reference in New Issue
Block a user