atualização para liberação do arquivo, sempre que baixá-lo
This commit is contained in:
@@ -2,29 +2,34 @@
|
|||||||
Atualiza C:\PilotDownloads\ com o conteúdo do repositório (branch main)
|
Atualiza C:\PilotDownloads\ com o conteúdo do repositório (branch main)
|
||||||
https://gitea.magicis.com.br/PilotSupport/vlt-install e executa pilot_install.ps1
|
https://gitea.magicis.com.br/PilotSupport/vlt-install e executa pilot_install.ps1
|
||||||
|
|
||||||
Recursos:
|
Ajuste as variáveis $GitUser e $GitToken conforme necessário.
|
||||||
- Instala/atualiza Git via winget
|
|
||||||
- Evita abrir navegador (sem prompts do GCM)
|
|
||||||
- Suporte a token do Gitea (param ou arquivo)
|
|
||||||
- Copia por cima (não espelha)
|
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param(
|
# ========= CONFIGURAÇÃO DE USUÁRIO/TOKEN =========
|
||||||
[string]$GitUser, # opcional: usuário do Gitea
|
$GitUser = "ricardo.sarda" # coloque aqui seu usuário do Gitea
|
||||||
[string]$GitToken, # opcional: PAT do Gitea
|
$GitToken = "d6504f7d969c77a51dcbd5854a1f37f0a96398cd" # coloque aqui o Personal Access Token do Gitea
|
||||||
[string]$GitTokenPath # opcional: caminho de arquivo contendo somente o token
|
# ================================================
|
||||||
)
|
|
||||||
|
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
# ===== Auto-desbloqueio (MOTW) =====
|
||||||
|
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 =====
|
# ===== Configurações =====
|
||||||
$RepoUrl = 'https://gitea.magicis.com.br/PilotSupport/vlt-install' # sem credenciais na URL
|
|
||||||
|
$RepoUrl = 'https://gitea.magicis.com.br/PilotSupport/vlt-install'
|
||||||
$Branch = 'main'
|
$Branch = 'main'
|
||||||
$TargetDir = 'C:\PilotDownloads'
|
$TargetDir = 'C:\PilotDownloads'
|
||||||
$WorkDir = Join-Path $env:TEMP 'vlt-install_repo'
|
$WorkDir = Join-Path $env:TEMP 'vlt-install_repo'
|
||||||
$CopyLog = Join-Path $env:TEMP 'vlt-install_copy.log'
|
$CopyLog = Join-Path $env:TEMP 'vlt-install_copy.log'
|
||||||
|
|
||||||
# ===== Utilitárias =====
|
|
||||||
function Write-Info($m){ Write-Host "[INFO ] $m" -ForegroundColor Cyan }
|
function Write-Info($m){ Write-Host "[INFO ] $m" -ForegroundColor Cyan }
|
||||||
function Write-Ok($m) { Write-Host "[ OK ] $m" -ForegroundColor Green }
|
function Write-Ok($m) { Write-Host "[ OK ] $m" -ForegroundColor Green }
|
||||||
function Write-Warn($m){ Write-Host "[WARN ] $m" -ForegroundColor Yellow }
|
function Write-Warn($m){ Write-Host "[WARN ] $m" -ForegroundColor Yellow }
|
||||||
@@ -40,17 +45,16 @@ function Test-Winget { [bool](Get-Command winget -ErrorAction SilentlyContinue)
|
|||||||
|
|
||||||
function Ensure-Git-WithWinget {
|
function Ensure-Git-WithWinget {
|
||||||
if (-not (Test-Winget)) {
|
if (-not (Test-Winget)) {
|
||||||
Write-Err "winget não encontrado. Instale o 'App Installer' pela Microsoft Store para habilitar o winget."
|
Write-Err "winget não encontrado. Instale o 'App Installer' da Microsoft Store."
|
||||||
throw "winget ausente"
|
throw "winget ausente"
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Info "Verificando Git via winget..."
|
Write-Info "Verificando Git via winget..."
|
||||||
$argsCommon = @('--accept-package-agreements','--accept-source-agreements','--silent')
|
$argsCommon = @('--accept-package-agreements','--accept-source-agreements','--silent')
|
||||||
|
|
||||||
# Detecta se Git está instalado
|
|
||||||
$gitInstalled = $false
|
$gitInstalled = $false
|
||||||
try {
|
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 }
|
if ($list -match 'Git\s+Git') { $gitInstalled = $true }
|
||||||
} catch { }
|
} catch { }
|
||||||
|
|
||||||
@@ -62,7 +66,6 @@ function Ensure-Git-WithWinget {
|
|||||||
& winget install --id Git.Git -e @argsCommon | Out-Null
|
& winget install --id Git.Git -e @argsCommon | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
# Garante PATH do git
|
|
||||||
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
|
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
|
||||||
$maybeGit = 'C:\Program Files\Git\cmd\git.exe'
|
$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" }
|
||||||
@@ -73,17 +76,6 @@ function Ensure-Git-WithWinget {
|
|||||||
Write-Ok "Git pronto: $ver"
|
Write-Ok "Git pronto: $ver"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-GitTokenEffective {
|
|
||||||
if ($GitToken) { return $GitToken }
|
|
||||||
if ($GitTokenPath) {
|
|
||||||
if (-not (Test-Path -LiteralPath $GitTokenPath)) {
|
|
||||||
throw "Arquivo de token não encontrado: $GitTokenPath"
|
|
||||||
}
|
|
||||||
return (Get-Content -LiteralPath $GitTokenPath -Raw).Trim()
|
|
||||||
}
|
|
||||||
return $null
|
|
||||||
}
|
|
||||||
|
|
||||||
function Get-BasicAuthHeader([string]$user,[string]$token){
|
function Get-BasicAuthHeader([string]$user,[string]$token){
|
||||||
if (-not $user -or -not $token) { return $null }
|
if (-not $user -or -not $token) { return $null }
|
||||||
$bytes = [Text.Encoding]::ASCII.GetBytes("$user`:$token")
|
$bytes = [Text.Encoding]::ASCII.GetBytes("$user`:$token")
|
||||||
@@ -94,47 +86,32 @@ function Get-BasicAuthHeader([string]$user,[string]$token){
|
|||||||
function Get-GitCommonArgs {
|
function Get-GitCommonArgs {
|
||||||
param([string]$AuthHeader)
|
param([string]$AuthHeader)
|
||||||
|
|
||||||
# Evita prompts/UI/navegador e askpass
|
|
||||||
$args = @(
|
$args = @(
|
||||||
'-c','credential.helper=',
|
'-c','credential.helper=',
|
||||||
'-c','credential.interactive=never',
|
'-c','credential.interactive=never',
|
||||||
'-c','core.askPass='
|
'-c','core.askPass='
|
||||||
)
|
)
|
||||||
|
|
||||||
# Se fornecer header, usa-o nesta chamada (não grava no .git/config)
|
|
||||||
if ($AuthHeader) {
|
if ($AuthHeader) {
|
||||||
$args += @('-c',"http.extraHeader=$AuthHeader")
|
$args += @('-c',"http.extraHeader=$AuthHeader")
|
||||||
}
|
}
|
||||||
return ,$args
|
return ,$args
|
||||||
}
|
}
|
||||||
|
|
||||||
# ===== Início =====
|
|
||||||
try {
|
try {
|
||||||
# Auto-desbloqueia este arquivo (elimina marca de internet se houver)
|
|
||||||
try { Unblock-File -LiteralPath $MyInvocation.MyCommand.Path -ErrorAction SilentlyContinue } catch { }
|
|
||||||
|
|
||||||
Ensure-Git-WithWinget
|
Ensure-Git-WithWinget
|
||||||
Ensure-Dir $TargetDir
|
Ensure-Dir $TargetDir
|
||||||
|
|
||||||
# Prepara credenciais (opcionais)
|
|
||||||
$EffectiveToken = Get-GitTokenEffective
|
|
||||||
if ($GitUser -and -not $EffectiveToken) {
|
|
||||||
Write-Warn "GitUser informado mas nenhum token fornecido. Continuação sem autenticação."
|
|
||||||
}
|
|
||||||
$AuthHeader = $null
|
$AuthHeader = $null
|
||||||
if ($GitUser -and $EffectiveToken) {
|
if ($GitUser -and $GitToken) {
|
||||||
$AuthHeader = Get-BasicAuthHeader -user $GitUser -token $EffectiveToken
|
$AuthHeader = Get-BasicAuthHeader -user $GitUser -token $GitToken
|
||||||
Write-Info "Usando autenticação via header (sem gravar credenciais em .git/config)."
|
Write-Info "Usando autenticação com header."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Nunca abrir prompts/navegador
|
|
||||||
$env:GIT_TERMINAL_PROMPT = '0'
|
$env:GIT_TERMINAL_PROMPT = '0'
|
||||||
|
|
||||||
# Clone/Update
|
|
||||||
if (Test-Path (Join-Path $WorkDir '.git')) {
|
if (Test-Path (Join-Path $WorkDir '.git')) {
|
||||||
Write-Info "Atualizando repositório em $WorkDir ..."
|
Write-Info "Atualizando repositório em $WorkDir ..."
|
||||||
Push-Location $WorkDir
|
Push-Location $WorkDir
|
||||||
try { & git (Get-GitCommonArgs -AuthHeader $AuthHeader) remote set-url origin $RepoUrl | Out-Null } catch { }
|
|
||||||
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) fetch --all --prune
|
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) fetch --all --prune
|
||||||
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) checkout $Branch
|
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) checkout $Branch
|
||||||
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) reset --hard "origin/$Branch"
|
& git (Get-GitCommonArgs -AuthHeader $AuthHeader) reset --hard "origin/$Branch"
|
||||||
@@ -147,7 +124,6 @@ try {
|
|||||||
Write-Ok "Clone concluído."
|
Write-Ok "Clone concluído."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Copiar por cima (sem espelhar)
|
|
||||||
Write-Info "Copiando arquivos para $TargetDir (sem espelhar)..."
|
Write-Info "Copiando arquivos para $TargetDir (sem espelhar)..."
|
||||||
$rc = robocopy `
|
$rc = robocopy `
|
||||||
$WorkDir `
|
$WorkDir `
|
||||||
@@ -165,7 +141,6 @@ try {
|
|||||||
Write-Ok "Cópia finalizada. (código robocopy: $LASTEXITCODE) Log: $CopyLog"
|
Write-Ok "Cópia finalizada. (código robocopy: $LASTEXITCODE) Log: $CopyLog"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Executa o instalador
|
|
||||||
$InstallScript = Join-Path $TargetDir 'pilot_install.ps1'
|
$InstallScript = Join-Path $TargetDir 'pilot_install.ps1'
|
||||||
if (Test-Path -LiteralPath $InstallScript) {
|
if (Test-Path -LiteralPath $InstallScript) {
|
||||||
Write-Info "Executando $InstallScript ..."
|
Write-Info "Executando $InstallScript ..."
|
||||||
@@ -190,6 +165,5 @@ try {
|
|||||||
Write-Err ("Erro: " + $_.Exception.Message)
|
Write-Err ("Erro: " + $_.Exception.Message)
|
||||||
exit 1
|
exit 1
|
||||||
} finally {
|
} finally {
|
||||||
# Limpa variáveis sensíveis do ambiente
|
|
||||||
Remove-Item Env:\GIT_TERMINAL_PROMPT -ErrorAction SilentlyContinue
|
Remove-Item Env:\GIT_TERMINAL_PROMPT -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user