# NxusLab Toolkit - inicializador oficial # Uso: irm https://toolkit.nxuslab.com | iex $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $NxusBaseUrl = 'https://toolkit.nxuslab.com' $NxusManifestUrl = "$NxusBaseUrl/latest.json" $NxusInstallRoot = Join-Path ([Environment]::GetFolderPath('LocalApplicationData')) 'NxusLab\Toolkit' function Write-NxusMessage { param([string]$Text, [ConsoleColor]$Color = [ConsoleColor]::Gray) Write-Host "[NxusLab] $Text" -ForegroundColor $Color } function Test-NxusEnvironment { if ($PSVersionTable.PSVersion.Major -lt 5) { throw 'O NxusLab Toolkit requer PowerShell 5.1 ou superior.' } if ($ExecutionContext.SessionState.LanguageMode -ne 'FullLanguage') { throw 'A politica deste computador bloqueou a execucao em FullLanguage Mode.' } if (-not [Environment]::Is64BitOperatingSystem) { throw 'Esta versao do NxusLab Toolkit requer Windows de 64 bits.' } } function Get-NxusRemoteJson { param([string]$Uri) $response = Invoke-RestMethod -Uri $Uri -UseBasicParsing -Headers @{ 'Cache-Control' = 'no-cache' } if ($response -is [string]) { return ($response | ConvertFrom-Json) } return $response } try { try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } catch {} Test-NxusEnvironment Write-NxusMessage 'Consultando a versao mais recente...' Cyan $manifest = Get-NxusRemoteJson -Uri "$NxusManifestUrl`?t=$([DateTimeOffset]::UtcNow.ToUnixTimeSeconds())" if (-not $manifest.version -or -not $manifest.url -or -not $manifest.sha256) { throw 'O manifesto publicado esta incompleto.' } $packageUri = [Uri]$manifest.url if ($packageUri.Scheme -ne 'https' -or $packageUri.Host -ne 'toolkit.nxuslab.com') { throw 'O endereco do pacote nao pertence ao servidor oficial do NxusLab Toolkit.' } if ($manifest.sha256 -notmatch '^[A-Fa-f0-9]{64}$') { throw 'O hash SHA-256 publicado e invalido.' } $safeVersion = ([string]$manifest.version) -replace '[^0-9A-Za-z._-]', '_' $versionRoot = Join-Path $NxusInstallRoot (Join-Path 'versions' $safeVersion) $executable = Join-Path $versionRoot 'NxusLab Toolkit.exe' if (Test-Path -LiteralPath $executable) { Write-NxusMessage "Versao $($manifest.version) ja instalada. Abrindo..." Green Start-Process -FilePath $executable -WorkingDirectory $versionRoot return } $temporaryRoot = Join-Path ([IO.Path]::GetTempPath()) ("NxusLab-Toolkit-" + [Guid]::NewGuid().ToString('N')) $zipPath = Join-Path $temporaryRoot 'toolkit.zip' $stagingRoot = Join-Path $temporaryRoot 'staging' New-Item -ItemType Directory -Path $stagingRoot -Force | Out-Null try { Write-NxusMessage "Baixando NxusLab Toolkit $($manifest.version)..." Yellow Invoke-WebRequest -Uri $packageUri.AbsoluteUri -OutFile $zipPath -UseBasicParsing Write-NxusMessage 'Verificando integridade SHA-256...' Yellow $downloadHash = (Get-FileHash -LiteralPath $zipPath -Algorithm SHA256).Hash if (-not $downloadHash.Equals([string]$manifest.sha256, [StringComparison]::OrdinalIgnoreCase)) { throw "Falha de integridade. Esperado: $($manifest.sha256); recebido: $downloadHash" } Expand-Archive -LiteralPath $zipPath -DestinationPath $stagingRoot -Force $stagedExecutable = Join-Path $stagingRoot 'NxusLab Toolkit.exe' if (-not (Test-Path -LiteralPath $stagedExecutable -PathType Leaf)) { throw 'O pacote validado nao contem o executavel esperado.' } New-Item -ItemType Directory -Path (Split-Path -Parent $versionRoot) -Force | Out-Null if (Test-Path -LiteralPath $versionRoot) { Remove-Item -LiteralPath $versionRoot -Recurse -Force } Move-Item -LiteralPath $stagingRoot -Destination $versionRoot $installed = @{ version = [string]$manifest.version sha256 = $downloadHash.ToUpperInvariant() installedAt = [DateTimeOffset]::Now.ToString('o') executable = $executable } | ConvertTo-Json New-Item -ItemType Directory -Path $NxusInstallRoot -Force | Out-Null Set-Content -LiteralPath (Join-Path $NxusInstallRoot 'installed.json') -Value $installed -Encoding UTF8 Write-NxusMessage 'Integridade confirmada. Abrindo o Toolkit...' Green Start-Process -FilePath $executable -WorkingDirectory $versionRoot } finally { if (Test-Path -LiteralPath $temporaryRoot) { Remove-Item -LiteralPath $temporaryRoot -Recurse -Force -ErrorAction SilentlyContinue } } } catch { Write-NxusMessage 'Nao foi possivel iniciar o Toolkit.' Red Write-NxusMessage $_.Exception.Message Yellow throw }