From 1665374a3aa9c44632e831535cb04007240bf79b Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 20 Feb 2019 15:50:16 +0100 Subject: [slx-uuid] new uuid fallback scheme --- .../modules.d/slx-uuid/scripts/get-system-uuid.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/builder/modules.d/slx-uuid/scripts/get-system-uuid.sh b/builder/modules.d/slx-uuid/scripts/get-system-uuid.sh index 2b55e73d..4f170e23 100644 --- a/builder/modules.d/slx-uuid/scripts/get-system-uuid.sh +++ b/builder/modules.d/slx-uuid/scripts/get-system-uuid.sh @@ -24,11 +24,11 @@ get_system_uuid() { BOOTIF="01-$(tr ':' '-' <<< $SLX_PXE_MAC)" fi - local UUID=$(dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr '[a-z]' '[A-Z]') + local UUID=$(dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr 'a-z' 'A-Z') if [ "${#UUID}" -ne "36" ]; then warn "Determined UUID (${UUID}) has not expected length of 36, falling back to MAC..." # Maybe use /proc/sys/kernel/random/uuid ? - UUID="000000000000001-$BOOTIF" + UUID= else # Got UUID, check blacklist local DIR="/etc/bad-uuid.d" @@ -37,7 +37,7 @@ get_system_uuid() { for file in "$DIR"/*; do [ -f "$file" ] || continue # 11111111-2222-3333-4444-555555555555 - < "$file" tr '[a-z]' '[A-Z]' | grep -Eo '[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}' + < "$file" tr 'a-z' 'A-Z' | grep -Eo '[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}' done | tee "$TMPLIST" > "$BADLIST" # Also add flipped version of bad uuids. Found some of them through googling and discovered that sometimes # users report them in a different order. UUIDs use different endianness for the first three blocks than @@ -47,11 +47,22 @@ get_system_uuid() { sort -u "$TMPLIST" > "$BADLIST" if grep -Fxq "$UUID" "$BADLIST"; then warn "WARNING: UUID is blacklisted as potentially not being unique, using MAC fallback" - UUID="000000000000000-$BOOTIF" + 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 + UUID="baad1d00-9491-4716-b98b-$UUID" + else + UUID="baad1d00-9491-4716-b98b-000000000000" + fi + fi + UUID=$( echo "$UUID" | tr 'a-z' 'A-Z' ) + readonly UUID echo "$UUID" > "/run/system-uuid" } -- cgit v1.2.3-55-g7522