-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
116 lines (106 loc) Β· 6.29 KB
/
Copy pathinstall.ps1
File metadata and controls
116 lines (106 loc) Β· 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# pgflow β Windows installer (PowerShell)
#
# Descarga el binario prebuilt desde GitHub Releases (NO necesitas Go).
# Si lo corres dentro de un clon del repo y falla la descarga, compila del cΓ³digo.
#
# Uso (one-liner):
# irm https://raw.githubusercontent.com/ander0code/pgflow/main/install.ps1 | iex
#
# Uso local:
# .\install.ps1
# $env:PGFLOW_INSTALL_DIR = "C:\Tools"; .\install.ps1
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[CmdletBinding()]
param([string]$InstallDir = $env:PGFLOW_INSTALL_DIR)
$ErrorActionPreference = "Stop"
$Repo = "ander0code/pgflow"
$ToolName = "pgflow"
if (-not $InstallDir) { $InstallDir = Join-Path $env:LOCALAPPDATA "pgflow" }
Write-Host ""
Write-Host "π Instalando pgflow (Windows)..."
# ββ detectar arquitectura βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
$arch = if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "amd64" }
$asset = "$ToolName-windows-$arch.exe"
$url = "https://github.com/$Repo/releases/latest/download/$asset"
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
$dest = Join-Path $InstallDir "$ToolName.exe"
# ββ descargar binario prebuilt + checksums.txt, verificar SHA256 ββββββββββββββ
$ReleaseBase = "https://github.com/$Repo/releases/latest/download"
$ChecksumsUrl = "$ReleaseBase/checksums.txt"
$TmpBin = Join-Path $env:TEMP "pgflow-install.exe"
$TmpChecksums = Join-Path $env:TEMP "pgflow-checksums.txt"
$downloaded = $false
$downloadError = $null
try {
Invoke-WebRequest -Uri $url -OutFile $TmpBin -UseBasicParsing
try {
Invoke-WebRequest -Uri $ChecksumsUrl -OutFile $TmpChecksums -UseBasicParsing
} catch { $ChecksumsUrl = $null } # release may exist without checksums yet
$line = if ($ChecksumsUrl) { Select-String -Path $TmpChecksums -Pattern " $asset$" | Select-Object -First 1 } else { $null }
if ($line) {
$expected = ($line -split '\s+')[0].ToLower()
$actual = (Get-FileHash -Algorithm SHA256 -Path $TmpBin).Hash.ToLower()
if ($actual -eq $expected) {
Write-Host "β
SHA256 verificado" -ForegroundColor Green
Move-Item -Path $TmpBin -Destination $dest -Force
$downloaded = $true
Write-Host ("β
Descargado e instalado β " + $dest) -ForegroundColor Green
} else {
Write-Host "β SHA256 no coincide (esperado $expected, obtuve $actual)." -ForegroundColor Red
Write-Host " La descarga puede estar comprometida. Mira: $ReleaseBase"
Remove-Item -Path $TmpBin -ErrorAction SilentlyContinue
exit 1
}
} elseif ($ChecksumsUrl) {
Write-Host "β οΈ checksums.txt no incluye $asset β instalo sin verificaciΓ³n." -ForegroundColor Yellow
Move-Item -Path $TmpBin -Destination $dest -Force
$downloaded = $true
Write-Host ("β
Descargado e instalado β " + $dest) -ForegroundColor Green
} else {
Write-Host "β οΈ No hay checksums.txt en el release β instalo sin verificaciΓ³n." -ForegroundColor Yellow
Move-Item -Path $TmpBin -Destination $dest -Force
$downloaded = $true
Write-Host ("β
Descargado e instalado β " + $dest) -ForegroundColor Green
}
} catch {
$downloadError = $_
Write-Host ("β οΈ No se pudo descargar (" + $url + "): " + $_.Exception.Message) -ForegroundColor Yellow
Remove-Item -Path $TmpBin -ErrorAction SilentlyContinue
}
# ββ fallback: compilar del cΓ³digo si hay Go y estamos en un clon ββββββββββββββββββ
if (-not $downloaded) {
$go = Get-Command go -ErrorAction SilentlyContinue
if ($go -and $PSScriptRoot -and (Test-Path (Join-Path $PSScriptRoot "go.mod"))) {
Write-Host "π¨ Compilando desde el cΓ³digo (go build)..." -ForegroundColor Cyan
Push-Location $PSScriptRoot
try { go build -ldflags="-s -w" -o $dest . } finally { Pop-Location }
Write-Host ("β
Compilado e instalado β " + $dest) -ForegroundColor Green
} else {
Write-Host " Para verificar el binario, clona el repo y corre:"
Write-Host " Get-FileHash dist\pgflow-windows-amd64.exe -Algorithm SHA256"
Write-Host " y compara con https://github.com/$Repo/releases/latest/download/checksums.txt"
Write-Host " O instala Go y reintenta el instalador."
exit 1
}
}
# ββ deps de runtime (solo aviso) ββββββββββββββββββββββββββββββββββββββββββββββββββ
$missing = @()
foreach ($dep in @("psql", "pg_dump", "pg_restore", "ssh")) {
if (-not (Get-Command $dep -ErrorAction SilentlyContinue)) { $missing += $dep }
}
if ($missing.Count -gt 0) {
Write-Host ("β οΈ Faltan herramientas en runtime: " + ($missing -join ", ")) -ForegroundColor Yellow
Write-Host " PostgreSQL client: https://www.postgresql.org/download/windows/"
Write-Host " OpenSSH client: Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0"
}
# ββ PATH ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -notlike "*$InstallDir*") {
Write-Host ""
Write-Host "β οΈ $InstallDir no estΓ‘ en tu PATH (usuario). Para aΓ±adirlo:" -ForegroundColor Yellow
Write-Host " [Environment]::SetEnvironmentVariable('Path',`"$InstallDir;`" + [Environment]::GetEnvironmentVariable('Path','User'),'User')"
Write-Host " Luego abre una NUEVA ventana de PowerShell."
}
Write-Host ""
Write-Host "π Listo. Ejecuta: pgflow (ayuda: pgflow --help)" -ForegroundColor Green