#!/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-required -> script to check whether the # addon should be installed (exit 0) or not (exit 1). # # * /opt/openslx/etc/.whiteout -> list of files # that were removed during the addon installation and thus need to be # removed after the addon was installed. # # * /opt/openslx/etc/ ld.so.cache -> ld cache containing # the newly installed libraries. CAVE: multiple addons -> ld cache combination # ### CURRENTLY NOT EXECUTED # * /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 info "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 ! bash addon-required 2>&1 ; then info "'$ADDONS_DIR/$ADDON/addon-required' missing or returned non-zero, skipping..." return 1 fi # purge addon-* files rm -f -- addon-* # move all the files over for entry in $(find * -not -type d 2>/dev/null); do mkdir -p "${NEWROOT}/${entry%/*}" mv -f -- "$entry" "${NEWROOT}/${entry}" done # post merge: remove files marked as whiteouts # (e.g. they were removed during the addon installation) for WHITEOUT in "$NEWROOT/opt/openslx/etc/"*.whiteout; do [ -e "$WHITEOUT" ] || continue while read line; do rm -f "${NEWROOT}/${line}" done < "$WHITEOUT" done } if ! setup_addons; then warn "Failed to fully setup some addons! They will likely malfunction..." fi