diff options
Diffstat (limited to 'modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh')
-rwxr-xr-x | modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh b/modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh new file mode 100755 index 00000000..2132423c --- /dev/null +++ b/modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- + +type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh + +# tarcopy <source_dir> <target_dir> +tarcopy() { + [ -d "$1" -a -d "$2" ] || return 1 + cd "$1" + local filelist="$(mktemp)" + find . \! -type d > "$filelist" + tar -c -p -T "$filelist" | tar -xp -C "$2" + rm -f -- "$filelist" + cd - &>/dev/null +} + +unpack_config_tgz() { + local config_tgz="/etc/config.tgz" + [ -e "$config_tgz" ] || return 1 + # create list of overwritten files for debugging purposes + mkdir -p "${NEWROOT}/opt/openslx" + tar \ + --list \ + --verbose \ + --file="$config_tgz" \ + > "${NEWROOT}/opt/openslx/config.tgz.list" 2>&1 + local extract_dir="$(mktemp -d)" + tar \ + --extract \ + --preserve-permissions \ + --file="$config_tgz" \ + --directory="$extract_dir" + if [ "$?" -ne 0 ]; then + warn "Failed to extract '$config_tgz' to '$extract_dir'." + return 1 + fi + # check SLX_LOCAL_CONFIGURATION + source "/etc/openslx" + if [ -n "$SLX_LOCAL_CONFIGURATION" ]; then + if [ ! -d "${extract_dir}/openslx-configs/${SLX_LOCAL_CONFIGURATION}" ]; then + warn "Ignoring missing SLX_LOCAL_CONFIGURATION in '$config_tgz'." + else + tarcopy \ + "${extract_dir}/openslx-configs/${SLX_LOCAL_CONFIGURATION}" \ + "${extract_dir}" + fi + fi + # always purge openslx-configs/ + rm -rf "${extract_dir}/openslx-configs" + + # finally copy the rest into stage4 + if ! tarcopy "${extract_dir}" "$NEWROOT"; then + warn "'tarcopy' from '$extract_dir' to '$NEWROOT' failed." + fi +} + +unpack_config_tgz +: |