-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinstall.ps1
More file actions
365 lines (314 loc) · 13.6 KB
/
install.ps1
File metadata and controls
365 lines (314 loc) · 13.6 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
[CmdletBinding()]
param(
[switch]$SkipWinGet,
[switch]$SkipNpmPackages,
[switch]$SkipExtensions,
[string]$WSLDistro = "Ubuntu-22.04"
)
# Check if running as Administrator
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "This script requires Administrator privileges. Requesting elevation..." -ForegroundColor Yellow
# Get the current script path and arguments
$scriptPath = $MyInvocation.MyCommand.Path
$arguments = ""
# Build argument string from bound parameters
foreach ($param in $PSBoundParameters.GetEnumerator()) {
if ($param.Value -is [switch] -and $param.Value) {
$arguments += " -$($param.Key)"
} elseif ($param.Value -isnot [switch]) {
$arguments += " -$($param.Key) '$($param.Value)'"
}
}
try {
# Determine which PowerShell to use - prefer PowerShell 7+
$pwshPath = Get-Command "pwsh.exe" -ErrorAction SilentlyContinue
if ($pwshPath) {
$powershellExe = "pwsh.exe"
Write-Host "Using PowerShell 7+ for elevation..." -ForegroundColor Green
} else {
$powershellExe = "powershell.exe"
Write-Host "PowerShell 7+ not found, using Windows PowerShell..." -ForegroundColor Yellow
}
# Start elevated process
$process = Start-Process -FilePath $powershellExe -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`"$arguments" -Verb RunAs -Wait -PassThru
# Exit with the same code as the elevated process
exit $process.ExitCode
}
catch {
Write-Error "Failed to elevate privileges: $($_.Exception.Message)"
Write-Host "Please run this script as Administrator manually." -ForegroundColor Red
exit 1
}
}
function Test-Command {
param([string]$CommandName)
return [bool](Get-Command -Name $CommandName -ErrorAction SilentlyContinue)
}
function Write-Header {
param([string]$Message)
Write-Host ""
Write-Host $Message -ForegroundColor White -BackgroundColor DarkBlue
Write-Host ""
}
function Write-Step {
param([string]$Message)
Write-Host "• $Message" -ForegroundColor Cyan
}
function Write-Success {
param([string]$Message)
Write-Host " ✓ $Message" -ForegroundColor Green
}
function Write-Warning {
param([string]$Message)
Write-Host " ⚠ $Message" -ForegroundColor Yellow
}
function Write-Error {
param([string]$Message)
Write-Host " ✗ $Message" -ForegroundColor Red
}
function Write-Skipped {
param([string]$Message)
Write-Host " - $Message" -ForegroundColor DarkGray
}
function Install-Fonts {
param([string]$FontZipPath)
try {
if (-not (Test-Path $FontZipPath)) {
Write-Warning "Font zip file not found: $FontZipPath"
return
}
# Silent installation - output handled by main script
# Create temporary directory for extraction
$tempDir = Join-Path $env:TEMP "CascadiaCodeFonts"
if (Test-Path $tempDir) {
Remove-Item $tempDir -Recurse -Force
}
New-Item -Path $tempDir -ItemType Directory -Force | Out-Null
# Extract fonts
Expand-Archive -Path $FontZipPath -DestinationPath $tempDir -Force
# Get font files
$fontFiles = Get-ChildItem -Path $tempDir -Recurse -Include "*.ttf", "*.otf"
if ($fontFiles.Count -eq 0) {
Write-Warning "No font files found in the archive"
return
}
# Install fonts
$fontsInstalled = 0
foreach ($fontFile in $fontFiles) {
try {
# Copy to Windows Fonts directory
$fontName = $fontFile.Name
$fontDestination = Join-Path $env:windir "Fonts\$fontName"
if (-not (Test-Path $fontDestination)) {
Copy-Item $fontFile.FullName $fontDestination -Force
# Register font in registry
$fontDisplayName = $fontFile.BaseName
New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" -Name $fontDisplayName -Value $fontName -PropertyType String -Force | Out-Null
$fontsInstalled++
}
}
catch {
Write-Warning "Failed to install font $($fontFile.Name): $($_.Exception.Message)"
}
}
# Silent installation - status reported by main script
# Cleanup
Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
catch {
Write-Warning "Font installation failed: $($_.Exception.Message)"
}
}
try {
Write-Header " Developer Setup Installation "
Write-Host "Automated installation of development tools and configurations" -ForegroundColor Gray
$totalSteps = 5
$currentStep = 0
# Step 1: WinGet
$currentStep++
Write-Header " Step ${currentStep}/${totalSteps}: Package Manager "
if (-not $SkipWinGet -and -not (Test-Command 'winget')) {
Write-Step "Installing WinGet package manager"
& "$PSScriptRoot\installs\install-winget.ps1" | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Success "WinGet installed"
} else {
Write-Error "WinGet installation failed"
throw "Failed to install WinGet"
}
} elseif (-not $SkipWinGet) {
Write-Success "WinGet already available"
} else {
Write-Skipped "WinGet installation skipped"
}
# Step 2: Development Tools
$currentStep++
Write-Header " Step ${currentStep}/${totalSteps}: Development Tools "
if (-not $SkipWinGet) {
Write-Step "Installing development tools via WinGet"
# Run WinGet script silently and show only clean progress
Write-Host " This may take several minutes..." -ForegroundColor Gray
# Capture all output but don't display the messy parts
$wingetResult = & "$PSScriptRoot\installs\winget.ps1" *>&1 | Out-String
# Parse the output for meaningful information
$installCount = 0
$skipCount = 0
$errorCount = 0
# Count successful installations, skips, and errors from the final result
if ($wingetResult -match "✓") {
$installCount = ([regex]::Matches($wingetResult, "✓")).Count
}
if ($wingetResult -match "Skipping") {
$skipCount = ([regex]::Matches($wingetResult, "Skipping")).Count
}
if ($wingetResult -match "✗|Failed") {
$errorCount = ([regex]::Matches($wingetResult, "✗|Failed")).Count
}
# Show clean summary
if ($installCount -gt 0) {
Write-Host " ✓ $installCount tools installed" -ForegroundColor Green
}
if ($skipCount -gt 0) {
Write-Host " - $skipCount tools skipped (already current)" -ForegroundColor Gray
}
if ($errorCount -gt 0) {
Write-Host " ⚠ $errorCount tools had issues" -ForegroundColor Yellow
}
if ($LASTEXITCODE -eq 0) {
Write-Success "Development tools installation completed"
} else {
Write-Warning "Some tools may have failed (see details above)"
}
} else {
Write-Skipped "Development tools installation skipped"
}
# Step 3: Fonts
$currentStep++
Write-Header " Step ${currentStep}/${totalSteps}: Developer Fonts "
Write-Step "Installing Cascadia Code fonts"
$fontZipPath = Join-Path $PSScriptRoot "fonts\CascadiaCode.zip"
try {
Install-Fonts -FontZipPath $fontZipPath
Write-Success "Cascadia Code fonts installed"
}
catch {
Write-Warning "Font installation failed"
}
# Step 4: NPM Packages
$currentStep++
Write-Header " Step ${currentStep}/${totalSteps}: Global NPM Packages "
if (-not $SkipNpmPackages) {
if (Test-Command 'fnm') {
Write-Step "Installing global npm packages"
# Run npm script with filtered output to show progress
$npmOutput = & "$PSScriptRoot\installs\npm-global.ps1" 2>&1
$npmOutput | ForEach-Object {
$line = $_.ToString().Trim()
# Show installation progress and results
if ($line -match "Initializing|Installing|✓|✗|already|Failed|Error") {
Write-Host $line
}
}
if ($LASTEXITCODE -eq 0) {
Write-Success "NPM packages installation completed"
} else {
Write-Warning "Some npm packages may have failed (see details above)"
}
} else {
Write-Warning "Fast Node Manager (fnm) not found"
Write-Host " Install fnm first, then run: .\installs\npm-global.ps1" -ForegroundColor Gray
}
} else {
Write-Skipped "NPM packages installation skipped"
}
# Step 5: VSCode Extensions
$currentStep++
Write-Header " Step ${currentStep}/${totalSteps}: VSCode Extensions "
if (-not $SkipExtensions) {
if (Test-Command 'code') {
Write-Step "Installing VSCode extensions"
# Run VSCode script with filtered output to show progress
$vscodeOutput = & "$PSScriptRoot\installs\vscode.ps1" 2>&1
$vscodeOutput | ForEach-Object {
$line = $_.ToString().Trim()
# Filter out the main header but keep progress info
if ($line -match "^Installing VSCode extensions from:" -or $line -match "^Found \d+ extensions") {
return
}
# Show installation progress and results
elseif ($line -match "Installing|✓|✗|already|Failed|Error") {
Write-Host $line
}
}
if ($LASTEXITCODE -eq 0) {
Write-Success "VSCode extensions installation completed"
} else {
Write-Warning "Some extensions may have failed (see details above)"
}
} else {
Write-Warning "VSCode not found"
Write-Host " Install VSCode first, then run: .\installs\vscode.ps1" -ForegroundColor Gray
}
} else {
Write-Skipped "VSCode extensions installation skipped"
}
# WSL Setup - Always performed
Write-Header " WSL Development Environment Setup "
Write-Step "Setting up WSL for Claude Code development"
# Check if WSL is enabled
if (-not (Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux).State -eq "Enabled") {
Write-Host " Enabling WSL feature..." -ForegroundColor Yellow
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
Write-Warning "WSL features enabled. Please restart your computer and run this script again."
return
}
# Check if the specified distro is installed
$installedDistros = wsl --list --quiet 2>$null | ForEach-Object { $_.Trim() }
if ($WSLDistro -notin $installedDistros) {
Write-Host " Installing $WSLDistro..." -ForegroundColor Yellow
wsl --install -d $WSLDistro
if ($LASTEXITCODE -ne 0) {
Write-Warning "Failed to install $WSLDistro. Please install manually."
return
}
} else {
Write-Host " ✓ $WSLDistro already installed" -ForegroundColor Green
}
# Run WSL tools setup
Write-Host " Setting up development tools in WSL..." -ForegroundColor Yellow
$wslToolsScript = Join-Path $PSScriptRoot "installs\wsl-tools.sh"
if (Test-Path $wslToolsScript) {
# Make script executable and run it
wsl -d $WSLDistro -- chmod +x "/mnt/c$($wslToolsScript.Replace('C:', '').Replace('\', '/'))"
wsl -d $WSLDistro -- bash "/mnt/c$($wslToolsScript.Replace('C:', '').Replace('\', '/'))"
if ($LASTEXITCODE -eq 0) {
Write-Success "WSL development environment setup completed"
} else {
Write-Warning "WSL tools setup encountered some issues (see details above)"
}
} else {
Write-Warning "WSL tools script not found: $wslToolsScript"
}
# Completion
Write-Header " Installation Complete "
Write-Host "✓ Setup process finished!" -ForegroundColor Green
Write-Host ""
Write-Host "WSL Setup Complete:" -ForegroundColor Cyan
Write-Host " • $WSLDistro installed with development tools" -ForegroundColor White
Write-Host " • Node.js, .NET SDK, Azure CLI, 1Password CLI ready" -ForegroundColor White
Write-Host " • prettier and markdownlint available for Claude Code" -ForegroundColor White
Write-Host ""
Write-Host "Next Steps:" -ForegroundColor Cyan
Write-Host " 1. Run .\configure.ps1 to configure Claude Code and development tools" -ForegroundColor White
Write-Host " 2. Test WSL setup: wsl -d $WSLDistro" -ForegroundColor White
}
catch {
Write-Host ""
Write-Host " Installation Failed " -ForegroundColor White -BackgroundColor Red
Write-Host ""
Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red
Write-Host ""
Write-Host "Check the error details above and try running the script again." -ForegroundColor Gray
exit 1
}