summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2018-05-23 12:12:16 +0200
committerJonathan Bauer2018-05-23 12:12:16 +0200
commit9a645fc0e67a73be1533b6e0cfa5be2abf244719 (patch)
tree71f2aa3d5cae445a9192dd60827708213df87187
parentnew slx-drm and slx-splash (PoC) modules (diff)
downloadsystemd-init-9a645fc0e67a73be1533b6e0cfa5be2abf244719.tar.gz
systemd-init-9a645fc0e67a73be1533b6e0cfa5be2abf244719.tar.xz
systemd-init-9a645fc0e67a73be1533b6e0cfa5be2abf244719.zip
Support for stage4 addons
Stage4 can contain addons under /opt/openslx/addons/<addon_name>. The contents will be moved to the stage4 if the 'addon-required' script present in the addon's root directory returns 0. ld cache and whiteouts (files removed during the overlay'ed addon build) are automatically processed. NOTE: addon-init script of old is NOT executed atm, since for the only addon we use, it only handled the whiteouts (which is now done for every addon). See code for details...
-rwxr-xr-xbuilder/modules.d/slx-addons/module-setup.sh12
-rw-r--r--builder/modules.d/slx-addons/scripts/setup-addons.sh110
2 files changed, 122 insertions, 0 deletions
diff --git a/builder/modules.d/slx-addons/module-setup.sh b/builder/modules.d/slx-addons/module-setup.sh
new file mode 100755
index 00000000..296b3fe4
--- /dev/null
+++ b/builder/modules.d/slx-addons/module-setup.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+check() {
+ # Tell dracut that this module should only be included if it is required
+ # explicitly.
+ return 255
+}
+depends() {
+ echo dnbd3-rootfs
+}
+install() {
+ inst_hook pre-pivot 30 "$moddir/scripts/setup-addons.sh"
+}
diff --git a/builder/modules.d/slx-addons/scripts/setup-addons.sh b/builder/modules.d/slx-addons/scripts/setup-addons.sh
new file mode 100644
index 00000000..eb3b7595
--- /dev/null
+++ b/builder/modules.d/slx-addons/scripts/setup-addons.sh
@@ -0,0 +1,110 @@
+#!/usr/bin/env bash
+#
+# Stage4 addons setup script
+#
+###############################################################################
+# Support stage4 addons residing under '/opt/openslx/addons'.
+# This script will loop over all addons found, in the form of
+# directories containing directory structures relative to '/'
+#
+# Additionally addons are expected to provide:
+# * <addon_dir>/addon-required -> script to check whether the
+# addon should be installed (exit 0) or not (exit 1).
+#
+# * <addon_dir>/opt/openslx/etc/<addon_name>.whiteout -> list of files
+# that were removed during the addon installation and thus need to be
+# removed after the addon was installed.
+#
+# * <addon_dir>/opt/openslx/etc/<addon_name> ld.so.cache -> ld cache containing
+# the newly installed libraries. CAVE: multiple addons -> ld cache combination
+#
+### CURRENTLY NOT EXECUTED
+# * <addon_dir>/addon-init -> script that will be automatically
+# be executed after the addon was installed.
+# NOTE: question remains if this should be done within stage3
+# or by chroot'ing into the stage4 before executing it.
+### CURRENTLY NOT EXECUTED: Since whiteouts could be handled for _all_addons
+
+type emergency_shell >/dev/null 2>&1 || . /lib/dracut-lib.sh
+
+# Check if we even have any addons to process
+if [ ! -d "$NEWROOT/opt/openslx/addons" ]; then
+ info "No stage4 addons found."
+ return 0
+fi
+
+setup_addons() {
+ local ADDONS_DIR="$NEWROOT/opt/openslx/addons/"
+ cd "$ADDONS_DIR" || return 1
+ for ADDON in *; do
+ if ! setup_addon "$ADDON"; then
+ warn "Failed to setup $ADDON"
+ fi
+ done
+}
+
+setup_addon() {
+ [ -z "$1" -o ! -d "$ADDONS_DIR/$1" ] && return 1
+ local ADDON="$1"
+ cd "$ADDONS_DIR/$ADDON" || return 1
+
+ if [ ! -x "addon-required" ] || ! bash addon-required 2>&1 ; then
+ warn "'$ADDONS_DIR/$ADDON/addon-required' returned non-zero, skipping..."
+ return 1
+ fi
+
+ for entry in $(find * -not -wholename "addon-*" 2>/dev/null); do
+ if [ -d "$entry" ]; then
+ [ -d "/$entry" ] || mkdir -p "/${entry}"
+ continue
+ fi
+ local dir=${entry%/*}
+ [ -d "$NEWROOT/$dir" ] || mkdir -p "$NEWROOT/$dir"
+ if [ -f "$entry" -a ! -L "$entry" ]; then
+ if [ ! -e "$NEWROOT/${entry}" ] || ! diff -q "$entry" "$NEWROOT/${entry}"; then
+ mv -f -- "$entry" "$NEWROOT/${entry}"
+ fi
+ else
+ # either block dev, char dev or a symlink, just overwrite them "blindly"
+ mv -f -- "$entry" "$NEWROOT/${entry}"
+ fi
+ done
+
+ # post merge: remove whiteouts from filesystem
+ local WHITEOUTS="$NEWROOT/opt/openslx/etc/${ADDON}.whiteout"
+ if [ -e "$WHITEOUTS" ]; then
+ while read line; do
+ rm "${NEWROOT}/${line}"
+ done < "$WHITEOUTS"
+ fi
+
+ # finally update ld.so.cache expected to be under /opt/openslx/etc/<addon_name>.ld.so.cache
+ # NOTE: if we have more than one addon in the future, we need to be extra
+ # careful with prebuilt ld.caches since they need to match *ALL* addons
+ local ADDON_LD_CACHE="$NEWROOT/opt/openslx/etc/$ADDON.ld.so.cache"
+ if [ ! -e "$ADDON_LD_CACHE" ] || ! mv -f -- "$ADDON_LD_CACHE" "$NEWROOT/etc/ld.so.cache" ; then
+ # Using prebuilt ld cache failed, try hard to find a ldconfig...
+ local LDCONFIG="$(hash -t ldconfig 2>/dev/null)"
+ if [ -n "$LDCONFIG" ] && ! "${LDCONFIG}" --root "$NEWROOT"; then
+ return 0
+ fi
+ # try with chroot if we have it
+ local CHROOT_PATH="$(hash -t chroot 2>/dev/null)"
+ if [ -n "$CHROOT_PATH" ] && "$CHROOT_PATH" "$NEWROOT" ldconfig; then
+ return 0
+ fi
+ # fallbacks to file paths...
+ for LDCONFIG_CANDIDATE in {,${NEWROOT}/sbin/}ldconfig{,.real}; do
+ if [ -x "$LDCONFIG_CANDIDATE" ] && ${LDCONFIG_CANDIDATE} -r "$NEWROOT"; then
+ return 0
+ fi
+ done
+ # very bad indeed, libraries won't be register in the cache ...
+ warn "Failed to find 'ldconfig' to rebuild the addon's missing ld.so.cache..."
+ return 1
+ fi
+}
+
+if ! setup_addons; then
+ warn "Failed to fully setup some addons! They will likely malfunction..."
+fi