diff --git a/README.md b/README.md index 14e3d9b..b6115ec 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ irm 'https://proxy.dandaedre.com/gitea/Beffroi/config-central/raw/branch/main/in The bundled machine profile is `beffroi-laptop`, selected automatically. If you add more machines, setup matches the computer name or asks you to choose one. It installs Git, PowerShell 7, and the declared software, then applies the configs. Approve -administrator prompts when needed. Rerun this command to repair setup. +administrator prompts when needed. Existing managed settings are backed up and +replaced with repository versions. Rerun this command to repair setup. Requires Windows 10 1809 or newer, Windows 11, or Windows Server 2025, with internet access and support for WinGet. diff --git a/TASKS.md b/TASKS.md index 87bf429..520dbcb 100644 --- a/TASKS.md +++ b/TASKS.md @@ -127,3 +127,4 @@ open until it is run on disposable machines with the required account setups. - [x] Use PowerShell 7-compatible ACL application for elevation requests; add Windows-only permission regression tests (Windows execution pending). - [x] Retry an upgrade with an install when WinGet reports no matching installed package, preserving scope and testing bounded retries. - [x] Make web config updates force replacement with backups by default, with an explicit opt-out. +- [x] Apply the force-by-default policy during install/bootstrap too, with a preserve-local-configs opt-out. diff --git a/bootstrap.ps1 b/bootstrap.ps1 index beb986c..f502941 100644 --- a/bootstrap.ps1 +++ b/bootstrap.ps1 @@ -6,6 +6,7 @@ param( [ValidatePattern('^[A-Za-z0-9._/-]+$')][string]$Branch = 'main', [string]$Checkout = (Join-Path $env:LOCALAPPDATA 'ConfigCentral\repository'), [switch]$SkipApply, + [switch]$PreserveLocalConfigs, [switch]$RepairWinGetOnly ) @@ -170,6 +171,10 @@ if (($userPath -split ';') -notcontains $launcherDirectory) { Write-Host "Config Central configured for '$Machine'." if (-not $SkipApply) { - & $powerShell7 -NoLogo -NoProfile -ExecutionPolicy Bypass -File (Join-Path $Checkout 'cc.ps1') apply -Machine $Machine -DataRoot $dataRoot -RepositoryRoot $Checkout + $applyArguments = @('-NoLogo', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', + (Join-Path $Checkout 'cc.ps1'), 'apply', '-Machine', $Machine, + '-DataRoot', $dataRoot, '-RepositoryRoot', $Checkout) + if (-not $PreserveLocalConfigs) { $applyArguments += '-ForceConfigs' } + & $powerShell7 @applyArguments exit $LASTEXITCODE } diff --git a/docs/advanced_commands.md b/docs/advanced_commands.md index d6a4309..29e61e6 100644 --- a/docs/advanced_commands.md +++ b/docs/advanced_commands.md @@ -40,6 +40,16 @@ For unattended installation, select the machine in the same command: $env:CONFIG_CENTRAL_MACHINE = 'beffroi-laptop'; irm 'https://proxy.dandaedre.com/gitea/Beffroi/config-central/raw/branch/main/install.ps1' | iex ``` +Setup backs up and replaces existing managed settings by default, just like the +web config updater. To preserve local settings and report conflicts during setup: + +```powershell +& ([scriptblock]::Create((irm 'https://proxy.dandaedre.com/gitea/Beffroi/config-central/raw/branch/main/install.ps1'))) -PreserveLocalConfigs +``` + +The same `-PreserveLocalConfigs` switch is available on `bootstrap.ps1`. +`-SkipApply` continues to skip deployment entirely. + The installer is safe to rerun for repair or setup updates. Use the web updater for routine config updates. Use `cc sync` when you also want package updates. diff --git a/install.ps1 b/install.ps1 index d6d9583..7d875d0 100644 --- a/install.ps1 +++ b/install.ps1 @@ -3,7 +3,8 @@ param( [string]$Machine = $env:CONFIG_CENTRAL_MACHINE, [string]$Branch = $env:CONFIG_CENTRAL_BRANCH, - [switch]$SkipApply + [switch]$SkipApply, + [switch]$PreserveLocalConfigs ) Set-StrictMode -Version 2.0 @@ -125,6 +126,7 @@ try { '-Repository', $repository, '-Branch', $Branch, '-Machine', $Machine ) if ($SkipApply) { $arguments += '-SkipApply' } + if ($PreserveLocalConfigs) { $arguments += '-PreserveLocalConfigs' } & $windowsPowerShell @arguments $bootstrapExitCode = $LASTEXITCODE diff --git a/tests/Installer.Tests.ps1 b/tests/Installer.Tests.ps1 index ed98119..e43ede0 100644 --- a/tests/Installer.Tests.ps1 +++ b/tests/Installer.Tests.ps1 @@ -59,3 +59,24 @@ Describe 'One-stop installer machine selection' { } } } + +Describe 'Setup config replacement policy' { + It 'forwards the preserve option through setup and disables force only when requested' { + $installerText = Get-Content "$PSScriptRoot/../install.ps1" -Raw + $bootstrapText = Get-Content "$PSScriptRoot/../bootstrap.ps1" -Raw + $installerArguments = [regex]::Match($installerText, '(?s) \$arguments = @\(.*?(?= & \$windowsPowerShell)').Value + $bootstrapArguments = [regex]::Match($bootstrapText, '(?s) \$applyArguments = @\(.*?(?= & \$powerShell7)').Value + $installerArguments | Should -Not -BeNullOrEmpty + $bootstrapArguments | Should -Not -BeNullOrEmpty + $bootstrapPath = 'bootstrap.ps1'; $repository = 'https://example.test/repo.git' + $Branch = 'main'; $Machine = 'test'; $SkipApply = $false + $Checkout = $TestDrive; $dataRoot = $TestDrive + foreach ($preserve in @($false, $true)) { + $PreserveLocalConfigs = $preserve + . ([scriptblock]::Create($installerArguments)) + ($arguments -contains '-PreserveLocalConfigs') | Should -Be $preserve + . ([scriptblock]::Create($bootstrapArguments)) + ($applyArguments -contains '-ForceConfigs') | Should -Be (-not $preserve) + } + } +}