From c70af5479c890b109ffa12617def457e49f7baf1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 12 Jul 2017 14:12:48 +0200 Subject: [init, etc] Pass system-uuid when fetching config & config.tgz Also save the system-uuid for later use in stage32+, which changed locations from /run to /etc - modules got updated accordingly --- core/modules/system-uuid/data/bin/get-uuid | 40 ++++++++++++++++++++++ .../data/opt/openslx/bad-uuid.d/00-default | 8 +++++ core/modules/system-uuid/module.build | 13 +++++++ core/modules/system-uuid/module.conf | 4 +++ 4 files changed, 65 insertions(+) create mode 100755 core/modules/system-uuid/data/bin/get-uuid create mode 100644 core/modules/system-uuid/data/opt/openslx/bad-uuid.d/00-default create mode 100644 core/modules/system-uuid/module.build create mode 100644 core/modules/system-uuid/module.conf (limited to 'core/modules/system-uuid') diff --git a/core/modules/system-uuid/data/bin/get-uuid b/core/modules/system-uuid/data/bin/get-uuid new file mode 100755 index 00000000..30ef3cf9 --- /dev/null +++ b/core/modules/system-uuid/data/bin/get-uuid @@ -0,0 +1,40 @@ +#!/bin/ash + +eval $(grep -Eo BOOTIF=\\S+ /proc/cmdline) +if [ "${#BOOTIF}" -ne "20" ]; then + echo "Getting MAC from /proc/cmdline failed, using 'ip a'..." + BOOTIF=01-$(ip a | grep -A 1 ': br0' | grep -o 'ether ..:..:..:..:..:..' | cut -d' ' -f2 | sed s/:/-/g) + if [ "${#BOOTIF}" -ne "20" ]; then + echo "FAIL FAIL FAIL" + BOOTIF="99-88-77-66-55-44-33" + fi +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..." + UUID="000000000000000-$BOOTIF" +else + # Got UUID, check blacklist + DIR="/opt/openslx/bad-uuid.d" + TMPLIST=$(mktemp) + BADLIST=$(mktemp) + 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}' + 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 + # the remaining two, but some tools seem to ignore that fact. + < "$BADLIST" sed -r 's/^(..)(..)(..)(..)\-(..)(..)\-(..)(..)\-([0-9A-F]{4}\-[0-9A-F]{12})$/\4\3\2\1-\6\5-\8\7-\9/' >> "$TMPLIST" + # 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" + UUID="000000000000000-$BOOTIF" + fi + rm -f -- "$TMPLIST" "$BADLIST" +fi + +echo "$UUID" > "/run/system-uuid" diff --git a/core/modules/system-uuid/data/opt/openslx/bad-uuid.d/00-default b/core/modules/system-uuid/data/opt/openslx/bad-uuid.d/00-default new file mode 100644 index 00000000..aaf59a7d --- /dev/null +++ b/core/modules/system-uuid/data/opt/openslx/bad-uuid.d/00-default @@ -0,0 +1,8 @@ +00000000-0000-0000-0000-000000000000 +03000200-0400-0500-0006-000700080009 +11111111-2222-3333-4444-555555555555 +44454C4C-2000-1020-8020-A0C04F202020 +4C4C4544-0000-2010-8020-80C04F202020 +4C4C4544-0046-3310-805A-B6C04F4B4D31 +A023157C-F692-11DE-977C-7F0F26276F33 +FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF diff --git a/core/modules/system-uuid/module.build b/core/modules/system-uuid/module.build new file mode 100644 index 00000000..3c6eb632 --- /dev/null +++ b/core/modules/system-uuid/module.build @@ -0,0 +1,13 @@ +#!/bin/bash +fetch_source() { + : +} + +build() { + : +} + +post_copy() { + : +} + diff --git a/core/modules/system-uuid/module.conf b/core/modules/system-uuid/module.conf new file mode 100644 index 00000000..805ff2c4 --- /dev/null +++ b/core/modules/system-uuid/module.conf @@ -0,0 +1,4 @@ +#!/bin/bash +REQUIRED_MODULES=" + dmidecode +" -- cgit v1.2.3-55-g7522