summaryrefslogtreecommitdiffstats
path: root/modules.d/slx-uuid
diff options
context:
space:
mode:
authorJonathan Bauer2020-05-13 11:04:02 +0200
committerJonathan Bauer2020-05-13 11:04:02 +0200
commit1130873aa55c9b0a7e5af48edc44bd6c6fd1f888 (patch)
tree0fcfa186cd631d8d36611b3d4bc509fd38841d51 /modules.d/slx-uuid
parentMerge branch 'centos8' into downloader (diff)
downloadsystemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.tar.gz
systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.tar.xz
systemd-init-1130873aa55c9b0a7e5af48edc44bd6c6fd1f888.zip
restructure repo
* remove packager * move everything from builder/* back to root
Diffstat (limited to 'modules.d/slx-uuid')
-rw-r--r--modules.d/slx-uuid/bad-uuid-defaults.conf8
-rwxr-xr-xmodules.d/slx-uuid/module-setup.sh20
-rw-r--r--modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh6
-rw-r--r--modules.d/slx-uuid/scripts/get-system-uuid.sh69
4 files changed, 103 insertions, 0 deletions
diff --git a/modules.d/slx-uuid/bad-uuid-defaults.conf b/modules.d/slx-uuid/bad-uuid-defaults.conf
new file mode 100644
index 00000000..aaf59a7d
--- /dev/null
+++ b/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/modules.d/slx-uuid/module-setup.sh b/modules.d/slx-uuid/module-setup.sh
new file mode 100755
index 00000000..569b5155
--- /dev/null
+++ b/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 busybox
+}
+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
+ inst_hook pre-udev 05 "$moddir/scripts/get-system-uuid.sh"
+ inst_hook pre-pivot 10 "$moddir/scripts/copy-system-uuid-to-newroot.sh"
+}
diff --git a/modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh b/modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh
new file mode 100644
index 00000000..553109fb
--- /dev/null
+++ b/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/etc/system-uuid"
+fi
+true
diff --git a/modules.d/slx-uuid/scripts/get-system-uuid.sh b/modules.d/slx-uuid/scripts/get-system-uuid.sh
new file mode 100644
index 00000000..fd6bb125
--- /dev/null
+++ b/modules.d/slx-uuid/scripts/get-system-uuid.sh
@@ -0,0 +1,69 @@
+#!/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/network.conf ]; then
+ . /run/openslx/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=
+ 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=
+ 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"
+}
+
+get_system_uuid