diff --git a/playbook/preinstall/preinstall.json b/playbook/preinstall/preinstall.json index 60e08da..0e62096 100644 --- a/playbook/preinstall/preinstall.json +++ b/playbook/preinstall/preinstall.json @@ -138,7 +138,7 @@ "Name": "UDC", "Installer": "UDC_Setup.exe", "Type": "EXE", - "InstallArgs": "\"West Jefferson\" 9999", + "InstallArgs": "WestJefferson -9999", "KillAfterDetection": true, "DetectionMethod": "Registry", "DetectionPath": "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\UDC", diff --git a/playbook/shopfloor-setup/Shopfloor/00-PreInstall-MachineApps.ps1 b/playbook/shopfloor-setup/Shopfloor/00-PreInstall-MachineApps.ps1 index 04a737f..0536019 100644 --- a/playbook/shopfloor-setup/Shopfloor/00-PreInstall-MachineApps.ps1 +++ b/playbook/shopfloor-setup/Shopfloor/00-PreInstall-MachineApps.ps1 @@ -122,18 +122,21 @@ if (-not $config.Applications) { Write-PreInstallLog "Staged installer dir: $installerDir" Write-PreInstallLog "Found $($config.Applications.Count) app entries in preinstall.json" -# --- Site-name override: replace "West Jefferson" in InstallArgs if site-config says otherwise --- +# --- Site-name override: replace 'WestJefferson' (compact, no space) in +# InstallArgs if site-config says otherwise. UDC_Setup.exe expects the +# compact site name as positional arg 1; the spaced variant is used in +# other places (eDNC SITESELECTED MSI property) but not here. $siteConfig = Get-SiteConfig -if ($siteConfig -and $siteConfig.siteName -and $siteConfig.siteName -ne 'West Jefferson') { - Write-PreInstallLog "Site config loaded - siteName: $($siteConfig.siteName)" +if ($siteConfig -and $siteConfig.siteNameCompact -and $siteConfig.siteNameCompact -ne 'WestJefferson') { + Write-PreInstallLog "Site config loaded - siteNameCompact: $($siteConfig.siteNameCompact)" foreach ($app in $config.Applications) { - if ($app.InstallArgs -and $app.InstallArgs -match 'West Jefferson') { - $app.InstallArgs = $app.InstallArgs -replace 'West Jefferson', $siteConfig.siteName + if ($app.InstallArgs -and $app.InstallArgs -match 'WestJefferson') { + $app.InstallArgs = $app.InstallArgs -replace 'WestJefferson', $siteConfig.siteNameCompact Write-PreInstallLog " Overrode site name in $($app.Name) args: $($app.InstallArgs)" } } } else { - Write-PreInstallLog "No site-config override for siteName (using defaults in preinstall.json)" + Write-PreInstallLog "No site-config override for siteNameCompact (using defaults in preinstall.json)" } # --- Machine-number override: replace "9999" in UDC InstallArgs if tech entered a number --- @@ -310,9 +313,36 @@ foreach ($app in $config.Applications) { Write-PreInstallLog " Detection passed at $elapsed s - killing installer to advance (KillAfterDetection)" try { $proc.Kill(); $proc.WaitForExit(5000) | Out-Null } catch { } - # UDC's installer auto-launches UDC.exe in silent mode. Kill that too - # so it can't write the placeholder MachineNumber to udc_settings.json. + # UDC's installer auto-launches UDC.exe silently; it's UDC.exe + # (not UDC_Setup) that actually writes udc_settings.json from + # the CLI args. Killing it immediately after the detection + # marker appears loses the MachineNumber write. Wait (up to + # 15s) for settings.json to reflect the target number, then + # kill. Works uniformly for tech-typed numbers and the 9999 + # placeholder - whichever was passed as arg 2 is what we + # expect to see persist. if ($app.Name -eq "UDC") { + $udcJson = 'C:\ProgramData\UDC\udc_settings.json' + $targetNum = $null + if ($app.InstallArgs -match '-(\d+)\s*$') { $targetNum = $matches[1] } + $waitSec = 0 + while ($waitSec -lt 15) { + if (Test-Path $udcJson) { + try { + $mn = (Get-Content $udcJson -Raw -ErrorAction Stop | + ConvertFrom-Json).GeneralSettings.MachineNumber + if ($mn -and $mn -eq $targetNum) { + Write-PreInstallLog " UDC persisted MachineNumber=$mn after $waitSec s" + break + } + } catch { } + } + Start-Sleep -Seconds 1 + $waitSec++ + } + if ($waitSec -ge 15) { + Write-PreInstallLog " UDC did not persist MachineNumber within 15 s - killing anyway" "WARN" + } Get-Process UDC -ErrorAction SilentlyContinue | ForEach-Object { try { $_.Kill(); $_.WaitForExit(2000) | Out-Null } catch { } } diff --git a/playbook/shopfloor-setup/Shopfloor/lib/Update-MachineNumber.ps1 b/playbook/shopfloor-setup/Shopfloor/lib/Update-MachineNumber.ps1 index 403f003..6b707b2 100644 --- a/playbook/shopfloor-setup/Shopfloor/lib/Update-MachineNumber.ps1 +++ b/playbook/shopfloor-setup/Shopfloor/lib/Update-MachineNumber.ps1 @@ -129,7 +129,10 @@ function Update-MachineNumber { # --- Relaunch UDC with new args --- if ((Test-Path $script:UdcExePath) -and $out.UdcUpdated) { try { - Start-Process -FilePath $script:UdcExePath -ArgumentList @('-site', "`"$Site`"", '-machine', $NewNumber) + # UDC.exe arg signature: positional compact-site (no space), then + # dash-prefixed machine number. Example: UDC.exe WestJefferson -7605 + $siteCompact = ($Site -replace '\s+','') + Start-Process -FilePath $script:UdcExePath -ArgumentList @($siteCompact, "-$NewNumber") } catch { $out.Errors += "UDC relaunch failed: $_" }