Shared machine-number helper, site-config for OpenText + PreInstall, placeholder type dirs

Three optimization batches from the pipeline audit:

1. Shared Update-MachineNumber.ps1 helper (lib/)
   Extracts duplicated machine-number update logic from Configure-PC.ps1,
   Check-MachineNumber.ps1, and Set-MachineNumber.ps1 into a shared
   dot-sourceable helper at Shopfloor/lib/Update-MachineNumber.ps1.

   Exports:
     Get-CurrentMachineNumber → @{ Udc = $string; Ednc = $string }
     Update-MachineNumber -NewNumber <n> [-Site <s>] → @{ UdcUpdated; EdncUpdated; Errors }

   All three consumers now dot-source the helper instead of duplicating
   ~50 lines each. Set-MachineNumber.ps1 also migrated from inline
   Get-SiteConfig to dot-sourcing Get-PCProfile.ps1 for consistency.

2. Site-config integration for remaining scripts
   Setup-OpenText.ps1: exclude lists (profiles + shortcuts) now read from
     site-config.json opentext section, falling back to West Jefferson
     defaults. Inline Get-SiteConfig since the script runs from
     C:\PreInstall\installers\opentext\ (can't dot-source Get-PCProfile).

   00-PreInstall-MachineApps.ps1: after parsing preinstall.json, scans
     InstallArgs for "West Jefferson" and replaces with site-config
     siteName if different. Inline Get-SiteConfig for same reason.

3. Placeholder type-specific directories
   Created skeleton 01-Setup-*.ps1 scripts for all PC types so the
   directory structure is in place and Run-ShopfloorSetup's type-specific
   loop has something to iterate over:
     Genspect/01-Setup-Genspect.ps1
     Keyence/01-Setup-Keyence.ps1
     WaxAndTrace/01-Setup-WaxAndTrace.ps1
     Lab/01-Setup-Lab.ps1
   Each logs a "no type-specific apps configured yet" banner and exits.
   Fill in app installs when details are finalized; for share-based
   installs, copy the CMM/01-Setup-CMM.ps1 pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-04-10 11:44:10 -04:00
parent b236b18fbc
commit 7c8eb6899d
10 changed files with 262 additions and 274 deletions

View File

@@ -31,6 +31,7 @@ Write-Host "Running as: $([System.Security.Principal.WindowsIdentity]::GetCurren
# Load site config + PC profile (resolves pc-type.txt + pc-subtype.txt
# into a profile from site-config.json's pcProfiles section)
. "$PSScriptRoot\lib\Get-PCProfile.ps1"
. "$PSScriptRoot\lib\Update-MachineNumber.ps1"
$startupDir = 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup'
$publicDesktop = 'C:\Users\Public\Desktop'
@@ -88,25 +89,9 @@ function New-StartupLnk {
# Machine number - read current state
# ============================================================================
$udcSettingsPath = 'C:\ProgramData\UDC\udc_settings.json'
$udcExePath = 'C:\Program Files\UDC\UDC.exe'
$ednRegPath = 'HKLM:\SOFTWARE\WOW6432Node\GE Aircraft Engines\DNC\General'
$currentUdc = $null
$currentEdnc = $null
if (Test-Path $udcSettingsPath) {
try {
$json = Get-Content $udcSettingsPath -Raw | ConvertFrom-Json
$currentUdc = $json.GeneralSettings.MachineNumber
} catch {}
}
if (Test-Path $ednRegPath) {
try {
$currentEdnc = (Get-ItemProperty -Path $ednRegPath -Name MachineNo -ErrorAction Stop).MachineNo
} catch {}
}
$currentMN = Get-CurrentMachineNumber
$currentUdc = $currentMN.Udc
$currentEdnc = $currentMN.Ednc
$needsMachineNumber = ($currentUdc -eq '9999' -or $currentEdnc -eq '9999')
@@ -296,44 +281,19 @@ if ($needsMachineNumber) {
$newNum = $newNum.Trim()
if ($newNum -and $newNum -match '^\d+$') {
$updated = @()
$site = if ($siteConfig) { $siteConfig.siteName } else { 'West Jefferson' }
$mnResult = Update-MachineNumber -NewNumber $newNum -Site $site
# Stop UDC before editing its JSON
Get-Process UDC -ErrorAction SilentlyContinue | ForEach-Object {
try { $_.Kill(); $_.WaitForExit(5000) | Out-Null } catch {}
if ($mnResult.UdcUpdated) {
Write-Host " UDC : $currentUdc -> $newNum" -ForegroundColor Green
$currentUdc = $newNum
}
Start-Sleep -Seconds 1
# UDC JSON
if (Test-Path $udcSettingsPath) {
try {
$json = Get-Content $udcSettingsPath -Raw | ConvertFrom-Json
$json.GeneralSettings.MachineNumber = $newNum
$json | ConvertTo-Json -Depth 99 | Set-Content -Path $udcSettingsPath -Encoding UTF8
Write-Host " UDC : $currentUdc -> $newNum" -ForegroundColor Green
$updated += 'UDC'
$currentUdc = $newNum
} catch { Write-Warning " UDC update failed: $_" }
}
# eDNC registry
if (Test-Path $ednRegPath) {
try {
Set-ItemProperty -Path $ednRegPath -Name MachineNo -Value $newNum -Type String -Force
Write-Host " eDNC : $currentEdnc -> $newNum" -ForegroundColor Green
$updated += 'eDNC'
$currentEdnc = $newNum
} catch { Write-Warning " eDNC update failed: $_" }
}
# Relaunch UDC
if ((Test-Path $udcExePath) -and $updated -contains 'UDC') {
try {
$site = if ($siteConfig) { $siteConfig.siteName } else { 'West Jefferson' }
Start-Process -FilePath $udcExePath -ArgumentList @('-site', "`"$site`"", '-machine', $newNum)
Write-Host " UDC.exe relaunched."
} catch {}
if ($mnResult.EdncUpdated) {
Write-Host " eDNC : $currentEdnc -> $newNum" -ForegroundColor Green
$currentEdnc = $newNum
}
foreach ($err in $mnResult.Errors) { Write-Warning " $err" }
if ($mnResult.UdcUpdated) { Write-Host " UDC.exe relaunched." }
$needsMachineNumber = ($currentUdc -eq '9999' -or $currentEdnc -eq '9999')
} elseif ($newNum) {