From 6305ad5acfeb954946b934b645231535ae005e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Sard=C3=A1?= Date: Fri, 20 Mar 2026 15:51:38 -0300 Subject: [PATCH] atualizacao scripts --- pilot_install.ps1 | 8 +++ pilot_installer_utilities.ps1 | 108 ++++++++++++++++++++++++---------- 2 files changed, 86 insertions(+), 30 deletions(-) diff --git a/pilot_install.ps1 b/pilot_install.ps1 index cd0ef0a..c6a535f 100644 --- a/pilot_install.ps1 +++ b/pilot_install.ps1 @@ -134,6 +134,14 @@ function Install-Pilot { } else { Write-Log "Could not retrieve MAC address.`n" } + + Write-Log "`nSetting main connectio as PRIVATE..." + Get-NetConnectionProfile | Where-Object {$_.InterfaceAlias -like "*Ethernet*"} | Set-NetConnectionProfile -NetworkCategory Private + + + Write-Log "`nAdjusting System Time..." + w32tm /resync /force + Write-Log "Stopping PilotGameAgent service..." Stop-Service -Name "PilotGameAgent" -Force -ErrorAction SilentlyContinue diff --git a/pilot_installer_utilities.ps1 b/pilot_installer_utilities.ps1 index c057fd0..31fc0aa 100644 --- a/pilot_installer_utilities.ps1 +++ b/pilot_installer_utilities.ps1 @@ -6,8 +6,8 @@ #> # ========= CONFIGURAÇÃO DE USUÁRIO/TOKEN ========= -$GitUser = "ricardo.sarda" # coloque aqui seu usuário do Gitea -$GitToken = "d6504f7d969c77a51dcbd5854a1f37f0a96398cd" # coloque aqui o Personal Access Token do Gitea +$GitUser = "ricardo.sarda" +$GitToken = "d6504f7d969c77a51dcbd5854a1f37f0a96398cd" # ================================================ $ErrorActionPreference = 'Stop' @@ -17,13 +17,11 @@ try { $scriptPath = $MyInvocation.MyCommand.Path if ($scriptPath -and (Test-Path -LiteralPath $scriptPath)) { Unblock-File -LiteralPath $scriptPath -ErrorAction SilentlyContinue - # remove explicitamente o ADS se existir (não falha se não existir) Remove-Item -LiteralPath "$scriptPath`:Zone.Identifier" -Force -ErrorAction SilentlyContinue } } catch {} # ===== Configurações ===== - $RepoUrl = 'https://gitea.magicis.com.br/PilotSupport/vlt-install' $Branch = 'main' $TargetDir = 'C:\PilotDownloads' @@ -54,7 +52,7 @@ function Ensure-Git-WithWinget { $gitInstalled = $false try { - $list = winget list --id Git.Git -e @argsCommon 2>$null + $list = winget list --id Git.Git -e 2>$null if ($list -match 'Git\s+Git') { $gitInstalled = $true } } catch { } @@ -68,7 +66,9 @@ function Ensure-Git-WithWinget { if (-not (Get-Command git -ErrorAction SilentlyContinue)) { $maybeGit = 'C:\Program Files\Git\cmd\git.exe' - if (Test-Path $maybeGit) { $env:Path = "C:\Program Files\Git\cmd;$env:Path" } + if (Test-Path $maybeGit) { + $env:Path = "C:\Program Files\Git\cmd;$env:Path" + } } $ver = git --version 2>$null @@ -97,6 +97,37 @@ function Get-GitCommonArgs { return ,$args } +function Force-ReplaceFile { + param( + [Parameter(Mandatory = $true)][string]$SourceFile, + [Parameter(Mandatory = $true)][string]$TargetFile + ) + + if (-not (Test-Path -LiteralPath $SourceFile)) { + throw "Arquivo de origem não encontrado: $SourceFile" + } + + $targetParent = Split-Path -Path $TargetFile -Parent + Ensure-Dir $targetParent + + if (Test-Path -LiteralPath $TargetFile) { + Remove-Item -LiteralPath $TargetFile -Force -ErrorAction SilentlyContinue + } + + Copy-Item -LiteralPath $SourceFile -Destination $TargetFile -Force + Unblock-File -LiteralPath $TargetFile -ErrorAction SilentlyContinue + + $srcHash = (Get-FileHash -LiteralPath $SourceFile -Algorithm SHA256).Hash + $dstHash = (Get-FileHash -LiteralPath $TargetFile -Algorithm SHA256).Hash + + Write-Info "Hash origem : $srcHash" + Write-Info "Hash destino: $dstHash" + + if ($srcHash -ne $dstHash) { + throw "Validação por hash falhou para: $TargetFile" + } +} + try { Ensure-Git-WithWinget Ensure-Dir $TargetDir @@ -109,21 +140,25 @@ try { $env:GIT_TERMINAL_PROMPT = '0' - if (Test-Path (Join-Path $WorkDir '.git')) { - Write-Info "Atualizando repositório em $WorkDir ..." - Push-Location $WorkDir - & git (Get-GitCommonArgs -AuthHeader $AuthHeader) fetch --all --prune - & git (Get-GitCommonArgs -AuthHeader $AuthHeader) checkout $Branch - & git (Get-GitCommonArgs -AuthHeader $AuthHeader) reset --hard "origin/$Branch" - Pop-Location - } else { - Write-Info "Clonando repositório (branch $Branch) para $WorkDir ..." - try { Remove-Item -LiteralPath $WorkDir -Recurse -Force -ErrorAction SilentlyContinue } catch { } - Ensure-Dir $WorkDir - & git (Get-GitCommonArgs -AuthHeader $AuthHeader) clone --depth 1 --branch $Branch $RepoUrl $WorkDir - Write-Ok "Clone concluído." + # ===== AUTOATUALIZAÇÃO FORÇADA ===== + Write-Info "Preparando diretório temporário para clone limpo..." + + if (Test-Path -LiteralPath $WorkDir) { + Write-Info "Removendo diretório temporário antigo..." + Remove-Item -LiteralPath $WorkDir -Recurse -Force -ErrorAction SilentlyContinue } + Ensure-Dir $WorkDir + + Write-Info "Clonando repositório (branch $Branch) para $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." + } + + Write-Ok "Clone concluído." + Write-Info "Copiando arquivos para $TargetDir (sem espelhar)..." $rc = robocopy ` $WorkDir ` @@ -135,27 +170,40 @@ try { /LOG:$CopyLog if ($LASTEXITCODE -ge 8) { - Write-Err "Falha ao copiar arquivos. Veja o log: $CopyLog" - exit $LASTEXITCODE + throw "Falha ao copiar arquivos. Veja o log: $CopyLog" } else { Write-Ok "Cópia finalizada. (código robocopy: $LASTEXITCODE) Log: $CopyLog" } - $InstallScript = Join-Path $TargetDir 'pilot_install.ps1' - if (Test-Path -LiteralPath $InstallScript) { - Write-Info "Executando $InstallScript ..." - try { Unblock-File -LiteralPath $InstallScript -ErrorAction SilentlyContinue } catch { } + # ===== 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' + $TargetUtilityScript = Join-Path $TargetDir 'pilot_installer_utilities.ps1' + + Write-Info "Forçando atualização de pilot_install.ps1 ..." + Force-ReplaceFile -SourceFile $SourceInstallScript -TargetFile $TargetInstallScript + Write-Ok "pilot_install.ps1 atualizado com sucesso." + + Write-Info "Forçando atualização de pilot_installer_utilities.ps1 ..." + Force-ReplaceFile -SourceFile $SourceUtilityScript -TargetFile $TargetUtilityScript + Write-Ok "pilot_installer_utilities.ps1 atualizado com sucesso." + + if (Test-Path -LiteralPath $TargetInstallScript) { + Write-Info "Executando $TargetInstallScript ..." + try { Unblock-File -LiteralPath $TargetInstallScript -ErrorAction SilentlyContinue } catch { } $p = Start-Process -FilePath 'powershell.exe' -ArgumentList @( - '-NoProfile','-ExecutionPolicy','Bypass','-File', $InstallScript + '-NoProfile','-ExecutionPolicy','Bypass','-File', $TargetInstallScript ) -Wait -PassThru + if ($p.ExitCode -ne 0) { Write-Err "pilot_install.ps1 retornou código $($p.ExitCode)." - exit $p.ExitCode + Stop-Process -Id $PID -Force } else { Write-Ok "pilot_install.ps1 executado com sucesso." } } else { - Write-Warn "Arquivo não encontrado: $InstallScript. Execução ignorada." + Write-Warn "Arquivo não encontrado: $TargetInstallScript. Execução ignorada." } Write-Ok "Processo concluído." @@ -163,7 +211,7 @@ try { } catch { Write-Err ("Erro: " + $_.Exception.Message) - exit 1 + Stop-Process -Id $PID -Force } finally { Remove-Item Env:\GIT_TERMINAL_PROMPT -ErrorAction SilentlyContinue -} +} \ No newline at end of file