diff --git a/deploy/windows/installer/shopdb-admin.ps1 b/deploy/windows/installer/shopdb-admin.ps1 index 547c56c..cf7673d 100644 --- a/deploy/windows/installer/shopdb-admin.ps1 +++ b/deploy/windows/installer/shopdb-admin.ps1 @@ -22,7 +22,7 @@ [CmdletBinding()] param( [ValidateSet('menu','status','start','stop','restart','logs','open','backup', - 'check','repair','sessions','plugins','add-plugin','verify','uninstall')] + 'check','repair','catalog','sessions','plugins','add-plugin','verify','uninstall')] [string] $Command = 'menu', [string] $Path = '', # Machine-readable output for 'check'. The people running this are expected to @@ -672,6 +672,50 @@ function Invoke-Repair { Restart-App } +function Invoke-Catalog { + Head 'Load the shared equipment catalog' + Say ' Vendors, model numbers, printer supply part numbers and the type' + Say ' lists, as built up across the other sites. It only ADDS - nothing' + Say ' already here is changed or removed - so it is safe to run at any' + Say ' time, including on a site that has been running for years.' + Say '' + Say ' Nothing site-specific is included: no assets, locations or people.' + Say '' + + # Dry run FIRST, always. Somebody running this on a populated site deserves + # to see what it would touch before it touches anything. + Say ' Checking what would be added...' 'White' + $preview = Invoke-Flask @('seed','catalog','--dry-run') + if ($script:LastFlaskExit -ne 0) { + Say ' could not read the catalog' 'Red' + $preview | Select-Object -Last 8 | ForEach-Object { Say " $_" 'Red' } + Say '' + Say ' An older build may not have this command. Update first.' 'Yellow' + return + } + $preview | ForEach-Object { Say " $_" } + + if (($preview | Out-String) -match 'nothing to add') { + Say '' + Say ' Already loaded. Nothing to do.' 'Green' + return + } + + Say '' + $answer = Read-Host ' Load it? (yes/no)' + if ($answer -ne 'yes') { Say ' Left alone.' 'Yellow'; return } + + $out = Invoke-Flask @('seed','catalog') + $out | ForEach-Object { Say " $_" } + if ($script:LastFlaskExit -ne 0) { + Say '' + Say ' Catalog load FAILED. Nothing else was changed.' 'Red' + return + } + Say '' + Say ' Catalog loaded.' 'Green' +} + function Show-Sessions { Head 'Worker processes' $w = Get-CimInstance Win32_Process -Filter "Name='w3wp.exe'" -EA SilentlyContinue @@ -916,6 +960,7 @@ function Show-Menu { Write-Host ' 3 Start the application 8 Open in browser' -ForegroundColor White Write-Host ' 4 View recent logs 9 Plugins' -ForegroundColor White Write-Host ' 5 Health check V Verify this install' -ForegroundColor White + Write-Host ' R Repair provisioning C Load equipment catalog' -ForegroundColor White Write-Host ' 0 Exit' -ForegroundColor White Write-Host '' $c = Read-Host ' Choose' @@ -924,6 +969,8 @@ function Show-Menu { '4' { Show-Logs } '5' { Invoke-Check } '6' { Backup-Db $Path } '7' { Show-Sessions } '8' { Open-Site } 'v' { Invoke-Verify } 'V' { Invoke-Verify } + 'r' { Invoke-Repair } 'R' { Invoke-Repair } + 'c' { Invoke-Catalog } 'C' { Invoke-Catalog } '9' { Show-Plugins $add = Read-Host ' Name of a shipped plugin to add (Enter to skip)' if ($add) { Add-Plugin $add } } @@ -947,6 +994,7 @@ switch ($Command) { 'backup' { Backup-Db $Path } 'check' { Invoke-Check } 'repair' { Invoke-Repair } + 'catalog' { Invoke-Catalog } 'sessions' { Show-Sessions } 'plugins' { Show-Plugins } 'add-plugin'{ Add-Plugin $Path }