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
|
local mac
|
||||||
mac=$(ip link show 2>/dev/null \
|
mac=$(ip link show 2>/dev/null \
|
||||||
| awk '/^[0-9]+: [^l][^o]/{iface=1} iface && /link\/ether/{print $2; iface=0; exit}')
|
| awk '/^[0-9]+: [^l][^o]/{iface=1} iface && /link\/ether/{print $2; iface=0; exit}')
|
||||||
# Remove colons via bash parameter substitution: ${var//pattern/replacement}.
|
# Strip any separator (colon/dot/dash) so the suffix is a bare hex string,
|
||||||
printf '%s' "${mac//:/}"
|
# 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
|
if $AF_MODE; then
|
||||||
|
|
@ -183,12 +185,17 @@ KEYMAPS=(
|
||||||
if $AF_MODE; then
|
if $AF_MODE; then
|
||||||
KERNEL=$(af_get '.kernel' 'linux')
|
KERNEL=$(af_get '.kernel' 'linux')
|
||||||
RAW_HOSTNAME=$(af_get '.hostname' '')
|
RAW_HOSTNAME=$(af_get '.hostname' '')
|
||||||
# Append MAC suffix to make the hostname unique across machines when the same
|
# Always append the machine's MAC (no separators) to the base name so every
|
||||||
# answerfile is deployed to a fleet (lab rollout, reinstall, etc.).
|
# node provisioned from the same answerfile gets a unique hostname, e.g.
|
||||||
if [[ -n "$RAW_HOSTNAME" ]]; then
|
# "arch-aabbccddeeff". Falls back to "arch" when the answerfile omits a name.
|
||||||
HOSTNAME="${RAW_HOSTNAME}-$(get_mac_suffix)"
|
# 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
|
else
|
||||||
HOSTNAME="arch"
|
HOSTNAME="$BASE_HOSTNAME"
|
||||||
fi
|
fi
|
||||||
USERNAME=$(af_get '.username' '')
|
USERNAME=$(af_get '.username' '')
|
||||||
ENCRYPT_DISK=$(af_bool '.encrypt')
|
ENCRYPT_DISK=$(af_bool '.encrypt')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue