diff options
Diffstat (limited to 'modules.d/conf-tgz')
-rwxr-xr-x | modules.d/conf-tgz/hooks/fetch-config-tgz.sh | 29 | ||||
-rwxr-xr-x | modules.d/conf-tgz/hooks/unpack-config-tgz.sh | 41 | ||||
-rwxr-xr-x | modules.d/conf-tgz/module-setup.sh | 13 |
3 files changed, 83 insertions, 0 deletions
diff --git a/modules.d/conf-tgz/hooks/fetch-config-tgz.sh b/modules.d/conf-tgz/hooks/fetch-config-tgz.sh new file mode 100755 index 00000000..1c8ace61 --- /dev/null +++ b/modules.d/conf-tgz/hooks/fetch-config-tgz.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- + +type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh + + + slx_server="$(getarg slxsrv=)" + slx_server_base="$(getarg slxbase=)" + + if [ -z "$SLX_NO_CONFIG_TGZ" ]; then + # build config.tgz url + conftgz_url="http://${slx_server#@}/${slx_server_base}/config.tgz" + + # check if system's uuid was set + if [ -s "/run/system-uuid" ]; then + uuid="$(cat /run/system-uuid)" + if [ -n "$uuid" ]; then + conftgz_url="${conftgz_url}?uuid=${uuid}" + fi + fi + info "Download config.tgz from '$conftgz_url'..." + slx-tools download_retry -s "${conftgz_url}" > "/etc/config.tgz" + + if [[ ! -s "/etc/config.tgz" ]]; then + warn \ + "Downloading 'config.tgz' from '${slx_server}' failed with: $return_code" + # TODO handle error + fi + fi diff --git a/modules.d/conf-tgz/hooks/unpack-config-tgz.sh b/modules.d/conf-tgz/hooks/unpack-config-tgz.sh new file mode 100755 index 00000000..a0da0cd3 --- /dev/null +++ b/modules.d/conf-tgz/hooks/unpack-config-tgz.sh @@ -0,0 +1,41 @@ +#!/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 +} + +# this module unpacks the config.tgz +temporary_extract_directory="$(mktemp -d)" + if [[ -e "/etc/config.tgz" ]]; then + tar --extract --preserve-permissions \ + --file="/etc/config.tgz" \ + --directory="$temporary_extract_directory" + fi + warn "Failed to extract '/etc/config.tgz' to '$temporary_extract_directory'." + warn "$exceptions_last_traceback" +# extracted to temporary directory, now check for SLX_LOCAL_CONFIGURATION + +source "/etc/openslx" +if [[ -n "$SLX_LOCAL_CONFIGURATION" ]]; then + if [[ ! -d "${temporary_extract_directory}/openslx-configs/${SLX_LOCAL_CONFIGURATION}" ]]; then + warn "SLX_LOCAL_CONFIGURATION is set but no corresponding folder found in '/etc/config.tgz'. Ignoring..." + else + tarcopy "${temporary_extract_directory}/openslx-configs/${SLX_LOCAL_CONFIGURATION}" "${temporary_extract_directory}" + fi +fi + # purge openslx-configs/ + rm -rf "${temporary_extract_directory}/openslx-configs" + tarcopy "${temporary_extract_directory}" "$NEWROOT" + + + # TODO error handling diff --git a/modules.d/conf-tgz/module-setup.sh b/modules.d/conf-tgz/module-setup.sh new file mode 100755 index 00000000..a07539cb --- /dev/null +++ b/modules.d/conf-tgz/module-setup.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +check() { + return 255 +} +depends() { + echo dnbd3-rootfs slx-tools +} +install() { + inst_hook pre-mount 20 "$moddir/hooks/fetch-config-tgz.sh" + inst_hook pre-pivot 20 "$moddir/hooks/unpack-config-tgz.sh" + # TODO check if busybox is enough + inst_multiple tar mktemp gzip +} |