summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2024-01-31 17:07:10 +0100
committerSimon Rettberg2024-01-31 17:07:10 +0100
commit501cdbda03871c619019980d1347b72743212de7 (patch)
tree350ae9f628c8c9cf57ef3d94d48259b0b08b5907
parent[slx-clock] Actually install ntp sync service (diff)
downloadsystemd-init-501cdbda03871c619019980d1347b72743212de7.tar.gz
systemd-init-501cdbda03871c619019980d1347b72743212de7.tar.xz
systemd-init-501cdbda03871c619019980d1347b72743212de7.zip
[busybox] Split into services
-rwxr-xr-xmodules.d/busybox/hooks/s3-install-busybox-stage4.sh35
-rwxr-xr-xmodules.d/busybox/hooks/s3-install-busybox.sh9
-rwxr-xr-xmodules.d/busybox/install-busybox-stage4.sh26
-rwxr-xr-xmodules.d/busybox/install-busybox.sh9
-rwxr-xr-xmodules.d/busybox/module-setup.sh12
-rw-r--r--modules.d/busybox/services/s3-install-busybox-stage4.service11
-rw-r--r--modules.d/busybox/services/s3-install-busybox.service11
7 files changed, 76 insertions, 37 deletions
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