-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInstall.ps1
More file actions
411 lines (345 loc) · 12.2 KB
/
Install.ps1
File metadata and controls
411 lines (345 loc) · 12.2 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
411
#Requires -Version 5.1
<#
.SYNOPSIS
One-line installer for blackdot on Windows.
.DESCRIPTION
Downloads and installs blackdot for Windows PowerShell users.
Usage:
irm https://raw.githubusercontent.com/blackwell-systems/blackdot/main/Install.ps1 | iex
Or with options:
$script = irm https://raw.githubusercontent.com/blackwell-systems/blackdot/main/Install.ps1
& ([scriptblock]::Create($script)) -Preset developer -SkipPackages
.PARAMETER Preset
Feature preset to apply: minimal, developer, claude, full (default: none)
.PARAMETER SkipPackages
Skip winget package installation
.PARAMETER SkipBinary
Skip Go binary download (use shell scripts only)
.PARAMETER WorkspaceTarget
Installation directory (default: $HOME\workspace)
.PARAMETER Version
Specific version to download (default: latest)
.EXAMPLE
irm https://raw.githubusercontent.com/blackwell-systems/blackdot/main/Install.ps1 | iex
.EXAMPLE
.\Install.ps1 -Preset developer
.EXAMPLE
.\Install.ps1 -SkipPackages -WorkspaceTarget "D:\dev"
#>
[CmdletBinding()]
param(
[ValidateSet('minimal', 'developer', 'claude', 'full')]
[string]$Preset,
[switch]$SkipPackages,
[switch]$SkipBinary,
[string]$WorkspaceTarget = "$HOME\workspace",
[string]$Version = "latest"
)
# ============================================================
# Colors and Output
# ============================================================
$script:Colors = @{
Red = "`e[31m"
Green = "`e[32m"
Yellow = "`e[33m"
Blue = "`e[34m"
Cyan = "`e[36m"
Bold = "`e[1m"
Reset = "`e[0m"
}
function Write-Info { param($Message) Write-Host "$($Colors.Blue)[INFO]$($Colors.Reset) $Message" }
function Write-Pass { param($Message) Write-Host "$($Colors.Green)[OK]$($Colors.Reset) $Message" }
function Write-Warn { param($Message) Write-Host "$($Colors.Yellow)[WARN]$($Colors.Reset) $Message" }
function Write-Fail { param($Message) Write-Host "$($Colors.Red)[FAIL]$($Colors.Reset) $Message" }
# ============================================================
# Banner
# ============================================================
function Show-Banner {
Write-Host ""
Write-Host "$($Colors.Cyan)$($Colors.Bold)"
Write-Host " ____ __ ___ ________ ____ ____ ______"
Write-Host " / __ )/ / / | / ____/ //_/ / / / / / / __ \______"
Write-Host " / __ / / / /| |/ / / ,< / / / / / / / / // __ /"
Write-Host " / /_/ / /___/ ___ / /___/ /| |/ /_/ / /_/ / /_/ // /_/ /"
Write-Host "/_____/_____/_/ |_\____/_/ |_|\____/\____/\____/ \____/"
Write-Host ""
Write-Host "$($Colors.Reset)"
Write-Host "$($Colors.Bold)Vault-backed configuration that travels with you$($Colors.Reset)"
Write-Host ""
}
# ============================================================
# Prerequisites Check
# ============================================================
function Test-Prerequisites {
$missing = @()
# Git is required
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
$missing += "git"
}
if ($missing.Count -gt 0) {
Write-Fail "Missing prerequisites: $($missing -join ', ')"
Write-Host ""
Write-Host "Install with winget:"
foreach ($pkg in $missing) {
switch ($pkg) {
"git" { Write-Host " winget install Git.Git" }
}
}
Write-Host ""
return $false
}
Write-Pass "Prerequisites check passed"
return $true
}
# ============================================================
# Download Go Binary
# ============================================================
function Install-GoBinary {
param(
[string]$InstallDir = "$HOME\.local\bin",
[string]$Version = "latest"
)
# Detect architecture
$arch = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { "386" }
$binaryName = "blackdot-windows-$arch.exe"
# GitHub release URL
$baseUrl = "https://github.com/blackwell-systems/blackdot/releases"
$downloadUrl = if ($Version -eq "latest") {
"$baseUrl/latest/download/$binaryName"
} else {
"$baseUrl/download/$Version/$binaryName"
}
Write-Info "Downloading Go binary: $binaryName"
Write-Info "From: $downloadUrl"
# Create install directory
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
$targetPath = Join-Path $InstallDir "blackdot.exe"
try {
# Download with progress
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $downloadUrl -OutFile $targetPath -UseBasicParsing
$ProgressPreference = 'Continue'
# Verify it works
$versionOutput = & $targetPath version 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Pass "Installed blackdot binary to: $targetPath"
# Check if in PATH
$pathDirs = $env:PATH -split ';'
if ($InstallDir -notin $pathDirs) {
Write-Warn "Add to your PATH: $InstallDir"
Write-Host ""
Write-Host "Run this to add permanently:"
Write-Host " [Environment]::SetEnvironmentVariable('Path', `$env:PATH + ';$InstallDir', 'User')"
}
return $true
} else {
throw "Binary verification failed"
}
}
catch {
Write-Fail "Failed to download binary: $_"
Write-Fail "Release may not exist yet. Check: $baseUrl"
if (Test-Path $targetPath) {
Remove-Item $targetPath -Force
}
return $false
}
}
# ============================================================
# Clone/Update Repository
# ============================================================
function Install-Repository {
param(
[string]$TargetDir
)
$repoUrl = "https://github.com/blackwell-systems/blackdot.git"
if (Test-Path (Join-Path $TargetDir ".git")) {
Write-Info "Blackdot already installed at $TargetDir"
Write-Info "Updating..."
Push-Location $TargetDir
try {
git pull --rebase origin main 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Pass "Updated to latest version"
} else {
Write-Warn "Update failed, continuing with existing version"
}
}
finally {
Pop-Location
}
}
else {
# Create parent directory
$parentDir = Split-Path $TargetDir -Parent
if (-not (Test-Path $parentDir)) {
New-Item -ItemType Directory -Path $parentDir -Force | Out-Null
}
Write-Info "Cloning blackdot repository..."
git clone $repoUrl $TargetDir 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Pass "Cloned to $TargetDir"
} else {
Write-Fail "Failed to clone repository"
return $false
}
}
return $true
}
# ============================================================
# Install PowerShell Module
# ============================================================
function Install-BlackdotModule {
param(
[string]$BlackdotDir
)
$installScript = Join-Path $BlackdotDir "powershell\Install-Blackdot.ps1"
if (-not (Test-Path $installScript)) {
Write-Fail "Install script not found: $installScript"
return $false
}
Write-Info "Installing PowerShell module..."
Push-Location (Join-Path $BlackdotDir "powershell")
try {
& $installScript
if ($LASTEXITCODE -eq 0 -or $?) {
Write-Pass "PowerShell module installed"
return $true
} else {
Write-Fail "Module installation failed"
return $false
}
}
catch {
Write-Fail "Module installation error: $_"
return $false
}
finally {
Pop-Location
}
}
# ============================================================
# Install Packages (Optional)
# ============================================================
function Install-BlackdotPackages {
param(
[string]$BlackdotDir,
[string]$Tier = "enhanced"
)
$packagesScript = Join-Path $BlackdotDir "powershell\Install-Packages.ps1"
if (-not (Test-Path $packagesScript)) {
Write-Warn "Packages script not found, skipping"
return $true
}
Write-Info "Installing packages (tier: $Tier)..."
Push-Location (Join-Path $BlackdotDir "powershell")
try {
& $packagesScript -Tier $Tier
Write-Pass "Packages installed"
return $true
}
catch {
Write-Warn "Some packages may not have installed: $_"
return $true # Non-fatal
}
finally {
Pop-Location
}
}
# ============================================================
# Apply Preset
# ============================================================
function Set-BlackdotPreset {
param(
[string]$Preset
)
if (-not $Preset) { return $true }
$blackdot = Get-Command blackdot -ErrorAction SilentlyContinue
if (-not $blackdot) {
$blackdot = Get-Command blackdot.exe -ErrorAction SilentlyContinue
}
if ($blackdot) {
Write-Info "Applying preset: $Preset"
& $blackdot.Source features preset $Preset
if ($LASTEXITCODE -eq 0) {
Write-Pass "Preset '$Preset' applied"
return $true
}
}
Write-Warn "Could not apply preset (blackdot CLI not in PATH yet)"
Write-Host " Run after restart: blackdot features preset $Preset"
return $true
}
# ============================================================
# Main Installation
# ============================================================
function Main {
Show-Banner
# Check prerequisites
if (-not (Test-Prerequisites)) {
exit 1
}
$blackdotDir = Join-Path $WorkspaceTarget "blackdot"
# Clone/update repository
Write-Host ""
if (-not (Install-Repository -TargetDir $blackdotDir)) {
exit 1
}
# Install Go binary (unless skipped)
Write-Host ""
if (-not $SkipBinary) {
$binaryInstalled = Install-GoBinary -Version $Version
if (-not $binaryInstalled) {
Write-Warn "Binary installation failed, shell scripts will be used"
}
}
# Install PowerShell module
Write-Host ""
if (-not (Install-BlackdotModule -BlackdotDir $blackdotDir)) {
Write-Warn "Module installation had issues, but continuing..."
}
# Install packages (unless skipped)
if (-not $SkipPackages) {
Write-Host ""
Write-Host "Install development packages via winget? (This may take a while)"
$response = Read-Host "Install packages? [y/N]"
if ($response -match '^[Yy]') {
Install-BlackdotPackages -BlackdotDir $blackdotDir
} else {
Write-Info "Skipping package installation"
Write-Host " Run later: $blackdotDir\powershell\Install-Packages.ps1"
}
}
# Apply preset
if ($Preset) {
Write-Host ""
Set-BlackdotPreset -Preset $Preset
}
# Success message
Write-Host ""
Write-Host "$($Colors.Green)$($Colors.Bold)================================================$($Colors.Reset)"
Write-Host "$($Colors.Green)$($Colors.Bold) Installation Complete! $($Colors.Reset)"
Write-Host "$($Colors.Green)$($Colors.Bold)================================================$($Colors.Reset)"
Write-Host ""
Write-Host "Next steps:"
Write-Host ""
Write-Host " 1. Restart PowerShell to load the module"
Write-Host ""
Write-Host " 2. Set up vault and restore secrets:"
Write-Host " $($Colors.Cyan)blackdot setup$($Colors.Reset)"
Write-Host ""
Write-Host " 3. Verify installation:"
Write-Host " $($Colors.Cyan)blackdot doctor$($Colors.Reset)"
Write-Host ""
if (-not $SkipPackages -and $response -notmatch '^[Yy]') {
Write-Host " Optional: Install development packages:"
Write-Host " $($Colors.Cyan)$blackdotDir\powershell\Install-Packages.ps1$($Colors.Reset)"
Write-Host ""
}
Write-Host "Documentation: $($Colors.Blue)https://github.com/blackwell-systems/blackdot$($Colors.Reset)"
Write-Host ""
}
# Run main
Main