$ErrorActionPreference = "Stop" function Fail([string]$Message) { Write-Error "OpenTeam installer: $Message" exit 1 } $installerColor = -not [Console]::IsOutputRedirected -and -not (Test-Path Env:NO_COLOR) -and $env:TERM -ne "dumb" function Write-Step([string]$Mark, [string]$Message, [string]$Color = "Cyan") { if ($installerColor) { Write-Host " $Mark $Message" -ForegroundColor $Color } else { Write-Host " $Mark $Message" } } Write-Host "" Write-Step "OPENTEAM" "/ install" Write-Host " Windows" Write-Host "" $architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant() switch ($architecture) { "x64" { $assetName = "openteam-windows-x64.exe" } "arm64" { $assetName = "openteam-windows-x64.exe" } default { Fail "unsupported Windows architecture: $architecture" } } $repository = if ($env:OPENTEAM_REPOSITORY) { $env:OPENTEAM_REPOSITORY } else { "raghavpillai/openteam" } $requestedVersion = if ($env:OPENTEAM_VERSION) { $env:OPENTEAM_VERSION } else { "latest" } if ($requestedVersion -eq "latest") { try { $releaseTag = (Invoke-RestMethod "https://api.github.com/repos/$repository/releases/latest").tag_name } catch { Fail "no public OpenTeam release is available yet." } } else { $releaseTag = if ($requestedVersion.StartsWith("v")) { $requestedVersion } else { "v$requestedVersion" } } $releaseBase = "https://github.com/$repository/releases/download/$releaseTag" $temporaryDirectory = Join-Path ([System.IO.Path]::GetTempPath()) ("openteam-" + [guid]::NewGuid()) New-Item -ItemType Directory -Path $temporaryDirectory | Out-Null $binaryPath = Join-Path $temporaryDirectory $assetName $checksumsPath = Join-Path $temporaryDirectory "SHA256SUMS" $binDirectory = if ($env:OPENTEAM_BIN_DIR) { $env:OPENTEAM_BIN_DIR } else { Join-Path $env:LOCALAPPDATA "OpenTeam\bin" } $installedBinary = Join-Path $binDirectory "openteam.exe" $installerProgressPreference = $ProgressPreference $ProgressPreference = "SilentlyContinue" try { Write-Step ([char]0x25C7) "Downloading CLI $releaseTag$([char]0x2026)" # Prefer the gzip copy; fall back to the raw binary for releases that predate it. # Basic parsing avoids browser/HTML prompts in Windows PowerShell 5.1. $compressedPath = "$binaryPath.gz" try { Invoke-WebRequest "$releaseBase/$assetName.gz" -UseBasicParsing -OutFile $compressedPath $compressedStream = [System.IO.File]::OpenRead($compressedPath) $binaryStream = [System.IO.File]::Create($binaryPath) $gzipStream = New-Object System.IO.Compression.GZipStream($compressedStream, [System.IO.Compression.CompressionMode]::Decompress) $gzipStream.CopyTo($binaryStream) $gzipStream.Dispose(); $binaryStream.Dispose(); $compressedStream.Dispose() } catch { Invoke-WebRequest "$releaseBase/$assetName" -UseBasicParsing -OutFile $binaryPath } Invoke-WebRequest "$releaseBase/SHA256SUMS" -UseBasicParsing -OutFile $checksumsPath $checksumLine = Get-Content $checksumsPath | Where-Object { $fields = $_.Trim() -split "\s+", 2 $fields.Count -eq 2 -and (($fields[1].Trim() -replace "^\*", "") -replace "^.*/", "") -ceq $assetName } | Select-Object -First 1 if (-not $checksumLine) { Fail "SHA256SUMS does not contain $assetName." } $expectedChecksum = ($checksumLine.Trim() -split "\s+")[0].ToLowerInvariant() $actualChecksum = (Get-FileHash -Algorithm SHA256 $binaryPath).Hash.ToLowerInvariant() if ($actualChecksum -ne $expectedChecksum) { Fail "the OpenTeam CLI checksum did not match." } Write-Step ([char]0x2713) "Download verified" "Green" New-Item -ItemType Directory -Force -Path $binDirectory | Out-Null Copy-Item -Force $binaryPath $installedBinary Write-Step ([char]0x2713) "CLI installed" "Green" Write-Host " $installedBinary" $userPath = [Environment]::GetEnvironmentVariable("Path", "User") if (-not $userPath) { $userPath = "" } if (-not (($userPath -split ";") -contains $binDirectory)) { $newPath = if ($userPath) { "$($userPath.TrimEnd(";"));$binDirectory" } else { $binDirectory } [Environment]::SetEnvironmentVariable("Path", $newPath, "User") Write-Host "Added $binDirectory to your user PATH." } Write-Host "" Write-Step "SERVER" "SETUP" Write-Host "" & $installedBinary install @args exit $LASTEXITCODE } finally { $ProgressPreference = $installerProgressPreference Remove-Item -Recurse -Force $temporaryDirectory -ErrorAction SilentlyContinue }