diff --git a/Plugin/unraid/pages/setup.php b/Plugin/unraid/pages/setup.php index c8846f4..317be2d 100644 --- a/Plugin/unraid/pages/setup.php +++ b/Plugin/unraid/pages/setup.php @@ -38,6 +38,38 @@ // master.conf pull (for partner servers) lives in the checklist, not here. $detectedHostname = vv_get_hostname(); + +// ── Identity already on disk? ──────────────────────────────────────────────────────────────── +// A partner that has been sent the owner's master.conf already knows everything this step asks +// for: the conf names the primary, and it names this machine in one of the HOSTn slots. Asking +// for it again invites a typo in the one field the form itself warns is case-sensitive, and the +// answer is sitting in a file two lines away. +// +// Only a *populated* conf counts. The installer seeds master.conf from the template, where every +// HOSTn is empty — that is a fresh node with no identity, not a detected one. +// +// Matching is exact and case-insensitive, never a prefix: two hosts called Tower and Tower2 must +// not resolve to each other, and there is no ambiguity to tolerate when the value was written by +// the very host it names. +$vvDetected = ['slot' => '', 'primary' => '', 'role' => '']; +$vvMasterRaw = vv_read_conf_raw('master.conf'); +if ($vvMasterRaw !== '' && $detectedHostname !== '') { + preg_match_all('/^\s*(HOST\d+)\s*=\s*"([^"]*)"/m', $vvMasterRaw, $vvHm, PREG_SET_ORDER); + $vvSlots = []; + foreach ($vvHm as $m) { + $val = trim($m[2]); + if ($val !== '') $vvSlots[strtolower($m[1])] = $val; + } + foreach ($vvSlots as $slot => $name) { + if (strcasecmp($name, $detectedHostname) === 0) { + $vvDetected['slot'] = $slot; + $vvDetected['role'] = ($slot === 'host1') ? 'primary' : 'partner'; + break; + } + } + // The primary is whatever HOST1 says, and it is only useful to a host that is not HOST1. + if ($vvDetected['role'] === 'partner') $vvDetected['primary'] = $vvSlots['host1'] ?? ''; +} ?>