|
| 1 | +#Requires -Version 5.1 |
| 2 | +<# |
| 3 | +install.ps1 - one-time installer for the ai-meta `meta` CLI (native Windows). |
| 4 | +
|
| 5 | + irm https://raw.githubusercontent.com/tizz98/ai-meta/main/install.ps1 | iex |
| 6 | +
|
| 7 | +Downloads the `meta` binary from GitHub releases, verifies its checksum, and |
| 8 | +installs it. After installing, run `meta init` in a repo. |
| 9 | +
|
| 10 | +Tunables (environment variables): |
| 11 | + AI_META_VERSION pin a version (e.g. 0.4.0); default: latest release. |
| 12 | + AI_META_BIN_DIR install directory; default: %LOCALAPPDATA%\ai-meta\bin. |
| 13 | + AI_META_REPO owner/repo to fetch from; default: tizz98/ai-meta. |
| 14 | +#> |
| 15 | +$ErrorActionPreference = 'Stop' |
| 16 | +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 |
| 17 | +$ProgressPreference = 'SilentlyContinue' |
| 18 | + |
| 19 | +$repo = if ($env:AI_META_REPO) { $env:AI_META_REPO } else { 'tizz98/ai-meta' } |
| 20 | +$binDir = if ($env:AI_META_BIN_DIR) { $env:AI_META_BIN_DIR } else { Join-Path $env:LOCALAPPDATA 'ai-meta\bin' } |
| 21 | +$version = $env:AI_META_VERSION |
| 22 | + |
| 23 | +$arch = $env:PROCESSOR_ARCHITECTURE |
| 24 | +if ($arch -ne 'AMD64' -and $arch -ne 'x86') { |
| 25 | + throw "install: unsupported Windows arch $arch (no published build)" |
| 26 | +} |
| 27 | +$tgt = 'x86_64-pc-windows-msvc' |
| 28 | +$ext = '.exe' |
| 29 | + |
| 30 | +if ($version) { |
| 31 | + $version = $version.TrimStart('v') |
| 32 | + $base = "https://github.com/$repo/releases/download/v$version" |
| 33 | + $label = "v$version" |
| 34 | +} else { |
| 35 | + $base = "https://github.com/$repo/releases/latest/download" |
| 36 | + $label = 'latest' |
| 37 | +} |
| 38 | +$asset = "ai-meta-$tgt$ext" |
| 39 | +$url = "$base/$asset" |
| 40 | + |
| 41 | +$tmp = Join-Path ([IO.Path]::GetTempPath()) ("ai-meta-install-" + [Guid]::NewGuid().ToString('N')) |
| 42 | +New-Item -ItemType Directory -Force -Path $tmp | Out-Null |
| 43 | +try { |
| 44 | + Write-Host "downloading meta ($label) for $tgt..." |
| 45 | + $dl = Join-Path $tmp $asset |
| 46 | + Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $dl |
| 47 | + |
| 48 | + # Verify the checksum when the release publishes one (it always should). |
| 49 | + $sumFile = Join-Path $tmp "$asset.sha256" |
| 50 | + $haveSum = $false |
| 51 | + try { |
| 52 | + Invoke-WebRequest -UseBasicParsing -Uri "$url.sha256" -OutFile $sumFile |
| 53 | + $haveSum = $true |
| 54 | + } catch { |
| 55 | + Write-Warning "no checksum published for $asset; skipping verification" |
| 56 | + } |
| 57 | + if ($haveSum) { |
| 58 | + $rawSum = Get-Content -Raw -LiteralPath $sumFile |
| 59 | + $want = if ($rawSum) { (($rawSum.Trim()) -split '\s+')[0].ToLower() } else { '' } |
| 60 | + $have = (Get-FileHash -Algorithm SHA256 -LiteralPath $dl).Hash.ToLower() |
| 61 | + if ($want -ne $have) { |
| 62 | + throw "install: checksum mismatch for $asset (expected $want, got $have)" |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + New-Item -ItemType Directory -Force -Path $binDir | Out-Null |
| 67 | + $dest = Join-Path $binDir "meta$ext" |
| 68 | + Move-Item -Force -LiteralPath $dl -Destination $dest |
| 69 | + Write-Host "installed meta -> $dest" |
| 70 | +} finally { |
| 71 | + Remove-Item -Recurse -Force -LiteralPath $tmp -ErrorAction SilentlyContinue |
| 72 | +} |
| 73 | + |
| 74 | +# Nudge (do not auto-edit PATH) if the install dir isn't on PATH. |
| 75 | +if (($env:PATH -split ';') -notcontains $binDir) { |
| 76 | + Write-Host "" |
| 77 | + Write-Host "note: $binDir is not on your PATH. Add it (User scope), then restart your shell:" |
| 78 | + Write-Host " [Environment]::SetEnvironmentVariable('Path', (`"$binDir;`" + [Environment]::GetEnvironmentVariable('Path','User')), 'User')" |
| 79 | +} |
| 80 | +Write-Host "" |
| 81 | +Write-Host "done. Run 'meta init' in a repo to get started." |
0 commit comments