From 501cdbda03871c619019980d1347b72743212de7 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 31 Jan 2024 17:07:10 +0100 Subject: [busybox] Split into services --- .../busybox/hooks/s3-install-busybox-stage4.sh | 35 ++++++++++++++++++++++ modules.d/busybox/hooks/s3-install-busybox.sh | 9 ++++++ modules.d/busybox/install-busybox-stage4.sh | 26 ---------------- modules.d/busybox/install-busybox.sh | 9 ------ modules.d/busybox/module-setup.sh | 12 ++++++-- .../services/s3-install-busybox-stage4.service | 11 +++++++ .../busybox/services/s3-install-busybox.service | 11 +++++++ 7 files changed, 76 insertions(+), 37 deletions(-) create mode 100755 modules.d/busybox/hooks/s3-install-busybox-stage4.sh create mode 100755 modules.d/busybox/hooks/s3-install-busybox.sh delete mode 100755 modules.d/busybox/install-busybox-stage4.sh delete mode 100755 modules.d/busybox/install-busybox.sh create mode 100644 modules.d/busybox/services/s3-install-busybox-stage4.service create mode 100644 modules.d/busybox/services/s3-install-busybox.service diff --git a/modules.d/busybox/hooks/s3-install-busybox-stage4.sh b/modules.d/busybox/hooks/s3-install-busybox-stage4.sh new file mode 100755 index 00000000..f5c0aae9 --- /dev/null +++ b/modules.d/busybox/hooks/s3-install-busybox-stage4.sh @@ -0,0 +1,35 @@ +#!/bin/ash + +# copy busybox to NEWROOT unless one exists at the expected path. +bb_target_path="/opt/openslx/bin/busybox" +bb_source_path="$( type -p busybox )" +[ -x "$bb_source_path" ] || bb_source_path="$( command -v busybox )" + +if ! [ -x "$bb_source_path" ]; then + echo "Busybox binary not found in initrd!?" + exit 1 +fi + +if [ -x "${NEWROOT}${bb_target_path}" ]; then + echo "Not installing busybox in stage 4 - already exists" + exit 1 +fi + +mkdir -p -- "${NEWROOT}/opt/openslx/bin" "${NEWROOT}/opt/openslx/sbin" +cp -f -- "$bb_source_path" "${NEWROOT}${bb_target_path}" +# --list-full gives {s,}bin prefixes +for app in $( busybox --list-full ); do + # No -f, so we skip any tools that might already exist + ln -ns -- "$bb_target_path" "${NEWROOT}/opt/openslx/$app" +done +# compat: /bin/ash if not exists +# also accept dead symlinks as it might be relative and just look dead +# to us from outside NEWROOT +if ! [ -e "${NEWROOT}/bin/ash" ] && ! [ -L "${NEWROOT}/bin/ash" ]; then + ln -nsf -- "$bb_target_path" "${NEWROOT}/bin/ash" +else + # either valid symlink or binary, log it and ignore. + echo "'/bin/ash' is a symlink or binary, leaving it alone." +fi + +exit 0 diff --git a/modules.d/busybox/hooks/s3-install-busybox.sh b/modules.d/busybox/hooks/s3-install-busybox.sh new file mode 100755 index 00000000..3e42153b --- /dev/null +++ b/modules.d/busybox/hooks/s3-install-busybox.sh @@ -0,0 +1,9 @@ +#!/bin/ash + +if busybox --install -s; then + echo "Busybox installed." + exit 0 +fi + +echo "Busybox install failed." +exit 1 diff --git a/modules.d/busybox/install-busybox-stage4.sh b/modules.d/busybox/install-busybox-stage4.sh deleted file mode 100755 index bcd1f94d..00000000 --- a/modules.d/busybox/install-busybox-stage4.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -if hash busybox; then - # copy busybox to NEWROOT unless one exists at the expected path. - bb_target_path="/opt/openslx/bin/busybox" - bb_source_path="$(type -p busybox)" - - if [ -n "$bb_source_path" ] && [ ! -x "${NEWROOT}${bb_target_path}" ]; then - mkdir -p "${NEWROOT}"/opt/openslx/{s,}bin - cp -f "$bb_source_path" "${NEWROOT}${bb_target_path}" - # --list-full gives {s,}bin prefixes - for app in $(busybox --list-full); do - ln -s "$bb_target_path" "${NEWROOT}/opt/openslx/$app" - done - fi - # compat: /bin/ash if not exists - if [ ! -e "${NEWROOT}/bin/ash" ]; then - # either dead symlink or nothing there. - ln -sf "$bb_target_path" "${NEWROOT}/bin/ash" - else - # either valid symlink or binary, log it and ignore. - type -p warn &>/dev/null || . /lib/dracut-lib.sh - warn "'/bin/ash' is a valid symlink or binary, ignoring." - fi -fi -true diff --git a/modules.d/busybox/install-busybox.sh b/modules.d/busybox/install-busybox.sh deleted file mode 100755 index d4606590..00000000 --- a/modules.d/busybox/install-busybox.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -if hash busybox && busybox --install -s; then - echo "Busybox installed" -else - . /lib/dracut-lib.sh - emergency_shell "Failed to initialize busybox, things will go wrong..." -fi -true diff --git a/modules.d/busybox/module-setup.sh b/modules.d/busybox/module-setup.sh index c2305e32..99e7574d 100755 --- a/modules.d/busybox/module-setup.sh +++ b/modules.d/busybox/module-setup.sh @@ -36,6 +36,14 @@ install() { return 1 fi inst "${moddir}/src/busybox" "/bin/busybox" - inst_hook cmdline 00 "${moddir}/install-busybox.sh" - inst_hook pre-pivot 50 "${moddir}/install-busybox-stage4.sh" + for _name in "s3-install-busybox" "s3-install-busybox-stage4"; do + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/initrd.target.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/initrd.target.requires/${_name}.service" + done } diff --git a/modules.d/busybox/services/s3-install-busybox-stage4.service b/modules.d/busybox/services/s3-install-busybox-stage4.service new file mode 100644 index 00000000..b9ed87f0 --- /dev/null +++ b/modules.d/busybox/services/s3-install-busybox-stage4.service @@ -0,0 +1,11 @@ +[Unit] +Description=Install busybox into stage 4 +After=initrd-root-fs.target +Wants=initrd-root-fs.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-install-busybox-stage4.sh diff --git a/modules.d/busybox/services/s3-install-busybox.service b/modules.d/busybox/services/s3-install-busybox.service new file mode 100644 index 00000000..b52500db --- /dev/null +++ b/modules.d/busybox/services/s3-install-busybox.service @@ -0,0 +1,11 @@ +[Unit] +Description=Install busybox applet symlinks +Before=dracut-cmdline.service +Wants=dracut-cmdline.service +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-install-busybox.sh -- cgit v1.2.3-55-g7522