summaryrefslogtreecommitdiffstats
path: root/core/modules/system-uuid
diff options
context:
space:
mode:
authorSimon Rettberg2017-07-12 14:12:48 +0200
committerSimon Rettberg2017-07-12 14:12:48 +0200
commitc70af5479c890b109ffa12617def457e49f7baf1 (patch)
treee655d3fc498646a674dd437768ec074aab8d0746 /core/modules/system-uuid
parent[rfs-stage31] init: Create /tmp early, unmount before switchroot (diff)
downloadmltk-c70af5479c890b109ffa12617def457e49f7baf1.tar.gz
mltk-c70af5479c890b109ffa12617def457e49f7baf1.tar.xz
mltk-c70af5479c890b109ffa12617def457e49f7baf1.zip
[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
Diffstat (limited to 'core/modules/system-uuid')
-rwxr-xr-xcore/modules/system-uuid/data/bin/get-uuid40
-rw-r--r--core/modules/system-uuid/data/opt/openslx/bad-uuid.d/00-default8
-rw-r--r--core/modules/system-uuid/module.build13
-rw-r--r--core/modules/system-uuid/module.conf4
4 files changed, 65 insertions, 0 deletions
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
+"