diff options
Diffstat (limited to 'builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh')
-rwxr-xr-x | builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh b/builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh index 619226f5..6a6b64f2 100755 --- a/builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh +++ b/builder/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh @@ -1,14 +1,7 @@ #!/usr/bin/env bash -# region imports type emergency_shell > /dev/null 2>&1 || source /lib/dracut-lib.sh source /etc/openslx -source '/usr/lib/rebash/core.sh' -core.import exceptions -core.import logging -# endregion -# region globals/helper -logging.set_log_file "${SLX_LOG_FILE_PATH:-/var/log/openslx}" # hardcode dnbd device path declare -rg _dnbd3_dev="/dev/dnbd0" @@ -20,18 +13,18 @@ container_unpack_xmount() { mkdir -p "$out_path" # check tools first if ! hash xmount systemd-preserve-process-marker; then - logging.warn "Missing xmount deps, will try raw..." 1>&2 + warn "Missing xmount deps, will try raw..." 1>&2 elif ! systemd-preserve-process-marker xmount \ --in qemu "$in_device" \ --out raw "$out_path" &>/dev/null; then - logging.warn "xmount call failed, assuming raw image." 1>&2 + warn "xmount call failed, assuming raw image." 1>&2 else in_device="${out_path}/${_dnbd3_dev##*/}.dd" fi local out_device="$(losetup -f)" if ! losetup "$out_device" "$in_device" --partscan; then - logging.warn "Failed to attach '$in_device' to '$out_device'." - return + warn "Failed to attach '$in_device' to '$out_device'." + return 1 fi udevadm settle echo "$out_device" @@ -41,7 +34,7 @@ container_unpack_losetup() { local in_device="$1" local out_device="$(losetup -f)" if ! losetup -r -t QCOW "$out_device" "$in_device" --partscan; then - logging.warn "Failed to attach '$in_device' to '$out_device'." + warn "Failed to attach '$in_device' to '$out_device'." return fi udevadm settle @@ -49,9 +42,6 @@ container_unpack_losetup() { } # endregion -exceptions.try -{ -# region connect dnbd3 image ( IFS=", " for host in ${SLX_DNBD3_SERVERS} FAIL; do @@ -60,7 +50,7 @@ for host in ${SLX_DNBD3_SERVERS} FAIL; do "${SLX_DNBD3_RID:+(revision: $SLX_DNBD3_RID)} " "from one of '$SLX_DNBD3_SERVERS' to '$_dnbd3_dev'." fi - logging.info "Trying host \"$host\"." + info "Trying host \"$host\"." if systemd-preserve-process-marker dnbd3-client \ --host "$host" \ --image "${SLX_DNBD3_IMAGE}" \ @@ -78,7 +68,7 @@ if [ "$SLX_QCOW_HANDLER" = "xmount" ]; then elif [ "$SLX_QCOW_HANDLER" = "kernel" ]; then read_only_device="$(container_unpack_losetup "$_dnbd3_dev")" else - logging.warn "Unsupported QCOW handler: $SLX_QCOW_HANDLER" + warn "Unsupported QCOW handler: $SLX_QCOW_HANDLER" fi # Fail fast if unpacking dnbd3 image failed. @@ -99,28 +89,15 @@ else eval "$SLX_SYSTEM_PARTITION_PREPARATION_SCRIPT" fi if [[ ! $? || -z "$read_only_partition" ]]; then - logging.error "Failed to find unique device with identifier" \ + warn "Failed to find unique device with identifier" \ "\"${SLX_SYSTEM_PARTITION_IDENTIFIER}\"; matched devices:" \ "\"${read_only_partition}\"" exit 1 fi -logging.info "Using read-only partition: $read_only_partition" +info "Using read-only partition: $read_only_partition" # endregion # region add rw layer to dnbd3 image # don't be fooled to think we are done, the next part is crucial dmsetup-slx-device "$read_only_partition" # endregion - -} -exceptions.catch -{ - logging.error "$exceptions_last_traceback" - emergency_shell "error in ${BASH_SOURCE[0]}" -} -# region vim modline - -# vim: set tabstop=4 shiftwidth=4 expandtab: -# vim: foldmethod=marker foldmarker=region,endregion: - -# endregion |