-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
329 lines (285 loc) · 11.8 KB
/
install.ps1
File metadata and controls
329 lines (285 loc) · 11.8 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
#!/usr/bin/env pwsh
# ================================================================================
# Windows Essential Applications Installer
# ================================================================================
# Installs common applications using winget
#
# Usage:
# .\install.ps1 # Install all packages
# .\install.ps1 -DryRun # Show what would be installed
# .\install.ps1 -ShowCommands # Display individual winget commands
# .\install.ps1 -Help # Show help message
param(
[switch]$DryRun,
[switch]$ShowCommands,
[switch]$Help,
[ValidateSet("home", "personal", "dev", "infra", "full")]
[string]$Profile = "home"
)
# Colors for output
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
}
# Helper function to read packages from profile files
function Get-PackagesFromProfile {
param(
[string]$PackageType, # "winget" or "npm"
[string]$Profile,
[string]$ScriptDir
)
if ($Profile -eq "full") {
$profileFiles = @("home", "personal", "dev", "infra")
$allPackages = @()
foreach ($prof in $profileFiles) {
$packageFile = Join-Path $ScriptDir "$PackageType\packages-$prof.txt"
if (Test-Path $packageFile) {
$profilePackages = Get-Content $packageFile | Where-Object {
$_ -and $_ -notmatch '^\s*#' -and $_ -notmatch '^\s*$'
}
$allPackages += $profilePackages
}
}
return $allPackages | Select-Object -Unique
} else {
$packageFile = Join-Path $ScriptDir "$PackageType\packages-$Profile.txt"
if (Test-Path $packageFile) {
return Get-Content $packageFile | Where-Object {
$_ -and $_ -notmatch '^\s*#' -and $_ -notmatch '^\s*$'
}
}
return @()
}
}
# Show help if requested
if ($Help) {
Write-Host ""
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host "Windows Applications Installer - Help" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "USAGE:" -ForegroundColor Yellow
Write-Host " .\install.ps1 Install home profile (default)"
Write-Host " .\install.ps1 -Profile home Family/essential apps"
Write-Host " .\install.ps1 -Profile personal Personal productivity tools"
Write-Host " .\install.ps1 -Profile dev Development tools"
Write-Host " .\install.ps1 -Profile infra Infrastructure/virtualization"
Write-Host " .\install.ps1 -Profile full Everything combined"
Write-Host " .\install.ps1 -DryRun Preview packages without installing"
Write-Host " .\install.ps1 -ShowCommands Display individual winget commands"
Write-Host " .\install.ps1 -Help Show this help message"
Write-Host ""
Write-Host "PROFILES:" -ForegroundColor Yellow
Write-Host " home - Essential apps for family computers (DEFAULT)"
Write-Host " Git, VSCode, browsers, Dropbox, Zoom, etc."
Write-Host " personal - Personal productivity (Windows Terminal, Teams, VLC, etc.)"
Write-Host " dev - Development tools (Claude, Python, Cloud CLIs, editors)"
Write-Host " infra - Infrastructure (Docker, VMware, Vagrant, DBeaver)"
Write-Host " full - All profiles combined"
Write-Host ""
Write-Host "EXAMPLES:" -ForegroundColor Yellow
Write-Host " # Family computer (default)"
Write-Host " .\install.ps1"
Write-Host ""
Write-Host " # Your personal workstation"
Write-Host " .\install.ps1 -Profile home"
Write-Host " .\install.ps1 -Profile personal"
Write-Host " .\install.ps1 -Profile dev"
Write-Host ""
Write-Host " # Everything at once"
Write-Host " .\install.ps1 -Profile full"
Write-Host ""
Write-Host " # Preview what would be installed"
Write-Host " .\install.ps1 -Profile personal -DryRun"
Write-Host ""
Write-Host " # See individual commands to copy/paste"
Write-Host " .\install.ps1 -ShowCommands -Profile dev"
Write-Host ""
exit 0
}
# Header
Write-Host ""
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host "Windows Applications Installer" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host ""
# Check if winget is available
Write-Step "Checking winget availability..."
if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
Write-Error "winget not found!"
Write-Host "Please install App Installer from Microsoft Store:" -ForegroundColor Yellow
Write-Host " https://www.microsoft.com/p/app-installer/9nblggh4nns1" -ForegroundColor Yellow
exit 1
}
Write-Success "winget found: $(winget --version)"
Write-Host ""
# Read package list based on profile
# Use script directory if available, otherwise use current directory
$scriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { Get-Location }
Write-Step "Reading winget package list..."
Write-Host "Script directory: $scriptDir" -ForegroundColor Gray
Write-Host "Current location: $(Get-Location)" -ForegroundColor Gray
$packages = Get-PackagesFromProfile -PackageType "winget" -Profile $Profile -ScriptDir $scriptDir
if ($packages.Count -eq 0) {
Write-Error "No winget packages found for profile: $Profile"
Write-Host "Available profiles: home, personal, dev, infra, full" -ForegroundColor Yellow
exit 1
}
Write-Host "Found $($packages.Count) packages to install" -ForegroundColor White
Write-Host ""
# Show commands mode
if ($ShowCommands) {
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host "Individual Installation Commands" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Copy and paste these commands to install packages individually:" -ForegroundColor Yellow
Write-Host ""
$packages | ForEach-Object {
Write-Host "winget install --id $_ -e --source winget" -ForegroundColor Green
}
Write-Host ""
Write-Host "TIP: Use these commands to install only specific packages" -ForegroundColor Cyan
Write-Host ""
exit 0
}
# Dry run mode
if ($DryRun) {
Write-Warning "DRY RUN MODE - No packages will be installed"
Write-Host ""
Write-Host "Packages that would be installed:" -ForegroundColor Yellow
$packages | ForEach-Object {
Write-Host " - $_" -ForegroundColor Gray
}
Write-Host ""
Write-Host "Run without -DryRun to install packages" -ForegroundColor Yellow
exit 0
}
# Installation
Write-Step "Starting installation..."
Write-Host ""
$installed = 0
$failed = 0
$skipped = 0
$failedPackages = @()
foreach ($package in $packages) {
Write-Host "[>] Processing: $package" -ForegroundColor Yellow
# Check if already installed (fast check)
$checkResult = winget list --id $package --exact 2>&1
$isInstalled = $LASTEXITCODE -eq 0
if ($isInstalled) {
Write-Host " [=] Already installed: $package" -ForegroundColor Gray
$skipped++
} else {
# Not installed, proceed with installation
Write-Host " [*] Installing..." -ForegroundColor Cyan
try {
$installResult = winget install --id $package --exact --silent --accept-package-agreements --accept-source-agreements 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Success " Installed: $package"
$installed++
} else {
Write-Warning " Failed: $package"
Write-Host " Error details:" -ForegroundColor Gray
$installResult | ForEach-Object {
if ($_ -and $_ -notmatch '^\s*$') {
Write-Host " $_" -ForegroundColor DarkGray
}
}
$failed++
$failedPackages += $package
}
} catch {
Write-Warning " Error installing: $package"
Write-Host " $($_.Exception.Message)" -ForegroundColor Gray
$failed++
$failedPackages += $package
}
}
Write-Host ""
}
# Summary
Write-Host ""
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host "Installation Summary" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host "[+] Installed: $installed" -ForegroundColor Green
Write-Host "[=] Already installed: $skipped" -ForegroundColor Gray
Write-Host "[-] Failed: $failed" -ForegroundColor Red
Write-Host ""
if ($failed -gt 0) {
Write-Warning "Failed packages:"
$failedPackages | ForEach-Object {
Write-Host " - $_" -ForegroundColor Red
}
Write-Host ""
Write-Host "See MANUAL_INSTALL.md for manual installation instructions" -ForegroundColor Yellow
}
# NPM Package Installation
$npmPackages = Get-PackagesFromProfile -PackageType "npm" -Profile $Profile -ScriptDir $scriptDir
if ($npmPackages.Count -gt 0) {
Write-Host ""
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host "NPM Package Installation" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host ""
# Check if npm is available, reload PATH if not
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
Write-Step "npm not found, reloading PATH..."
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# Check again after reloading
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
Write-Warning "npm still not found! Node.js may need to be installed first."
Write-Host "Please restart your terminal and run this script again." -ForegroundColor Yellow
Write-Host ""
}
}
# Proceed with npm installation if available
if (Get-Command npm -ErrorAction SilentlyContinue) {
Write-Success "npm found: $(npm --version)"
Write-Host "Found $($npmPackages.Count) npm packages to install" -ForegroundColor White
Write-Host ""
if (-not $DryRun) {
$npmInstalled = 0
$npmFailed = 0
foreach ($package in $npmPackages) {
Write-Host "[>] Processing: $package" -ForegroundColor Yellow
try {
npm install -g $package --silent 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Success " Installed: $package"
$npmInstalled++
} else {
Write-Warning " Failed: $package"
$npmFailed++
}
} catch {
Write-Warning " Error: $package"
$npmFailed++
}
Write-Host ""
}
# NPM Summary
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host "NPM Installation Summary" -ForegroundColor Cyan
Write-Host "=====================================" -ForegroundColor Cyan
Write-Host "[+] Installed: $npmInstalled" -ForegroundColor Green
Write-Host "[-] Failed: $npmFailed" -ForegroundColor Red
Write-Host ""
}
}
}
Write-Host "Installation complete!" -ForegroundColor Cyan
Write-Host ""