Show managed config locations

This commit is contained in:
Dandaedre 2026-10-17 08:01:21 +02:00
parent 9387a472bf
commit 1ad10c50f4
6 changed files with 55 additions and 5 deletions

View File

@ -102,6 +102,7 @@ open until it is run on disposable machines with the required account setups.
## Requested desktop configuration
- [x] Show each managed config's repository source and resolved computer path.
- [x] Add the requested WinGet packages: XnView MP, Zoom, Nextcloud Desktop,
Notepad++, HandBrake, GIMP, Krita, LibreOffice, Waterfox, and Shotcut.
- [x] Add a safe registry-value adapter for MPC-HC settings.

2
cc.ps1
View File

@ -1,6 +1,6 @@
[CmdletBinding()]
param(
[Parameter(Position = 0)][ValidateSet('doctor', 'plan', 'apply', 'sync', 'status', 'restore', 'schedule', 'unschedule', 'menu')][string]$Command = 'menu',
[Parameter(Position = 0)][ValidateSet('doctor', 'plan', 'apply', 'sync', 'status', 'configs', 'restore', 'schedule', 'unschedule', 'menu')][string]$Command = 'menu',
[string]$Machine,
[string]$Config,
[switch]$ConfigsOnly,

View File

@ -82,6 +82,36 @@ function Get-ConfigPlan {
return @($plan)
}
function Get-ConfigLocations {
param(
[Parameter(Mandatory)]$Configs,
[Parameter(Mandatory)][string]$RepositoryRoot,
[Parameter(Mandatory)]$Settings,
[string]$Name
)
$pathMap = Get-UserPathMap -Settings $Settings
$selected = @($Configs)
if (-not [string]::IsNullOrWhiteSpace($Name)) {
$selected = @($selected | Where-Object { $_.name -eq $Name })
if ($selected.Count -eq 0) { throw "Unknown config '$Name'." }
}
$locations = [System.Collections.Generic.List[object]]::new()
foreach ($config in $selected) {
$source = Resolve-ConfigSource -RepositoryRoot $RepositoryRoot -Source $config.source
$target = if ($config.mode -eq 'registry') { [string]$config.target } else { Resolve-ConfigTarget -Target $config.target -PathMap $pathMap }
$targetExists = [bool](Test-Path -LiteralPath $target -ErrorAction SilentlyContinue)
$locations.Add([pscustomobject]@{
kind = 'config'; name = [string]$config.name
status = if ($targetExists) { 'Present' } else { 'Missing' }
message = "Repository: $source | Computer: $target"
mode = [string]$config.mode; source = $source; target = $target
sourceExists = $true; targetExists = $targetExists
})
}
return @($locations)
}
function Backup-ConfigTarget {
param($Operation, $Paths)
if (-not (Test-Path -LiteralPath $Operation.target -PathType Leaf)) { return $null }
@ -163,4 +193,4 @@ function Restore-ConfigBackup {
[pscustomobject]@{ name = $Name; status = 'Restored'; message = "Restored $($backup.FullName)" }
}
Export-ModuleMember -Function Get-UserPathMap, Resolve-ConfigTarget, Resolve-ConfigSource, Get-FileHashValue, Get-ConfigPlan, Invoke-ConfigOperation, Restore-ConfigBackup
Export-ModuleMember -Function Get-UserPathMap, Resolve-ConfigTarget, Resolve-ConfigSource, Get-FileHashValue, Get-ConfigPlan, Get-ConfigLocations, Invoke-ConfigOperation, Restore-ConfigBackup

View File

@ -132,6 +132,13 @@ function Invoke-ConfigCentral {
[string]$Revision
)
if ($Command -eq 'doctor') { return Invoke-Doctor -Machine $Machine -RepositoryRoot $RepositoryRoot -Paths $Paths }
if ($Command -eq 'configs') {
$settings = Read-JsonState -Path $Paths.Settings -Default ([ordered]@{})
$effective = Resolve-MachineManifest -RepositoryRoot $RepositoryRoot -Machine $Machine
$result = New-BaseResult 'configs'
$result.operations = @(Get-ConfigLocations -Configs $effective.configs -RepositoryRoot $RepositoryRoot -Settings $settings -Name $Config)
return [pscustomobject]$result
}
if ($Command -eq 'restore') {
if ([string]::IsNullOrWhiteSpace($Config)) { throw 'restore requires -Config NAME.' }
$state = Read-JsonState -Path $Paths.State -Default ([ordered]@{})
@ -183,9 +190,9 @@ function Write-ConfigCentralResult {
function Show-ConfigCentralMenu {
param([string]$Machine, [string]$DataRoot, [string]$RepositoryRoot)
Write-Host 'Config Central'
Write-Host '1. Plan 2. Sync 3. Status 4. Doctor 5. Schedule Q. Quit'
Write-Host '1. Plan 2. Sync 3. Status 4. Doctor 5. Schedule 6. Config paths Q. Quit'
$choice = Read-Host 'Select'
$command = switch ($choice.ToUpperInvariant()) { '1' { 'plan' } '2' { 'sync' } '3' { 'status' } '4' { 'doctor' } '5' { 'schedule' } 'Q' { return } default { throw "Unknown menu choice '$choice'." } }
$command = switch ($choice.ToUpperInvariant()) { '1' { 'plan' } '2' { 'sync' } '3' { 'status' } '4' { 'doctor' } '5' { 'schedule' } '6' { 'configs' } 'Q' { return } default { throw "Unknown menu choice '$choice'." } }
$arguments = @($command, '-RepositoryRoot', $RepositoryRoot)
if ($Machine) { $arguments += @('-Machine', $Machine) }
if ($DataRoot) { $arguments += @('-DataRoot', $DataRoot) }

View File

@ -59,6 +59,18 @@ Describe 'Configuration deployment' {
Test-Path -LiteralPath $configs[0].target | Should -BeTrue
}
It 'reports repository and computer config locations without changing them' {
New-Item -ItemType Directory (Split-Path -Parent $destination) -Force | Out-Null
'computer value' | Set-Content $destination -NoNewline
$locations = Get-ConfigLocations -Configs $configs -RepositoryRoot $repo -Settings $settings -Name sample
$locations.Count | Should -Be 1
$locations[0].source | Should -Be (Join-Path $repo 'configs/config.txt')
$locations[0].target | Should -Be $destination
$locations[0].targetExists | Should -BeTrue
(Get-Content -LiteralPath $destination -Raw) | Should -Be 'computer value'
{ Get-ConfigLocations -Configs $configs -RepositoryRoot $repo -Settings $settings -Name missing } | Should -Throw "*Unknown config 'missing'*"
}
It 'refuses unsafe automatic restoration of registry and hosts backups' {
$registryState = @{ configs = @{ 'mpc-hc-settings' = @{ mode = 'registry'; target = 'HKCU:\Software\MPC-HC\MPC-HC' } } }
{ Restore-ConfigBackup -Name mpc-hc-settings -Paths $paths -State $registryState } | Should -Throw '*not supported for registry*'

View File

@ -91,7 +91,7 @@ def main() -> int:
except json.JSONDecodeError as exc:
errors.append(f"{path.relative_to(ROOT)}: {exc}")
required_cli_markers = ("doctor", "plan", "apply", "sync", "status", "restore", "schedule", "unschedule", "menu")
required_cli_markers = ("doctor", "plan", "apply", "sync", "status", "configs", "restore", "schedule", "unschedule", "menu")
cli = (ROOT / "cc.ps1").read_text(encoding="utf-8-sig")
for marker in required_cli_markers:
if not re.search(rf"['\"]{re.escape(marker)}['\"]", cli):