#Requires -Version 5.1 <# .SYNOPSIS Install tunzip from GitHub Releases (served at https://tun.zip/install.ps1). .EXAMPLE irm https://tun.zip/install.ps1 | iex .EXAMPLE $env:TUNZIP_VERSION = '0.1.0'; irm https://tun.zip/install.ps1 | iex #> [CmdletBinding()] param( [string]$Version = $env:TUNZIP_VERSION, [string]$InstallDir = $env:TUNZIP_INSTALL_DIR, [string]$Repo = $(if ($env:TUNZIP_REPO) { $env:TUNZIP_REPO } else { 'BaseDatum/tunzip' }), [switch]$NoPathUpdate ) $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' # Embedded minisign public key (RW...) for BaseDatum/tunzip releases. # Populate this value once the production release signing keypair is provisioned. $EmbeddedMinisignPubKey = 'RWR+wcIcy/XydbJUwRjiS5LwQIalC+as4l4FWqBqQaHnrxvcgP0QSVwh' $MinisignPubKey = if ($env:TUNZIP_MINISIGN_PUBKEY) { $env:TUNZIP_MINISIGN_PUBKEY } else { $EmbeddedMinisignPubKey } if (-not $InstallDir) { if ($env:LOCALAPPDATA) { $InstallDir = Join-Path $env:LOCALAPPDATA 'tunzip\bin' } else { $InstallDir = Join-Path $HOME '.local\bin' } } function Get-TargetTriple { $arch = $null try { $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString() } catch { $arch = $env:PROCESSOR_ARCHITECTURE } switch -Regex ($arch) { '^(X64|AMD64)$' { return 'x86_64-pc-windows-msvc' } default { throw "Unsupported Windows architecture: $arch (only x86_64 is currently published)" } } } function Resolve-LatestTag { param([string]$RepoSlug) $apiUrl = "https://api.github.com/repos/$RepoSlug/releases/latest" $headers = @{ 'User-Agent' = 'tunzip-installer' } $release = Invoke-RestMethod -Uri $apiUrl -Headers $headers if (-not $release.tag_name) { throw "Could not determine latest release tag from $apiUrl" } return [string]$release.tag_name } if ([Net.ServicePointManager]::SecurityProtocol -band [Net.SecurityProtocolType]::Tls12) { # TLS 1.2 already enabled } else { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } $target = Get-TargetTriple if ($Version) { $cleanVersion = $Version.TrimStart('v') $tag = "v$cleanVersion" } else { $tag = Resolve-LatestTag -RepoSlug $Repo $cleanVersion = $tag.TrimStart('v') } $archive = "tunzip-$cleanVersion-$target.zip" $baseUrl = "https://github.com/$Repo/releases/download/$tag" $workDir = Join-Path ([System.IO.Path]::GetTempPath()) ("tunzip-install-" + [System.Guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $workDir -Force | Out-Null try { $archivePath = Join-Path $workDir $archive $sumsPath = Join-Path $workDir 'SHA256SUMS' Write-Host "Downloading tunzip $cleanVersion ($target)..." Invoke-WebRequest -Uri "$baseUrl/$archive" -OutFile $archivePath -UseBasicParsing Invoke-WebRequest -Uri "$baseUrl/SHA256SUMS" -OutFile $sumsPath -UseBasicParsing $expectedSha = $null foreach ($line in Get-Content -Path $sumsPath) { if ($line -match '^([0-9a-fA-F]{64})\s+\*?(.+)$') { if ($Matches[2].Trim() -eq $archive) { $expectedSha = $Matches[1].ToLowerInvariant() break } } } if (-not $expectedSha) { throw "Checksum for $archive not found in SHA256SUMS" } $actualSha = (Get-FileHash -Path $archivePath -Algorithm SHA256).Hash.ToLowerInvariant() if ($actualSha -ne $expectedSha) { throw "SHA-256 mismatch for ${archive}: expected $expectedSha, got $actualSha" } Write-Host 'Verified SHA-256 checksum.' if ($MinisignPubKey) { $minisign = Get-Command minisign -ErrorAction SilentlyContinue if ($minisign) { $sigPath = Join-Path $workDir "$archive.minisig" Invoke-WebRequest -Uri "$baseUrl/$archive.minisig" -OutFile $sigPath -UseBasicParsing & $minisign.Source -Vq -P $MinisignPubKey -m $archivePath -x $sigPath if ($LASTEXITCODE -ne 0) { throw "minisign signature verification failed for $archive" } Write-Host 'Verified minisign signature.' } else { Write-Host 'Note: install minisign to also verify release signatures.' } } $unpackDir = Join-Path $workDir 'unpack' Expand-Archive -Path $archivePath -DestinationPath $unpackDir -Force $binSrc = Join-Path $unpackDir "tunzip-$cleanVersion-$target\tunzip.exe" if (-not (Test-Path $binSrc)) { $binSrc = Join-Path $unpackDir 'tunzip.exe' } if (-not (Test-Path $binSrc)) { throw "tunzip.exe not found inside $archive" } New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null $destBin = Join-Path $InstallDir 'tunzip.exe' Copy-Item -Path $binSrc -Destination $destBin -Force if (-not $NoPathUpdate) { $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') $parts = @() if ($userPath) { $parts = $userPath -split ';' | Where-Object { $_ -ne '' } } $alreadyOnPath = $false foreach ($p in $parts) { if ($p.TrimEnd('\') -ieq $InstallDir.TrimEnd('\')) { $alreadyOnPath = $true break } } if (-not $alreadyOnPath) { $newPath = if ($userPath) { "$userPath;$InstallDir" } else { $InstallDir } [Environment]::SetEnvironmentVariable('Path', $newPath, 'User') $env:Path = "$InstallDir;$env:Path" Write-Host "Added $InstallDir to your user PATH (restart open terminals to pick it up)." } } Write-Host '' Write-Host "Installed tunzip $cleanVersion to $destBin" Write-Host '' Write-Host 'Next steps:' Write-Host ' tunzip init' Write-Host ' tunzip share 3000' Write-Host '' Write-Host 'MCP setup (Claude Code):' Write-Host ' claude mcp add tunzip -- tunzip mcp' Write-Host '' Write-Host 'MCP config snippet (Cursor / Codex / stdio clients):' Write-Host ' {"mcpServers":{"tunzip":{"command":"tunzip","args":["mcp"]}}}' } finally { Remove-Item -Path $workDir -Recurse -Force -ErrorAction SilentlyContinue }