-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
410 lines (365 loc) · 16.3 KB
/
install.ps1
File metadata and controls
410 lines (365 loc) · 16.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# Copyright 2026 ResQ Software
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Usage:
# irm https://raw.githubusercontent.com/resq-software/dev/main/install.ps1 | iex
#
# Or inspect first:
# irm https://raw.githubusercontent.com/resq-software/dev/main/install.ps1 -OutFile install.ps1
# Get-Content install.ps1
# .\install.ps1
#Requires -Version 5.1
[CmdletBinding()]
param(
# Pre-select a repo for unattended runs. Also honours $env:REPO.
[string]$Repo = $env:REPO
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# ── Constants ────────────────────────────────────────────────────────────────
$ScriptVersion = '0.3.0'
$Org = 'resq-software'
$NixInstallUrl = 'https://install.determinate.systems/nix'
# Canonical repo list — keep in sync with install.sh and README.md.
$ValidRepos = @('programs','dotnet-sdk','pypi','crates','npm','vcpkg','landing','docs')
# ── Platform flag ────────────────────────────────────────────────────────────
$IsNativeWindows = $IsWindows -or (-not $IsLinux -and -not $IsMacOS -and
[System.Environment]::OSVersion.Platform -eq 'Win32NT')
# ── Utility functions ────────────────────────────────────────────────────────
function Write-Info { param([string]$Msg) Write-Host "info $Msg" -ForegroundColor Cyan }
function Write-Ok { param([string]$Msg) Write-Host " ok $Msg" -ForegroundColor Green }
function Write-Warn { param([string]$Msg) Write-Host "warn $Msg" -ForegroundColor Yellow }
function Write-Fail { param([string]$Msg) Write-Host "fail $Msg" -ForegroundColor Red; throw $Msg }
function Test-Command {
param([string]$Name)
$null -ne (Get-Command $Name -ErrorAction SilentlyContinue)
}
function Test-MinVersion {
param(
[string]$Tool,
[string]$Actual,
[string]$Minimum,
[string]$Url
)
$cleanActual = ($Actual -replace '[^0-9.]', '').Trim('.')
$cleanMinimum = ($Minimum -replace '[^0-9.]', '').Trim('.')
$aParts = $cleanActual.Split('.')
$mParts = $cleanMinimum.Split('.')
$len = [Math]::Max($aParts.Length, $mParts.Length)
for ($i = 0; $i -lt $len; $i++) {
$a = if ($i -lt $aParts.Length) { [int]$aParts[$i] } else { 0 }
$m = if ($i -lt $mParts.Length) { [int]$mParts[$i] } else { 0 }
if ($a -gt $m) { return }
if ($a -lt $m) {
Write-Warn "$Tool $Actual is below recommended minimum $Minimum — upgrade: $Url"
return
}
}
}
function Test-Interactive {
# User-interactive AND a real input stream — rules out CI, piped iex, etc.
return [Environment]::UserInteractive -and -not [Console]::IsInputRedirected
}
function Confirm-Action {
param([string]$Message)
if ($env:YES -eq '1') { return $true }
if (-not (Test-Interactive)) { return $false }
$answer = Read-Host "$Message [y/N]"
return ($answer -match '^[yY]([eE][sS])?$')
}
# ── Step functions ───────────────────────────────────────────────────────────
function Get-Platform {
$script:IsWSL = $false
if ($IsLinux) {
if (Test-Path /proc/version) {
$procVersion = Get-Content /proc/version -Raw
if ($procVersion -match 'microsoft|WSL') { $script:IsWSL = $true }
}
}
if ($IsNativeWindows) {
$script:Platform = "Windows $([System.Environment]::OSVersion.Version)"
$script:Arch = if ([System.Environment]::Is64BitOperatingSystem) { 'x64' } else { 'x86' }
}
elseif ($IsMacOS) {
$script:Platform = 'macOS'
$script:Arch = (uname -m)
}
elseif ($IsLinux) {
$script:Platform = if ($script:IsWSL) { 'WSL/Linux' } else { 'Linux' }
$script:Arch = (uname -m)
}
else {
Write-Fail 'Unsupported platform. ResQ requires Windows, Linux, or macOS.'
}
Write-Info "Detected $script:Platform ($script:Arch)"
}
function Assert-Git {
if (-not (Test-Command 'git')) {
if ($IsNativeWindows) {
Write-Warn 'git not found — attempting install via winget...'
winget install --id Git.Git -e --accept-source-agreements --accept-package-agreements
$env:PATH = "$env:PATH;$env:ProgramFiles\Git\cmd"
if (-not (Test-Command 'git')) {
Write-Fail 'git install failed. Install manually: https://git-scm.com/downloads'
}
}
else {
Write-Fail 'git is required. Install it first: https://git-scm.com/downloads'
}
}
$gitVersion = (git --version) -replace 'git version ', ''
Write-Ok "git $gitVersion"
Test-MinVersion 'git' $gitVersion '2.0' 'https://git-scm.com/downloads'
}
function Install-GitHubCLI {
if (-not (Test-Command 'gh')) {
Write-Warn 'gh (GitHub CLI) not found — installing...'
if ($IsNativeWindows) {
winget install --id GitHub.cli -e --accept-source-agreements --accept-package-agreements
$env:PATH = [System.Environment]::GetEnvironmentVariable('PATH', 'Machine') + ';' +
[System.Environment]::GetEnvironmentVariable('PATH', 'User')
if (-not (Test-Command 'gh')) {
Write-Fail 'gh install failed. Install manually: https://cli.github.com'
}
}
elseif ($IsMacOS) {
if (Test-Command 'brew') {
brew install gh
}
else {
Write-Fail 'Install Homebrew first (https://brew.sh) or install gh manually'
}
}
elseif ($IsLinux) {
if (Test-Command 'apt-get') {
bash -c 'curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null && sudo apt-get update && sudo apt-get install -y gh'
}
elseif (Test-Command 'dnf') { sudo dnf install -y gh }
elseif (Test-Command 'pacman') { sudo pacman -S --noconfirm github-cli }
else { Write-Fail 'Cannot auto-install gh. Install manually: https://cli.github.com' }
}
}
$ghVersion = ((gh --version | Select-Object -First 1) -replace '[^0-9.]', '').Trim('.')
Write-Ok "gh $ghVersion"
Test-MinVersion 'gh' $ghVersion '2.0' 'https://cli.github.com'
}
function Connect-GitHub {
gh auth status 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Info 'Not logged in to GitHub — starting auth...'
gh auth login
}
$ghUser = try { gh api user --jq '.login' 2>$null } catch { 'unknown' }
Write-Ok "GitHub authenticated as $ghUser"
}
function Install-Nix {
if (-not (Test-Command 'nix')) {
if ($IsNativeWindows) {
Write-Info 'Nix is not natively supported on Windows.'
Write-Info 'If you are using WSL, run this script inside your WSL distribution.'
Write-Info 'Skipping Nix installation — you can still clone repos below.'
return
}
if (-not (Confirm-Action 'Install Nix package manager?')) {
Write-Warn 'Skipping Nix install — some repos require Nix for their dev environment.'
return
}
Write-Info 'Installing Nix via Determinate Systems installer...'
bash -c "curl --proto '=https' --tlsv1.2 -sSf -L '$NixInstallUrl' | sh -s -- install"
# Source nix in current shell
if (Test-Path '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh') {
bash -c '. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && echo $PATH' |
ForEach-Object { $env:PATH = $_ }
}
elseif (Test-Path "$HOME/.nix-profile/etc/profile.d/nix.sh") {
bash -c ". $HOME/.nix-profile/etc/profile.d/nix.sh && echo \$PATH" |
ForEach-Object { $env:PATH = $_ }
}
}
if (Test-Command 'nix') {
$nixVer = ((nix --version 2>$null) -replace '[^0-9.]', '').Trim('.')
Write-Ok "nix $nixVer"
Test-NixFlakes
}
elseif (-not $IsNativeWindows) {
Write-Warn 'Nix installed but not in PATH. Restart your shell and re-run this script.'
exit 0
}
}
function Test-NixFlakes {
# `nix develop` requires nix-command + flakes. Determinate enables both;
# pre-existing nix installs often don't.
& nix --extra-experimental-features 'nix-command flakes' flake --help *> $null
if ($LASTEXITCODE -ne 0) {
Write-Warn "Nix flakes not enabled — 'nix develop' will fail."
Write-Warn " Add to ~/.config/nix/nix.conf: experimental-features = nix-command flakes"
}
}
function Select-Repo {
# Honour -Repo / $env:REPO for unattended runs.
if ($Repo) {
if ($ValidRepos -notcontains $Repo) {
Write-Fail "Invalid -Repo '$Repo'. Valid: $($ValidRepos -join ', ')"
}
$script:Repo = $Repo
Write-Info "Using Repo=$Repo from parameter/env"
return
}
if (-not (Test-Interactive)) {
Write-Fail "No interactive host for prompt. Use -Repo <name> or `$env:REPO to run unattended. Valid: $($ValidRepos -join ', ')"
}
Write-Host ''
Write-Host ' Which repo do you want to work on?' -ForegroundColor White
Write-Host ''
Write-Host ' ' -NoNewline; Write-Host ' 1' -ForegroundColor Cyan -NoNewline; Write-Host ' programs Solana/Anchor on-chain programs'
Write-Host ' ' -NoNewline; Write-Host ' 2' -ForegroundColor Cyan -NoNewline; Write-Host ' dotnet-sdk .NET client libraries'
Write-Host ' ' -NoNewline; Write-Host ' 3' -ForegroundColor Cyan -NoNewline; Write-Host ' pypi Python packages (MCP + DSA)'
Write-Host ' ' -NoNewline; Write-Host ' 4' -ForegroundColor Cyan -NoNewline; Write-Host ' crates Rust workspace (CLI + DSA)'
Write-Host ' ' -NoNewline; Write-Host ' 5' -ForegroundColor Cyan -NoNewline; Write-Host ' npm TypeScript packages (UI + DSA)'
Write-Host ' ' -NoNewline; Write-Host ' 6' -ForegroundColor Cyan -NoNewline; Write-Host ' vcpkg C++ libraries'
Write-Host ' ' -NoNewline; Write-Host ' 7' -ForegroundColor Cyan -NoNewline; Write-Host ' landing Marketing site'
Write-Host ' ' -NoNewline; Write-Host ' 8' -ForegroundColor Cyan -NoNewline; Write-Host ' docs Documentation site'
Write-Host ''
$choice = Read-Host ' Choice [1-8]'
$script:Repo = switch ($choice) {
'1' { 'programs' }
'2' { 'dotnet-sdk' }
'3' { 'pypi' }
'4' { 'crates' }
'5' { 'npm' }
'6' { 'vcpkg' }
'7' { 'landing' }
'8' { 'docs' }
default { Write-Fail "Invalid choice: $choice" }
}
}
function Clone-Repo {
$script:BaseDir = if ($env:RESQ_DIR) { $env:RESQ_DIR } else { Join-Path $HOME 'resq' }
$script:TargetDir = Join-Path $script:BaseDir $script:Repo
if (Test-Path (Join-Path $script:TargetDir '.git')) {
if (Confirm-Action "$($script:TargetDir) already exists — pull latest?") {
Write-Info 'Pulling latest changes...'
git -C $script:TargetDir pull --ff-only 2>$null
}
}
else {
Write-Info "Cloning $Org/$($script:Repo) into $($script:TargetDir)"
$parentDir = Split-Path $script:TargetDir -Parent
if (-not (Test-Path $parentDir)) { New-Item -ItemType Directory -Path $parentDir -Force | Out-Null }
gh repo clone "$Org/$($script:Repo)" $script:TargetDir
}
Write-Ok "Repository ready at $($script:TargetDir)"
}
function Initialize-Repo {
if ((Test-Path (Join-Path $script:TargetDir 'flake.nix')) -and (Test-Command 'nix')) {
Write-Info 'Nix flake detected — building dev environment (first run may take a few minutes)...'
& nix develop $script:TargetDir --command true
if ($LASTEXITCODE -ne 0) {
Write-Warn "nix develop failed — cd into $($script:TargetDir) and run 'nix develop' to see errors"
}
}
Write-Info 'Installing canonical ResQ git hooks...'
$hooksUrl = "https://raw.githubusercontent.com/$Org/dev/main/scripts/install-hooks.ps1"
try {
$script = Invoke-RestMethod -Uri $hooksUrl -UseBasicParsing
$sb = [ScriptBlock]::Create($script)
Push-Location $script:TargetDir
try { & $sb -TargetDir $script:TargetDir } finally { Pop-Location }
Write-Ok 'Git hooks configured'
} catch {
Write-Warn "Hook install failed — re-run: cd $($script:TargetDir); irm $hooksUrl | iex"
}
}
function Show-RepoInfo {
switch ($script:Repo) {
'programs' {
Write-Host ''
Write-Host ' What''s included:' -ForegroundColor White
Write-Host ''
Write-Host ' Solana CLI, Anchor framework, Rust toolchain'
Write-Host ' make anchor-build, make anchor-test'
Write-Host ''
}
'pypi' {
Write-Host ''
Write-Host ' What''s included:' -ForegroundColor White
Write-Host ''
Write-Host ' Python 3.11-3.13, uv, ruff, mypy'
Write-Host ' Packages: resq-mcp, resq-dsa'
Write-Host ' 90% test coverage gate enforced'
Write-Host ''
}
'crates' {
Write-Host ''
Write-Host ' What''s included:' -ForegroundColor White
Write-Host ''
Write-Host ' Rust toolchain, clippy, cargo-deny'
Write-Host ' Workspace: 9+ crates including CLI tools and resq-dsa'
Write-Host ''
}
'npm' {
Write-Host ''
Write-Host ' What''s included:' -ForegroundColor White
Write-Host ''
Write-Host ' Bun, TypeScript, React 19, Storybook, Chromatic'
Write-Host ' Packages: @resq-sw/ui (55+ components), @resq-sw/dsa'
Write-Host ' Biome linter'
Write-Host ''
}
'vcpkg' {
Write-Host ''
Write-Host ' What''s included:' -ForegroundColor White
Write-Host ''
Write-Host ' C++ toolchain, CMake, clang-format'
Write-Host ' Header-only library: resq-common'
Write-Host ''
}
'docs' {
Write-Host ''
Write-Host ' What''s included:' -ForegroundColor White
Write-Host ''
Write-Host ' Mintlify docs site'
Write-Host ' npx mint dev for local preview'
Write-Host ''
}
}
}
# ── Main ─────────────────────────────────────────────────────────────────────
function Main {
Write-Host ''
Write-Host " ResQ Developer Setup v$ScriptVersion" -ForegroundColor White
Write-Host ' ─────────────────────────────'
Write-Host ''
Get-Platform
Assert-Git
Install-GitHubCLI
Connect-GitHub
Install-Nix
Select-Repo
Clone-Repo
Initialize-Repo
Show-RepoInfo
Write-Host ' Ready!' -ForegroundColor Green
Write-Host ''
Write-Host ' Get started:' -ForegroundColor White
Write-Host ''
Write-Host " cd $($script:TargetDir)"
if (Test-Path (Join-Path $script:TargetDir 'flake.nix')) {
Write-Host ' nix develop'
}
if (Test-Path (Join-Path $script:TargetDir 'Makefile')) {
Write-Host ' make help'
}
Write-Host ''
}
Main