summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/slx-uuid
diff options
context:
space:
mode:
authorJonathan Bauer2018-11-12 12:17:19 +0100
committerJonathan Bauer2018-11-12 17:30:33 +0100
commitcd1b40ba72c2165b799e8adce871d0b8be76aec6 (patch)
treecdd4b7688bbf28c5c7606ecde134d4361debd3b7 /builder/modules.d/slx-uuid
parentin bridge mode, do not copy the physical interface configuration (diff)
downloadsystemd-init-cd1b40ba72c2165b799e8adce871d0b8be76aec6.tar.gz
systemd-init-cd1b40ba72c2165b799e8adce871d0b8be76aec6.tar.xz
systemd-init-cd1b40ba72c2165b799e8adce871d0b8be76aec6.zip
[slx-uuid] Detects and exposes system UUID
for various openslx-related scripts
Diffstat (limited to 'builder/modules.d/slx-uuid')
-rw-r--r--builder/modules.d/slx-uuid/bad-uuid-defaults.conf8
-rwxr-xr-xbuilder/modules.d/slx-uuid/module-setup.sh20
-rw-r--r--builder/modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh6
-rw-r--r--builder/modules.d/slx-uuid/scripts/get-system-uuid.sh58
4 files changed, 92 insertions, 0 deletions
diff --git a/builder/modules.d/slx-uuid/bad-uuid-defaults.conf b/builder/modules.d/slx-uuid/bad-uuid-defaults.conf
new file mode 100644
index 00000000..aaf59a7d
--- /dev/null
+++ b/builder/modules.d/slx-uuid/bad-uuid-defaults.conf
@@ -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/builder/modules.d/slx-uuid/module-setup.sh b/builder/modules.d/slx-uuid/module-setup.sh
new file mode 100755
index 00000000..875c9f77
--- /dev/null
+++ b/builder/modules.d/slx-uuid/module-setup.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+check() {
+ # Tell dracut that this module should only be included if it is required
+ # explicitly.
+ if ! hash dmidecode; then
+ echo "dmidecode is missing from this system, please install it."
+ return 1
+ fi
+ return 255
+}
+depends() {
+ echo dnbd3-rootfs
+}
+install() {
+ mkdir -p "$initdir/etc/bad-uuid.d"
+ inst_simple "$moddir/bad-uuid-defaults.conf" "/etc/bad-uuid.d/bad-uuid-defaults.conf"
+ inst_multiple dmidecode head
+ inst_hook pre-mount 05 "$moddir/scripts/get-system-uuid.sh"
+ inst_hook pre-pivot 10 "$moddir/scripts/copy-system-uuid-to-newroot.sh"
+}
diff --git a/builder/modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh b/builder/modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh
new file mode 100644
index 00000000..d73b0d94
--- /dev/null
+++ b/builder/modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+if [ -s "/run/system-uuid" ]; then
+ cp "/run/system-uuid" "$NEWROOT/run/system-uuid"
+fi
+true
diff --git a/builder/modules.d/slx-uuid/scripts/get-system-uuid.sh b/builder/modules.d/slx-uuid/scripts/get-system-uuid.sh
new file mode 100644
index 00000000..2b55e73d
--- /dev/null
+++ b/builder/modules.d/slx-uuid/scripts/get-system-uuid.sh
@@ -0,0 +1,58 @@
+#!/usr/bin/env bash
+#
+# Slighty changed version of:
+# http://git.openslx.org/openslx-ng/mltk.git/plain/core/modules/system-uuid/data/bin/get-uuid
+
+. /lib/dracut-lib.sh
+
+get_system_uuid() {
+ if [ -e /run/openslx/pxe-network.conf ]; then
+ . /run/openslx/pxe-network.conf
+ fi
+
+ if [ -z "$SLX_PXE_MAC" ]; then
+ eval $(grep -Eo BOOTIF=\\S+ /proc/cmdline)
+ if [ "${#BOOTIF}" -ne "20" ]; then
+ warn "Getting MAC from /proc/cmdline failed, using 'ip a'..."
+ BOOTIF=01-$(ip a | grep -A 1 ": ${SLX_BRIDGE:-br0}" | grep -o 'ether ..:..:..:..:..:..' | cut -d' ' -f2 | sed s/:/-/g)
+ fi
+ if [ "${#BOOTIF}" -ne "20" ]; then
+ warn "Getting MAC from 'ip a' failed, using a default value..."
+ BOOTIF="99-88-77-66-55-44-33"
+ fi
+ else
+ BOOTIF="01-$(tr ':' '-' <<< $SLX_PXE_MAC)"
+ fi
+
+ 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"
+ else
+ # Got UUID, check blacklist
+ local DIR="/etc/bad-uuid.d"
+ local TMPLIST=$(mktemp)
+ local 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
+ warn "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"
+}
+
+get_system_uuid