Atualizacao Pilot_Installer_Utilities
This commit is contained in:
@@ -140,81 +140,61 @@ try {
|
|||||||
|
|
||||||
$env:GIT_TERMINAL_PROMPT = '0'
|
$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..."
|
Write-Info "Primeira execução. Clonando repositório..."
|
||||||
|
if (Test-Path $WorkDir) { Remove-Item $WorkDir -Recurse -Force -ErrorAction SilentlyContinue }
|
||||||
if (Test-Path -LiteralPath $WorkDir) {
|
|
||||||
Remove-Item -LiteralPath $WorkDir -Recurse -Force -ErrorAction SilentlyContinue
|
|
||||||
}
|
|
||||||
|
|
||||||
Ensure-Dir $WorkDir
|
Ensure-Dir $WorkDir
|
||||||
|
|
||||||
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) clone --depth 1 --branch $Branch $RepoUrl $WorkDir
|
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) clone --depth 1 --branch $Branch $RepoUrl $WorkDir
|
||||||
|
if ($LASTEXITCODE -ne 0 -or -not (Test-Path $GitDir)) {
|
||||||
if (-not (Test-Path -LiteralPath (Join-Path $WorkDir '.git'))) {
|
throw "Falha ao clonar o repositório."
|
||||||
throw "Falha ao clonar repositório."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$NeedCopy = $true
|
$NeedCopy = $true
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
Write-Info "Verificando atualizações..."
|
|
||||||
|
|
||||||
Push-Location $WorkDir
|
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
|
& git diff --quiet HEAD ("origin/" + $Branch)
|
||||||
|
$DiffExit = $LASTEXITCODE
|
||||||
|
|
||||||
$LocalCommit = (& git rev-parse HEAD).Trim()
|
switch ($DiffExit) {
|
||||||
$RemoteCommit = (& git rev-parse ("origin/" + $Branch)).Trim()
|
0 {
|
||||||
|
Write-Ok "Repositório já está atualizado."
|
||||||
if ($LocalCommit -ne $RemoteCommit) {
|
}
|
||||||
|
1 {
|
||||||
Write-Info "Nova versão encontrada."
|
Write-Info "Atualizações encontradas."
|
||||||
|
& git reset --hard ("origin/" + $Branch)
|
||||||
& git reset --hard ("origin/" + $Branch)
|
if ($LASTEXITCODE -ne 0) { throw "git reset falhou." }
|
||||||
|
& git clean -fd
|
||||||
$NeedCopy = $true
|
$NeedCopy = $true
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
throw "Falha ao comparar versões do Git."
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
finally { Pop-Location }
|
||||||
|
}
|
||||||
|
|
||||||
Write-Ok "Repositório já está atualizado."
|
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."
|
||||||
|
}
|
||||||
|
|
||||||
$NeedCopy = $false
|
# ===== GARANTE A ATUALIZAÇÃO DOS ARQUIVOS PRINCIPAIS =====
|
||||||
}
|
|
||||||
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ===== FORÇA A ATUALIZAÇÃO DOS ARQUIVOS PRINCIPAIS =====
|
|
||||||
$SourceInstallScript = Join-Path $WorkDir 'pilot_install.ps1'
|
$SourceInstallScript = Join-Path $WorkDir 'pilot_install.ps1'
|
||||||
$TargetInstallScript = Join-Path $TargetDir 'pilot_install.ps1'
|
$TargetInstallScript = Join-Path $TargetDir 'pilot_install.ps1'
|
||||||
$SourceUtilityScript = Join-Path $WorkDir 'pilot_installer_utilities.ps1'
|
$SourceUtilityScript = Join-Path $WorkDir 'pilot_installer_utilities.ps1'
|
||||||
|
|||||||
Reference in New Issue
Block a user