fix(installer): always append separator-free MAC to answerfile hostname
In answerfile mode the hostname now always gets the machine's MAC appended as "<name>-<mac>" with the MAC stripped of all separators (colons/dots/dashes), so fleet deployments from one answerfile stay unique. The default "arch" name now also receives the suffix, and the dash is only added when a MAC is actually found (no trailing "-" on NIC-less machines). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>main
parent
bc13de7508
commit
db4079d543
|
|
@ -127,8 +127,10 @@ get_mac_suffix() {
|
|||
local mac
|
||||
mac=$(ip link show 2>/dev/null \
|
||||
| awk '/^[0-9]+: [^l][^o]/{iface=1} iface && /link\/ether/{print $2; iface=0; exit}')
|
||||
# Remove colons via bash parameter substitution: ${var//pattern/replacement}.
|
||||
printf '%s' "${mac//:/}"
|
||||
# Strip any separator (colon/dot/dash) so the suffix is a bare hex string,
|
||||
# e.g. "aa:bb:cc:dd:ee:ff" -> "aabbccddeeff". The character class [:.-] matches
|
||||
# all three common MAC delimiters regardless of how the kernel formats them.
|
||||
printf '%s' "${mac//[:.-]/}"
|
||||
}
|
||||
|
||||
if $AF_MODE; then
|
||||
|
|
@ -183,12 +185,17 @@ KEYMAPS=(
|
|||
if $AF_MODE; then
|
||||
KERNEL=$(af_get '.kernel' 'linux')
|
||||
RAW_HOSTNAME=$(af_get '.hostname' '')
|
||||
# Append MAC suffix to make the hostname unique across machines when the same
|
||||
# answerfile is deployed to a fleet (lab rollout, reinstall, etc.).
|
||||
if [[ -n "$RAW_HOSTNAME" ]]; then
|
||||
HOSTNAME="${RAW_HOSTNAME}-$(get_mac_suffix)"
|
||||
# Always append the machine's MAC (no separators) to the base name so every
|
||||
# node provisioned from the same answerfile gets a unique hostname, e.g.
|
||||
# "arch-aabbccddeeff". Falls back to "arch" when the answerfile omits a name.
|
||||
# The dash is only added when a MAC was actually found, so a NIC-less machine
|
||||
# never ends up with a trailing "-".
|
||||
BASE_HOSTNAME="${RAW_HOSTNAME:-arch}"
|
||||
MAC_SUFFIX=$(get_mac_suffix)
|
||||
if [[ -n "$MAC_SUFFIX" ]]; then
|
||||
HOSTNAME="${BASE_HOSTNAME}-${MAC_SUFFIX}"
|
||||
else
|
||||
HOSTNAME="arch"
|
||||
HOSTNAME="$BASE_HOSTNAME"
|
||||
fi
|
||||
USERNAME=$(af_get '.username' '')
|
||||
ENCRYPT_DISK=$(af_bool '.encrypt')
|
||||
|
|
|
|||
Loading…
Reference in New Issue