#Requires -Version 5.1 $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $repo = 'ggonn-arg/gonix' $apiUrl = "https://api.github.com/repos/$repo/releases/latest" $esAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator ) if (-not $esAdmin) { $launcherPath = $PSCommandPath $temporaryLauncher = $null try { if (-not $launcherPath) { $temporaryLauncher = Join-Path $env:TEMP ("gonix-launcher-{0}.ps1" -f [guid]::NewGuid()) Invoke-WebRequest -Uri 'https://ggonn-arg.github.io/gonix/win.txt' ` -OutFile $temporaryLauncher -UseBasicParsing $launcherPath = $temporaryLauncher } $argumentos = '-NoProfile -ExecutionPolicy Bypass -File "{0}"' -f $launcherPath Start-Process -FilePath 'powershell.exe' -ArgumentList $argumentos -Verb RunAs -Wait } catch { Write-Host " [X] No se pudo elevar Gonix: $($_.Exception.Message)" -ForegroundColor Red Read-Host ' Enter para salir' | Out-Null } finally { if ($temporaryLauncher) { Remove-Item -LiteralPath $temporaryLauncher -Force -ErrorAction SilentlyContinue } } return } $base = Join-Path $env:TEMP ("gonix-{0}" -f [guid]::NewGuid()) $zip = Join-Path $env:TEMP ("gonix-{0}.zip" -f [guid]::NewGuid()) $checksumFile = "$zip.sha256" try { try { $release = Invoke-RestMethod -Uri $apiUrl -Headers @{ Accept = 'application/vnd.github+json' 'User-Agent' = 'Gonix' } } catch { if ($_.Exception.Response -and [int]$_.Exception.Response.StatusCode -eq 404) { throw 'No hay un Release publicado de Gonix. El lanzador requiere un Release con gonix.zip y su SHA-256.' } throw } $zipAsset = @($release.assets | Where-Object { $_.name -ceq 'gonix.zip' }) | Select-Object -First 1 $checksumAsset = @($release.assets | Where-Object { $_.name -ceq 'gonix.zip.sha256' }) | Select-Object -First 1 if (-not $zipAsset -or -not $checksumAsset) { throw "El Release '$($release.tag_name)' no contiene gonix.zip y gonix.zip.sha256." } foreach ($asset in @($zipAsset, $checksumAsset)) { $uri = [Uri]$asset.browser_download_url if ($uri.Scheme -cne 'https' -or $uri.Host -cne 'github.com') { throw "GitHub devolvió una URL de descarga no válida para '$($asset.name)'." } } New-Item -ItemType Directory -Path $base -Force | Out-Null Invoke-WebRequest -Uri $zipAsset.browser_download_url -OutFile $zip -UseBasicParsing Invoke-WebRequest -Uri $checksumAsset.browser_download_url -OutFile $checksumFile -UseBasicParsing $checksum = Get-Content -LiteralPath $checksumFile -Raw -Encoding ASCII if ($checksum -notmatch '^\s*([A-Fa-f0-9]{64})\s+\*?gonix\.zip\s*$') { throw 'El archivo gonix.zip.sha256 tiene un formato inválido.' } $expectedHash = $Matches[1].ToUpperInvariant() $actualHash = (Get-FileHash -LiteralPath $zip -Algorithm SHA256).Hash.ToUpperInvariant() if ($actualHash -cne $expectedHash) { throw 'El SHA-256 de gonix.zip no coincide con el publicado.' } Expand-Archive -LiteralPath $zip -DestinationPath $base -Force $script = Get-ChildItem -LiteralPath $base -Filter Gonix.ps1 -Recurse -File | Select-Object -First 1 if (-not $script) { throw "El Release '$($release.tag_name)' no contiene Gonix.ps1." } Write-Host " Ejecutando Gonix desde el Release $($release.tag_name) (SHA-256 verificado)..." -ForegroundColor Cyan & powershell.exe -NoProfile -ExecutionPolicy Bypass -File $script.FullName } catch { Write-Host " [X] $($_.Exception.Message)" -ForegroundColor Red Read-Host ' Enter para salir' | Out-Null } finally { Remove-Item -LiteralPath $zip -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath $checksumFile -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath $base -Recurse -Force -ErrorAction SilentlyContinue }