Atualizacao Pilot_Installer_Utilities
This commit is contained in:
@@ -140,81 +140,61 @@ try {
|
||||
|
||||
$env:GIT_TERMINAL_PROMPT = '0'
|
||||
|
||||
|
||||
# ===== AUTOATUALIZAÇÃO =====
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $WorkDir '.git'))) {
|
||||
|
||||
Write-Info "Primeira execução. Clonando repositório..."
|
||||
|
||||
if (Test-Path -LiteralPath $WorkDir) {
|
||||
Remove-Item -LiteralPath $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."
|
||||
}
|
||||
|
||||
$NeedCopy = $true
|
||||
}
|
||||
else {
|
||||
|
||||
Write-Info "Verificando atualizações..."
|
||||
|
||||
Push-Location $WorkDir
|
||||
|
||||
& 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 reset --hard ("origin/" + $Branch)
|
||||
|
||||
$NeedCopy = $true
|
||||
}
|
||||
else {
|
||||
|
||||
Write-Ok "Repositório já está atualizado."
|
||||
|
||||
$NeedCopy = $false
|
||||
}
|
||||
$GitDir = Join-Path $WorkDir '.git'
|
||||
|
||||
Pop-Location
|
||||
if (-not (Test-Path -LiteralPath $GitDir)) {
|
||||
Write-Info "Primeira execução. Clonando repositório..."
|
||||
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 ($LASTEXITCODE -ne 0 -or -not (Test-Path $GitDir)) {
|
||||
throw "Falha ao clonar o repositório."
|
||||
}
|
||||
$NeedCopy = $true
|
||||
}
|
||||
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 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
|
||||
}
|
||||
default {
|
||||
throw "Falha ao comparar versões do Git."
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { 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."
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Ok "Nenhuma alteração encontrada."
|
||||
}
|
||||
copy: $LASTEXITCODE) Log: $CopyLog"
|
||||
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."
|
||||
}
|
||||
|
||||
# ===== FORÇA A ATUALIZAÇÃO DOS ARQUIVOS PRINCIPAIS =====
|
||||
# ===== GARANTE 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'
|
||||
|
||||
Reference in New Issue
Block a user