diff options
Diffstat (limited to 'modules.d/conf-tgz')
-rwxr-xr-x | modules.d/conf-tgz/hooks/s3-fetch-config-tgz.sh | 38 | ||||
-rwxr-xr-x | modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh | 90 |
2 files changed, 64 insertions, 64 deletions
diff --git a/modules.d/conf-tgz/hooks/s3-fetch-config-tgz.sh b/modules.d/conf-tgz/hooks/s3-fetch-config-tgz.sh index 2ed5f579..1d032a19 100755 --- a/modules.d/conf-tgz/hooks/s3-fetch-config-tgz.sh +++ b/modules.d/conf-tgz/hooks/s3-fetch-config-tgz.sh @@ -1,27 +1,27 @@ -#!/usr/bin/env bash +#!/bin/ash # -*- coding: utf-8 -*- -type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh - . /etc/openslx -if [ -z "$SLX_NO_CONFIG_TGZ" ]; then - # build config.tgz url from SLX_KCL_SERVERS and SLX_BASE_PATH - # both are written to /etc/openslx by dnbd3-rootfs's s3-fetch-config.sh script - conftgz_url="http://${SLX_KCL_SERVERS}/${SLX_BASE_PATH}/config.tgz" +[ -n "$SLX_NO_CONFIG_TGZ" ] && exit 0 - # 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 --slx-time 20 -sS "${conftgz_url}" > "/etc/config.tgz" +# build config.tgz url from SLX_KCL_SERVERS and SLX_BASE_PATH +# both are written to /etc/openslx by dnbd3-rootfs's s3-fetch-config.sh script +conftgz_url="http://${SLX_KCL_SERVERS}/${SLX_BASE_PATH}/config.tgz" - if [[ ! -s "/etc/config.tgz" ]]; then - warn "Failed to download '${conftgz_url}'!" +# 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 -: +echo "Download config.tgz from '$conftgz_url'..." +slx-tools download_retry --slx-time 20 -sS "${conftgz_url}" > "/etc/config.tgz" + +if ! [ -s "/etc/config.tgz" ]; then + echo "Failed to download '${conftgz_url}'" + exit 1 +fi + +exit 0 diff --git a/modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh b/modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh index 2132423c..0ab877dd 100755 --- a/modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh +++ b/modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh @@ -1,58 +1,58 @@ -#!/usr/bin/env bash +#!/bin/ash # -*- 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" +tarcopy() ( + if ! [ -d "$1" ] || ! [ -d "$2" ]; then + echo "'$1' or '$2' is not a directory" + return 1 + fi + cd "$1" || return 1 local filelist="$(mktemp)" find . \! -type d > "$filelist" - tar -c -p -T "$filelist" | tar -xp -C "$2" + if [ -s "$filelist" ]; then + tar -c -p -T "$filelist" | tar -xp -C "$2" || return 1 + fi rm -f -- "$filelist" - cd - &>/dev/null -} + return 0 +) -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 \ +config_tgz="/etc/config.tgz" +[ -e "$config_tgz" ] || exit 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 +extract_dir="$(mktemp -d)" +if ! 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 + --directory="$extract_dir"; then + echo "Failed to extract '$config_tgz' to '$extract_dir'." + exit 1 +fi +# check SLX_LOCAL_CONFIGURATION +. "/etc/openslx" +if [ -n "$SLX_LOCAL_CONFIGURATION" ]; then + if ! [ -d "${extract_dir}/openslx-configs/${SLX_LOCAL_CONFIGURATION}" ]; then + echo "Ignoring missing SLX_LOCAL_CONFIGURATION in '$config_tgz'." + else + tarcopy \ + "${extract_dir}/openslx-configs/${SLX_LOCAL_CONFIGURATION}" \ + "${extract_dir}" 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" +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 -} +# finally copy the rest into stage4 +if ! tarcopy "${extract_dir}" "$NEWROOT"; then + echo "'tarcopy' from '$extract_dir' to '$NEWROOT' failed." + exit 1 +fi -unpack_config_tgz -: +exit 0 |