-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
151 lines (121 loc) · 4.94 KB
/
Copy pathsetup.ps1
File metadata and controls
151 lines (121 loc) · 4.94 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
#!/usr/bin/env pwsh
<#
.SYNOPSIS
Windows Post-Format Automation Setup Script
.DESCRIPTION
Automates installation and configuration of Windows after a clean format.
Runs selectively by group or executes all groups.
.PARAMETER Group
Specific group to execute: base, dev, gaming, or omit for all. The 'restore'
group reverses winforge's changes and runs ONLY when named explicitly (it is
never part of the default all-groups run). Use -WhatIf to preview it.
Examples:
.\setup.ps1 -Group dev
.\setup.ps1 -Group restore -WhatIf # preview the reversal
.\setup.ps1 # executes all groups (never restore)
.PARAMETER Profile
Safety profile for the optimize group: safe (default), desktop, or gaming.
'safe' applies only reversible tweaks; 'desktop' adds power/24-7 tweaks;
'gaming' adds network and aggressive service tweaks. Ignored by other groups.
.PARAMETER SkipElevation
Skip elevation check (for testing in current context).
#>
[CmdletBinding(SupportsShouldProcess)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidAssignmentToAutomaticVariable', 'Profile',
Justification = 'Public -Profile parameter forwarded to the optimize module; the automatic $PROFILE variable is not used.')]
param(
[Parameter(Mandatory = $false)]
[ValidateSet("base", "dev", "gaming", "system", "optimize", "customize", "shell", "restore")]
[string]$Group,
[Parameter(Mandatory = $false)]
[ValidateSet("safe", "desktop", "gaming")]
[string]$Profile = "safe",
[switch]$SkipElevation
)
# ========== Initialization ==========
# Surface undefined variables, missing properties and bad indexing early.
Set-StrictMode -Version Latest
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$srcPath = Join-Path $scriptRoot "src"
$corePath = Join-Path $srcPath "core"
$utilsPath = Join-Path $srcPath "utils"
$modulesPath = Join-Path $srcPath "modules"
# ========== Load Libraries (in order) ==========
# 1. Logging (needed by everything else)
. "$utilsPath\Logging.ps1"
# 2. System utilities (elevation, admin checks)
. "$utilsPath\System.ps1"
if (-not $SkipElevation) {
Request-Elevation -ScriptPath $MyInvocation.MyCommand.Path -BoundParameters $PSBoundParameters
}
# 3. Validation (installation detection)
. "$utilsPath\Validation.ps1"
# 4. Registry utilities (system configuration)
. "$utilsPath\Registry.ps1"
# 5. Core installation logic
. "$corePath\Installation.ps1"
Write-Host ""
Write-Host "Windows Post-Format Automation Setup" -ForegroundColor Cyan
Write-Host "PowerShell 7+" -ForegroundColor Cyan
Write-Host ""
if (Test-IsElevated) {
Write-Log "Running with administrator privileges" -Level Success
}
else {
Write-Log "WARNING: Not running as administrator" -Level Warning
Write-Host ""
Write-Host "Some features require administrator privileges (fonts, registry, services)." -ForegroundColor Yellow
Write-Host "Run as admin with: powershell -NoProfile -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -ForegroundColor Gray
Write-Host ""
# Try to ask for confirmation, but continue if in NonInteractive mode
try {
$continueAnyway = Read-Host "Continue without admin? (y/n)" -ErrorAction Stop
if ($continueAnyway -ne "y" -and $continueAnyway -ne "Y") {
Write-Log "Cancelled by user" -Level Info
exit 0
}
}
catch {
Write-Log "NonInteractive mode detected, continuing without admin..." -Level Info
}
}
# ========== Execute Groups ==========
$groupsToRun = @()
if ($Group) {
$groupsToRun = @($Group)
Write-Log "Running group: $Group" -Level Info
}
else {
# NOTE: 'restore' is intentionally excluded from the default run — it reverses
# winforge's changes and must be requested explicitly (-Group restore).
$groupsToRun = @("base", "dev", "gaming", "system", "optimize", "customize", "shell")
Write-Log "Running all groups" -Level Info
}
foreach ($groupName in $groupsToRun) {
$moduleFile = Join-Path $modulesPath "$groupName.ps1"
if (Test-Path -Path $moduleFile) {
try {
. $moduleFile
# Install programs
if (Get-Command -Name "Install-$groupName`Programs" -ErrorAction SilentlyContinue) {
& "Install-$groupName`Programs"
}
# Apply configuration (optimize takes the safety Profile)
if (Get-Command -Name "Set-$groupName`Configuration" -ErrorAction SilentlyContinue) {
$configArgs = @{}
if ($groupName -eq "optimize") { $configArgs["Profile"] = $Profile }
& "Set-$groupName`Configuration" @configArgs
}
}
catch {
Write-Log "Error executing group '$groupName': $_" -Level Error
}
}
else {
Write-Log "Module file not found: $moduleFile" -Level Error
}
}
# ========== Summary ==========
Write-Host ""
Write-Log "Setup completed" -Level Success
Write-Host ""