Atualizacao Pilot_Installer_Utilities

This commit is contained in:
2026-07-21 15:23:09 -03:00
parent b622804b03
commit abc2566eb8

View File

@@ -140,81 +140,61 @@ try {
$env:GIT_TERMINAL_PROMPT = '0'
# ===== AUTOATUALIZAÇÃO =====
if (-not (Test-Path -LiteralPath (Join-Path $WorkDir '.git'))) {
# ===== AUTOATUALIZAÇÃO =====
$NeedCopy = $false
$GitDir = Join-Path $WorkDir '.git'
if (-not (Test-Path -LiteralPath $GitDir)) {
Write-Info "Primeira execução. Clonando repositório..."
if (Test-Path -LiteralPath $WorkDir) {
Remove-Item -LiteralPath $WorkDir -Recurse -Force -ErrorAction SilentlyContinue
}
if (Test-Path $WorkDir) { Remove-Item $WorkDir -Recurse -Force -ErrorAction SilentlyContinue }
Ensure-Dir $WorkDir
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) clone --depth 1 --branch $Branch $RepoUrl $WorkDir
if (-not (Test-Path -LiteralPath (Join-Path $WorkDir '.git'))) {
throw "Falha ao clonar repositório."
if ($LASTEXITCODE -ne 0 -or -not (Test-Path $GitDir)) {
throw "Falha ao clonar o repositório."
}
$NeedCopy = $true
}
else {
Write-Info "Verificando atualizações..."
}
else {
Push-Location $WorkDir
try {
Write-Info "Verificando atualizações..."
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) fetch --prune origin $Branch
if ($LASTEXITCODE -ne 0) { throw "git fetch falhou." }
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) fetch origin $Branch
$LocalCommit = (& git rev-parse HEAD).Trim()
$RemoteCommit = (& git rev-parse ("origin/" + $Branch)).Trim()
if ($LocalCommit -ne $RemoteCommit) {
Write-Info "Nova versão encontrada."
& git diff --quiet HEAD ("origin/" + $Branch)
$DiffExit = $LASTEXITCODE
switch ($DiffExit) {
0 {
Write-Ok "Repositório já está atualizado."
}
1 {
Write-Info "Atualizações encontradas."
& git reset --hard ("origin/" + $Branch)
if ($LASTEXITCODE -ne 0) { throw "git reset falhou." }
& git clean -fd
$NeedCopy = $true
}
else {
Write-Ok "Repositório já está atualizado."
$NeedCopy = $false
}
Pop-Location
}
if ($NeedCopy) {
Write-Info "Copiando arquivos para $TargetDir..."
$rc = robocopy `
$WorkDir `
$TargetDir `
* `
/E /IS /IT /R:1 /W:1 /NFL /NDL /NP `
/XD ".git" `
/XF ".gitignore" ".gitattributes" `
/LOG:$CopyLog
if ($LASTEXITCODE -ge 8) {
throw "Falha ao copiar arquivos. Veja o log: $CopyLog"
}
else {
Write-Ok "Cópia concluída."
default {
throw "Falha ao comparar versões do Git."
}
}
else {
Write-Ok "Nenhuma alteração encontrada."
}
copy: $LASTEXITCODE) Log: $CopyLog"
}
finally { Pop-Location }
}
if ($NeedCopy) {
Write-Info "Atualizando arquivos em $TargetDir..."
$null = robocopy $WorkDir $TargetDir * /E /IS /IT /R:1 /W:1 /NFL /NDL /NP /XD ".git" /XF ".gitignore" ".gitattributes" /LOG:$CopyLog
if ($LASTEXITCODE -ge 8) { throw "Falha ao copiar arquivos. Veja o log: $CopyLog" }
Write-Ok "Arquivos atualizados."
} else {
Write-Ok "Nenhuma atualização necessária."
}
# ===== GARANTE A ATUALIZAÇÃO DOS ARQUIVOS PRINCIPAIS =====
# ===== FORÇA A ATUALIZAÇÃO DOS ARQUIVOS PRINCIPAIS =====
$SourceInstallScript = Join-Path $WorkDir 'pilot_install.ps1'
$TargetInstallScript = Join-Path $TargetDir 'pilot_install.ps1'
$SourceUtilityScript = Join-Path $WorkDir 'pilot_installer_utilities.ps1'