summaryrefslogtreecommitdiffstats
path: root/modules.d/slx-addons/scripts/setup-addons.sh
diff options
context:
space:
mode:
authorJonathan Bauer2020-05-25 11:26:54 +0200
committerJonathan Bauer2020-05-25 11:26:54 +0200
commit8b36285c9ec75ee9fa59f44b0714b952b574190f (patch)
tree3d4e51530e54e3d7643e47f2bd4e550be0de07f0 /modules.d/slx-addons/scripts/setup-addons.sh
parentbuild-initramfs.sh: support CentOS-7 again (diff)
parentMerge branch 'master' into nobash-merge (diff)
downloadsystemd-init-8b36285c9ec75ee9fa59f44b0714b952b574190f.tar.gz
systemd-init-8b36285c9ec75ee9fa59f44b0714b952b574190f.tar.xz
systemd-init-8b36285c9ec75ee9fa59f44b0714b952b574190f.zip
Merge branch 'nobash-merge' into downloader-nobash-merge
Diffstat (limited to 'modules.d/slx-addons/scripts/setup-addons.sh')
-rw-r--r--modules.d/slx-addons/scripts/setup-addons.sh99
1 files changed, 48 insertions, 51 deletions
diff --git a/modules.d/slx-addons/scripts/setup-addons.sh b/modules.d/slx-addons/scripts/setup-addons.sh
index 94c2c444..d4b94a1a 100644
--- a/modules.d/slx-addons/scripts/setup-addons.sh
+++ b/modules.d/slx-addons/scripts/setup-addons.sh
@@ -33,44 +33,40 @@ if [ ! -d "$NEWROOT/opt/openslx/addons" ]; then
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
+# This just activates the ldconfig service to run during the sysinit target
+# Since addons are likely to install libs, this is necessary to garantee
+# that the live system "sees" the libraries.
+activate_stage4_ldconfig() {
+ local service_path="/opt/openslx/services/ldconfig.service"
+ [ -e "$service_path" ] || return 1
+ local target_dir="${NEWROOT}/etc/systemd/system/sysinit.target.wants"
+ mkdir -p "$target_dir"
+ cp -f "$service_path" "${NEWROOT}/etc/systemd/system/${service_path##*/}"
+ ln -sf "../${service_path##*/}" "${target_dir}/${service_path##*/}"
}
setup_addon() {
- [ -z "$1" -o ! -d "$ADDONS_DIR/$1" ] && return 1
- local ADDON="$1"
- cd "$ADDONS_DIR/$ADDON" || return 1
-
+ if [ ! -d "$1" ]; then
+ warn "Given '$1' not a directory, skipping."
+ return 1
+ fi
+ local addon_dir="$1"
+ cd "$addon_dir"
if ! bash addon-required 2>&1 ; then
- info "'$ADDONS_DIR/$ADDON/addon-required' missing or returned non-zero, skipping..."
+ info "'$addon_dir/addon-required' missing or returned non-zero, skipping..."
return 1
fi
+ # purge addon-* files
+ rm -f -- addon-*
- 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
+ # move all the files over
+ for entry in $(find * -not -type d 2>/dev/null); do
+ [ "$entry" != "${entry%/*}" ] && mkdir -p "${NEWROOT}/${entry%/*}"
+ mv -f -- "$entry" "${NEWROOT}/${entry}"
done
- # post merge: remove whiteouts from filesystem
+ # 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
@@ -78,28 +74,29 @@ setup_addon() {
done < "$WHITEOUT"
done
- # 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...
- for LDCONFIG in "$(type -p ldconfig 2>/dev/null)" "${NEWROOT}/sbin/ldconfig.real"; do
- if [ -x "$LDCONFIG" ] && "$LDCONFIG" -r "$NEWROOT"; then
- return 0
- fi
- done
- # try with chroot if we have it
- local CHROOT_PATH="$(type -p chroot 2>/dev/null)"
- if [ -x "$CHROOT_PATH" ] && "$CHROOT_PATH" "$NEWROOT" ldconfig; then
- return 0
- fi
- # very bad indeed, libraries won't be registered in the cache ...
- warn "Failed to find 'ldconfig' to rebuild the addon's missing ld.so.cache..."
- return 1
- fi
+ cd - &>/dev/null
}
-if ! setup_addons; then
- warn "Failed to fully setup some addons! They will likely malfunction..."
+active=()
+for addon in "${NEWROOT}/opt/openslx/addons/"*; do
+ if setup_addon "$addon"; then
+ active+=("${addon#${NEWROOT}/opt/openslx/addons/}")
+ info "Activated '$addon' (@ $(date +%s))"
+ fi
+done
+
+# if only one addon was installed, use its pre-generated ld.so.cache
+# if more than one were installed, make sure ldconfig is called in stage4
+if [ "${#active[@]}" -eq 1 ]; then
+ addon_cache="${NEWROOT}/opt/openslx/etc/${active[0]}.ld.so.cache"
+ if [ -e "$addon_cache" ]; then
+ info "Using ld.so.cache of '${active[0]}'."
+ mv -f -- "${NEWROOT}/etc/ld.so.cache"{,.stage4}
+ mv -f -- "$addon_cache" "${NEWROOT}/etc/ld.so.cache"
+ fi
+elif [ "${#active[@]}" -gt 1 ]; then
+ info "Activating ldconfig in stage4 due to multiple loaded addons: ${active[@]}"
+ activate_stage4_ldconfig
fi
+
+: