diff options
author | Simon Rettberg | 2024-01-25 15:47:09 +0100 |
---|---|---|
committer | Simon Rettberg | 2024-01-29 09:53:08 +0100 |
commit | abb148916593de63554ef58c53cb1dd8fbbb0ab1 (patch) | |
tree | d8c640c33f699f3abc567d9bbf111190c779b7d2 /modules.d/slx-uuid | |
parent | [dnbd3-rootfs] Try optimized ext4 mount options if none are given (diff) | |
download | systemd-init-abb148916593de63554ef58c53cb1dd8fbbb0ab1.tar.gz systemd-init-abb148916593de63554ef58c53cb1dd8fbbb0ab1.tar.xz systemd-init-abb148916593de63554ef58c53cb1dd8fbbb0ab1.zip |
Try to use more systemd services
Diffstat (limited to 'modules.d/slx-uuid')
-rwxr-xr-x[-rw-r--r--] | modules.d/slx-uuid/hooks/copy-system-uuid-to-newroot.sh (renamed from modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh) | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | modules.d/slx-uuid/hooks/s3-get-system-uuid.sh (renamed from modules.d/slx-uuid/scripts/get-system-uuid.sh) | 18 | ||||
-rwxr-xr-x | modules.d/slx-uuid/module-setup.sh | 29 | ||||
-rw-r--r-- | modules.d/slx-uuid/services/s3-get-system-uuid.service | 13 |
4 files changed, 42 insertions, 20 deletions
diff --git a/modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh b/modules.d/slx-uuid/hooks/copy-system-uuid-to-newroot.sh index 553109fb..e451ce26 100644..100755 --- a/modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh +++ b/modules.d/slx-uuid/hooks/copy-system-uuid-to-newroot.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/ash if [ -s "/run/system-uuid" ]; then cp "/run/system-uuid" "$NEWROOT/etc/system-uuid" diff --git a/modules.d/slx-uuid/scripts/get-system-uuid.sh b/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh index fd6bb125..e65a3394 100644..100755 --- a/modules.d/slx-uuid/scripts/get-system-uuid.sh +++ b/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh @@ -8,22 +8,24 @@ get_system_uuid() { if [ -e /run/openslx/network.conf ]; then . /run/openslx/network.conf + else + echo "Don't have /run/openslx/network.conf" fi - + if [ -z "$SLX_PXE_MAC" ]; then - eval $(grep -Eo BOOTIF=\\S+ /proc/cmdline) + warn "Getting MAC from /run/openslx/network.conf failed, using 'ip a'..." + for iface in "${SLX_BRIDGE:-br0}" boot0 eth0; do + BOOTIF=01-$(ip a | grep -A 1 ": ${iface}" | grep -o 'ether ..:..:..:..:..:..' | cut -d' ' -f2 | sed s/:/-/g) + [ "${#BOOTIF}" -eq "20" ] && break + done 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..." + warn "Getting MAC from 'ip a' failed, using bogus 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..." diff --git a/modules.d/slx-uuid/module-setup.sh b/modules.d/slx-uuid/module-setup.sh index 1e550136..1cac712d 100755 --- a/modules.d/slx-uuid/module-setup.sh +++ b/modules.d/slx-uuid/module-setup.sh @@ -13,17 +13,24 @@ depends() { } install() { mkdir -p "$initdir/etc/bad-uuid.d" - # check if we have an uuid blacklists installed by openslx/mltk on this system - if [ "$(ls -A /opt/openslx/bad-uuid.d)" ]; then - for blacklist in "/opt/openslx/bad-uuid.d"/* ]; do - inst_simple "$blacklist" "/etc/bad-uuid.d/${blacklist##*/}" - done - else - # use this module's default blacklist - inst_simple "$moddir/bad-uuid-defaults.conf" "/etc/bad-uuid.d/bad-uuid-defaults.conf" - fi + # check if we have any uuid blacklists installed by openslx/mltk on this system + for blacklist in /opt/openslx/bad-uuid.d/*; do + [ -s "$blacklist" ] || continue + inst_simple "$blacklist" "/etc/bad-uuid.d/${blacklist##*/}" + done + # add this module's default blacklist + 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" + inst_hook pre-pivot 10 "$moddir/hooks/copy-system-uuid-to-newroot.sh" + + _name="s3-get-system-uuid" + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-pre-udev.service.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-pre-udev.service.requires/${_name}.service" } diff --git a/modules.d/slx-uuid/services/s3-get-system-uuid.service b/modules.d/slx-uuid/services/s3-get-system-uuid.service new file mode 100644 index 00000000..b726cd2b --- /dev/null +++ b/modules.d/slx-uuid/services/s3-get-system-uuid.service @@ -0,0 +1,13 @@ +[Unit] +Description=Get system UUID +Requires=dracut-cmdline.service +After=dracut-cmdline.service +Wants=s3-parse-network-kcl.service +After=s3-parse-network-kcl.service +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-get-system-uuid.sh |