-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.ps1
More file actions
307 lines (274 loc) · 14.3 KB
/
Copy pathsetup.ps1
File metadata and controls
307 lines (274 loc) · 14.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
<#
.SYNOPSIS
Sets up Git, Node.js, Python, and VS Code settings without admin rights or GUI installers.
.DESCRIPTION
Bootstraps user-local PortableGit when needed (which also configures the
credential helper), installs Node.js and Python, and applies VS Code
settings last. Python setup runs natively in PowerShell rather than through
Git Bash, since PortableGit's minimal Bash/coreutils are not a reliable
environment for running installer scripts.
Every tunable lives in config/dev-setup.config.json. Parameters here override
it for a single run. The final step runs src/configure-vscode.py, which stores
the syncable VS Code settings including Dev Containers defaults. Dev containers
stay opt-in; nothing is containerized by this script.
#>
param(
[string]$GitInstallDir,
[string]$PythonVersion,
[switch]$SkipVSCodeSettings,
[switch]$SkipUpgradeCheck,
[switch]$CheckUpgradesOnly,
[switch]$Uninstall,
[switch]$Audit
)
$ErrorActionPreference = "Stop"
. (Join-Path $PSScriptRoot "src\config.ps1")
function Write-DevSetupSection {
param([Parameter(Mandatory)][string]$Title)
Write-Host ""
Write-Host ("=" * 78) -ForegroundColor DarkCyan
Write-Host (" {0}" -f $Title.ToUpperInvariant()) -ForegroundColor Cyan
Write-Host ("=" * 78) -ForegroundColor DarkCyan
}
function Write-DevSetupHeader {
param([Parameter(Mandatory)]$Config, [Parameter(Mandatory)][string]$Mode)
Write-DevSetupSection "Blackout Secure Dev Setup Kit"
Write-Host " Author: Blackout Secure"
Write-Host " Standard: Config-driven developer environment setup"
Write-Host " Standard version: 1"
Write-Host " Script: setup.ps1"
Write-Host " PowerShell: $($PSVersionTable.PSVersion)"
Write-Host " Run mode: $Mode"
Write-Host " Repository root: $DevSetupRoot"
Write-Host " Configuration: $DevSetupConfigPath"
Write-Host " Python target: $(Get-DevSetupValue $Config 'user.python.version' '3.14')"
}
function Write-DevSetupConfiguration {
param(
[Parameter(Mandatory)]$Config,
[Parameter(Mandatory)][string]$GitInstallDir,
[Parameter(Mandatory)][string]$PythonVersion,
[Parameter(Mandatory)][bool]$ConfigureVSCode,
[Parameter(Mandatory)][bool]$CheckUpgrades
)
Write-DevSetupSection "Configuration"
Write-Host " Resolved runtime variables:"
Write-Host " GitInstallDir = $GitInstallDir"
Write-Host " PythonVersion = $PythonVersion"
Write-Host " ConfigureVSCode = $ConfigureVSCode"
Write-Host " CheckUpgrades = $CheckUpgrades"
Write-Host " Audit = $Audit"
Write-Host " Uninstall = $Uninstall"
Write-Host " Config file = $DevSetupConfigPath"
Write-Host ""
Write-Host " Loaded configuration:"
$profiles = @(Get-DevSetupValue $Config 'user.vscode.profiles' @('stable', 'insiders'))
$extensions = @(Get-DevSetupValue $Config 'user.vscode.extensions.install' @())
$mcpServers = Get-DevSetupValue $Config 'user.mcp.servers' ([pscustomobject]@{})
$mcpCount = @($mcpServers.PSObject.Properties).Count
Write-Host " Install tools: Git=$((Get-DevSetupValue $Config 'user.install.git' $true)), Node=$((Get-DevSetupValue $Config 'user.install.node' $true)), Prettier=$((Get-DevSetupValue $Config 'user.install.prettier' $true)), Python=$((Get-DevSetupValue $Config 'user.install.python' $true)), PHP=$((Get-DevSetupValue $Config 'user.install.php' $true))"
Write-Host " PowerShell=$((Get-DevSetupValue $Config 'user.install.powershell' $true)), ShellCheck=$((Get-DevSetupValue $Config 'user.install.shellcheck' $true)), ripgrep=$((Get-DevSetupValue $Config 'user.install.ripgrep' $true)), GPG=$((Get-DevSetupValue $Config 'user.install.gpg' $true))"
Write-Host " VS Code: settings=$((Get-DevSetupValue $Config 'user.install.vscodeSettings' $true)), profiles=$($profiles -join ', '), extensions=$($extensions.Count) managed"
Write-Host " User Sync: enabled=$((Get-DevSetupValue $Config 'user.vscode.settingsSync.syncAfterSetup' $false)), provider=$((Get-DevSetupValue $Config 'user.vscode.settingsSync.requiredProvider' 'github'))"
Write-Host " MCP servers: $mcpCount configured"
Write-Host " Dev containers: defaults=$((Get-DevSetupValue $Config 'user.install.devcontainerDefaults' $true)), base=$((Get-DevSetupValue $Config 'user.devcontainers.baseImage' 'not configured'))"
Write-Host " Config sections: user, advanced"
}
try {
Clear-Host -ErrorAction Stop
} catch {
# Non-interactive hosts may not provide a console handle to clear.
}
$configPath = $DevSetupConfigPath
$config = Get-DevSetupConfig $configPath
$scripts = Join-Path $PSScriptRoot "src\scripts"
$statusLog = Join-Path ([System.IO.Path]::GetTempPath()) ("devsetup-status-{0}.log" -f [guid]::NewGuid())
New-Item -Path $statusLog -ItemType File -Force | Out-Null
$env:DEVSETUP_STATUS_LOG = $statusLog
if (-not $GitInstallDir) {
$GitInstallDir = Expand-DevSetupPath (Get-DevSetupValue $config "user.git.installDir" (
Get-DevSetupValue $config "advanced.git.defaultInstallDir" "$env:USERPROFILE\PortableGit"))
}
if (-not $PythonVersion) {
$PythonVersion = Get-DevSetupValue $config "user.python.version" "3.14"
}
$configureVSCode = (-not $SkipVSCodeSettings) -and (Get-DevSetupValue $config "user.install.vscodeSettings" $true)
$checkUpgrades = $CheckUpgradesOnly -or ((-not $SkipUpgradeCheck) -and (Get-DevSetupValue $config "user.checkUpgrades" $true))
$gitExe = $null
$pythonExe = $null
$phpExe = $null
$powerShellExe = $null
$runMode = if ($Uninstall) { "Uninstall" } elseif ($CheckUpgradesOnly) { "Upgrade check" } elseif ($Audit) { "Audit" } else { "Setup" }
Write-DevSetupHeader -Config $config -Mode $runMode
Write-DevSetupConfiguration -Config $config -GitInstallDir $GitInstallDir -PythonVersion $PythonVersion -ConfigureVSCode $configureVSCode -CheckUpgrades $checkUpgrades
Write-DevSetupSection "Live Activity"
if ($Uninstall) {
Write-Host "Uninstalling (each step only removes tools this kit manages; Git is never removed):"
if (Get-DevSetupValue $config "user.install.git" $true) {
& (Join-Path $scripts "install-portable-git.ps1") -Uninstall -Audit:$Audit
}
if (Get-DevSetupValue $config "user.install.node" $true) {
& (Join-Path $scripts "install-node.ps1") -Uninstall -Audit:$Audit
}
if (Get-DevSetupValue $config "user.install.prettier" $true) {
& (Join-Path $scripts "install-prettier.ps1") -Uninstall -Audit:$Audit
}
if (Get-DevSetupValue $config "user.install.python" $true) {
& (Join-Path $scripts "install-python.ps1") -PythonVersion $PythonVersion -Uninstall -Audit:$Audit
}
if (Get-DevSetupValue $config "user.install.php" $true) {
& (Join-Path $scripts "install-php.ps1") -Uninstall -Audit:$Audit
}
if (Get-DevSetupValue $config "user.install.powershell" $true) {
& (Join-Path $scripts "install-powershell.ps1") -Uninstall -Audit:$Audit
}
if (Get-DevSetupValue $config "user.install.shellcheck" $true) {
& (Join-Path $scripts "install-shellcheck.ps1") -Uninstall -Audit:$Audit
}
if (Get-DevSetupValue $config "user.install.ripgrep" $true) {
& (Join-Path $scripts "install-ripgrep.ps1") -Uninstall -Audit:$Audit
}
if (Get-DevSetupValue $config "user.install.gpg" $true) {
& (Join-Path $scripts "install-gpg.ps1") -Uninstall -Audit:$Audit
}
Write-Host ""
if ($Audit) {
Write-Host "Uninstall audit complete. Nothing was removed. Re-run with -Uninstall (without -Audit) to apply."
} else {
Write-Host "Uninstall complete."
}
Write-DevSetupSummary -LogPath $statusLog -Audit:$Audit
Remove-Item $statusLog -ErrorAction SilentlyContinue
Remove-Item Env:\DEVSETUP_STATUS_LOG -ErrorAction SilentlyContinue
return
}
if ($CheckUpgradesOnly) {
Write-Host "Checking for upgrades (detect only - nothing will be installed or changed):"
if (Get-DevSetupValue $config "user.install.git" $true) {
& (Join-Path $scripts "install-portable-git.ps1") -InstallDir $GitInstallDir -Audit -CheckUpgrades | Out-Null
}
if (Get-DevSetupValue $config "user.install.node" $true) {
& (Join-Path $scripts "install-node.ps1") -Audit -CheckUpgrades
}
if (Get-DevSetupValue $config "user.install.prettier" $true) {
& (Join-Path $scripts "install-prettier.ps1") -Audit -CheckUpgrades
}
if (Get-DevSetupValue $config "user.install.python" $true) {
& (Join-Path $scripts "install-python.ps1") -PythonVersion $PythonVersion -Audit -CheckUpgrades | Out-Null
}
if (Get-DevSetupValue $config "user.install.php" $true) {
& (Join-Path $scripts "install-php.ps1") -Audit -CheckUpgrades | Out-Null
}
if (Get-DevSetupValue $config "user.install.powershell" $true) {
& (Join-Path $scripts "install-powershell.ps1") -Audit -CheckUpgrades | Out-Null
}
if (Get-DevSetupValue $config "user.install.shellcheck" $true) {
& (Join-Path $scripts "install-shellcheck.ps1") -Audit -CheckUpgrades
}
if (Get-DevSetupValue $config "user.install.ripgrep" $true) {
& (Join-Path $scripts "install-ripgrep.ps1") -Audit -CheckUpgrades
}
if (Get-DevSetupValue $config "user.install.gpg" $true) {
& (Join-Path $scripts "install-gpg.ps1") -Audit -CheckUpgrades
}
Write-Host ""
Write-Host "Upgrade check complete. Nothing was installed or changed."
Write-DevSetupSummary -LogPath $statusLog -Audit
Remove-Item $statusLog -ErrorAction SilentlyContinue
Remove-Item Env:\DEVSETUP_STATUS_LOG -ErrorAction SilentlyContinue
return
}
if ($Audit) {
Write-Host "Auditing (detect only - nothing will be installed or changed):"
} else {
Write-Host "Running setup (each step is skipped when already satisfied):"
}
Write-DevSetupStatus skip "WSL" "not installed or invoked by setup.ps1 (see setup-wsl.ps1 for existing WSL user setup)"
if (Get-DevSetupValue $config "user.install.git" $true) {
$gitExe = & (Join-Path $scripts "install-portable-git.ps1") -InstallDir $GitInstallDir -ConfigureVSCode:$configureVSCode -PrintPath:$configureVSCode -Audit:$Audit -CheckUpgrades:$checkUpgrades |
Select-Object -Last 1
} else {
Write-DevSetupStatus skip "Git" "user.install.git is false"
}
if (Get-DevSetupValue $config "user.install.node" $true) {
& (Join-Path $scripts "install-node.ps1") -Audit:$Audit -CheckUpgrades:$checkUpgrades
} else {
Write-DevSetupStatus skip "Node.js" "user.install.node is false"
}
if (Get-DevSetupValue $config "user.install.prettier" $true) {
& (Join-Path $scripts "install-prettier.ps1") -Audit:$Audit -CheckUpgrades:$checkUpgrades
} else {
Write-DevSetupStatus skip "Prettier" "user.install.prettier is false"
}
if (Get-DevSetupValue $config "user.install.python" $true) {
# install-python.ps1 emits the resolved interpreter path as its last output.
$pythonExe = & (Join-Path $scripts "install-python.ps1") -PythonVersion $PythonVersion -ConfigureVSCode:$configureVSCode -Audit:$Audit -CheckUpgrades:$checkUpgrades |
Select-Object -Last 1
} else {
Write-DevSetupStatus skip "Python" "user.install.python is false"
}
if (Get-DevSetupValue $config "user.install.php" $true) {
$phpExe = & (Join-Path $scripts "install-php.ps1") -Audit:$Audit -CheckUpgrades:$checkUpgrades | Select-Object -Last 1
} else {
Write-DevSetupStatus skip "PHP" "user.install.php is false"
}
if (Get-DevSetupValue $config "user.install.powershell" $true) {
$powerShellExe = & (Join-Path $scripts "install-powershell.ps1") -Audit:$Audit -CheckUpgrades:$checkUpgrades | Select-Object -Last 1
} else {
Write-DevSetupStatus skip "PowerShell" "user.install.powershell is false"
}
if (Get-DevSetupValue $config "user.install.shellcheck" $true) {
& (Join-Path $scripts "install-shellcheck.ps1") -Audit:$Audit -CheckUpgrades:$checkUpgrades
} else {
Write-DevSetupStatus skip "ShellCheck" "user.install.shellcheck is false"
}
if (Get-DevSetupValue $config "user.install.ripgrep" $true) {
& (Join-Path $scripts "install-ripgrep.ps1") -Audit:$Audit -CheckUpgrades:$checkUpgrades
} else {
Write-DevSetupStatus skip "ripgrep" "user.install.ripgrep is false"
}
if (Get-DevSetupValue $config "user.install.gpg" $true) {
try {
& (Join-Path $scripts "install-gpg.ps1") -Audit:$Audit -CheckUpgrades:$checkUpgrades
} catch {
Write-DevSetupStatus warn "GPG" $_.Exception.Message
}
} else {
Write-DevSetupStatus skip "GPG" "user.install.gpg is false"
}
if (-not $configureVSCode) {
$reason = if ($SkipVSCodeSettings) { "-SkipVSCodeSettings was passed" } else { "user.install.vscodeSettings is false" }
Write-DevSetupStatus skip "vscode" $reason
}
if ($configureVSCode) {
if (-not ($pythonExe -and (Test-Path $pythonExe))) {
# install-python.ps1 updates the user-level PATH, which the current session
# does not inherit, so rebuild $env:Path before looking for the interpreter.
$env:Path = ((
[Environment]::GetEnvironmentVariable("Path", "Machine"),
[Environment]::GetEnvironmentVariable("Path", "User")
) | Where-Object { $_ }) -join ";"
$pythonExe = Get-Command python.exe -ErrorAction SilentlyContinue |
Where-Object { $_.Source -notlike "*\Microsoft\WindowsApps\*" } |
Select-Object -First 1 -ExpandProperty Source
}
if ($pythonExe) {
$arguments = @((Join-Path $PSScriptRoot "src\configure-vscode.py"), "--config", $configPath, "--python-path", $pythonExe)
if ($gitExe -and (Test-Path $gitExe)) { $arguments += @("--git-path", $gitExe) }
if ($phpExe -and (Test-Path $phpExe)) { $arguments += @("--php-path", $phpExe) }
if ($powerShellExe -and (Test-Path $powerShellExe)) { $arguments += @("--powershell-path", $powerShellExe) }
if ($Audit) { $arguments += "--dry-run" }
& $pythonExe $arguments
} else {
Write-DevSetupStatus warn "vscode" "Python not on PATH; run src/configure-vscode.py manually from a new terminal"
}
}
Write-Host ""
if ($Audit) {
Write-Host "Audit complete. Nothing was installed or changed. Re-run without -Audit to apply."
} else {
Write-Host "Setup complete."
}
Write-DevSetupSummary -LogPath $statusLog -Audit:$Audit
Remove-Item $statusLog -ErrorAction SilentlyContinue
Remove-Item Env:\DEVSETUP_STATUS_LOG -ErrorAction SilentlyContinue