summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2024-02-01 10:16:57 +0100
committerSimon Rettberg2024-02-01 10:16:57 +0100
commitbae8a20575d1d240b06a38bf0852d4ca747b9e2c (patch)
tree643014e3f178925c541f09626a9ab82bdb9365a9
parent[slx-clock] Order ntp sync after fetch config (diff)
downloadsystemd-init-bae8a20575d1d240b06a38bf0852d4ca747b9e2c.tar.gz
systemd-init-bae8a20575d1d240b06a38bf0852d4ca747b9e2c.tar.xz
systemd-init-bae8a20575d1d240b06a38bf0852d4ca747b9e2c.zip
[slx-uuid] Move network stuff down to fallback path, more output
-rwxr-xr-xmodules.d/slx-uuid/hooks/s3-get-system-uuid.sh51
1 files changed, 24 insertions, 27 deletions
diff --git a/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh b/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh
index e97a0e18..3669ff4e 100755
--- a/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh
+++ b/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh
@@ -3,30 +3,9 @@
# Slighty changed version of:
# http://git.openslx.org/openslx-ng/mltk.git/plain/core/modules/system-uuid/data/bin/get-uuid
-if [ -e /run/openslx/network.conf ]; then
- . /run/openslx/network.conf
-else
- echo "Don't have /run/openslx/network.conf"
-fi
-
-if [ -z "$SLX_PXE_MAC" ]; then
- echo "Getting MAC from /run/openslx/network.conf failed, using 'ip a'..."
- for iface in "${SLX_BRIDGE:-br0}" boot0 eth0; do
- BOOTIF=01-$(ip a | grep -A 1 ": ${iface}" | grep -o 'ether ..:..:..:..:..:..' | cut -d' ' -f2 | sed s/:/-/g)
- [ "${#BOOTIF}" -eq "20" ] && break
- done
- if [ "${#BOOTIF}" -ne "20" ]; then
- echo "Getting MAC from 'ip a' failed, using bogus value..."
- BOOTIF="99-88-77-66-55-44-33"
- fi
-else
- BOOTIF="01-$( echo "$SLX_PXE_MAC" | tr ':' '-' )"
-fi
-
UUID=$(dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr 'a-z' 'A-Z')
if [ "${#UUID}" -ne "36" ]; then
- echo "Determined UUID (${UUID}) has not expected length of 36, falling back to MAC..."
- # Maybe use /proc/sys/kernel/random/uuid ?
+ echo "Determined UUID ${UUID} has not expected length of 36, falling back to MAC..."
UUID=
else
# Got UUID, check blacklist
@@ -45,21 +24,39 @@ else
# Finally make unique
sort -u "$TMPLIST" > "$BADLIST"
if grep -Fxq "$UUID" "$BADLIST"; then
- echo "WARNING: UUID is blacklisted as potentially not being unique, using MAC fallback"
+ echo "WARNING: UUID $UUID is blacklisted as potentially not being unique, using MAC fallback"
UUID=
fi
rm -f -- "$TMPLIST" "$BADLIST"
fi
if [ -z "$UUID" ]; then
- UUID=$( echo "$BOOTIF" | sed -r 's/[^0-9A-Fa-f]//g' )
- [ "${#UUID}" -eq 14 ] && UUID="${UUID:2}"
- if [ "${#UUID}" -eq 12 ]; then
+ # No UUID, or was bogus - derive from bootif MAC address
+ if [ -e /run/openslx/network.conf ]; then
+ . /run/openslx/network.conf
+ else
+ echo "Don't have /run/openslx/network.conf"
+ fi
+
+ if [ "${#SLX_PXE_MAC}" != 17 ]; then
+ echo "Getting MAC from /run/openslx/network.conf failed, looking up in sysfs"
+ for iface in "${SLX_BRIDGE:-br0}" "${SLX_PXE_NETIF:-boot0}" eth0; do
+ SLX_PXE_MAC=$( cat "/sys/class/net/$iface/address" )
+ [ "${#SLX_PXE_MAC}" = "17" ] && break
+ done
+ if [ "${#SLX_PXE_MAC}" != "17" ]; then
+ echo "Getting MAC from sysfs failed, using bogus value..."
+ SLX_PXE_MAC="88:77:66:55:44:33"
+ fi
+ fi
+ UUID="$( echo "$SLX_PXE_MAC" | sed -r 's/[^0-9A-Fa-f]//g' )"
+ if [ "${#UUID}" = 12 ]; then
UUID="baad1d00-9491-4716-b98b-$UUID"
else
+ echo "Could not derive UUID from MAC (got '$UUID'), using bogus fallback"
UUID="baad1d00-9491-4716-b98b-000000000000"
fi
fi
UUID=$( echo "$UUID" | tr 'a-z' 'A-Z' )
-readonly UUID
+echo "Final UUID is $UUID"
echo "$UUID" > "/run/system-uuid"