From 06e3fea70bad6c3e5cfbbce14d2b8c736218a982 Mon Sep 17 00:00:00 2001 From: Pratham Patel Date: Sat, 29 Jul 2023 13:02:14 +0530 Subject: [PATCH] THE FINAL BOSS --- create-image.sh | 62 ++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/create-image.sh b/create-image.sh index 95cdae5..e16428d 100755 --- a/create-image.sh +++ b/create-image.sh @@ -1,45 +1,45 @@ #!/usr/bin/env bash -REAL_USER=$(who am i | awk '{print $1}') +set -x + APPLIANCE_NAME="Rocky-9-aarch64-minimal" KICKSTARTER_FILENAME="${APPLIANCE_NAME}.ks" +IMAGE_NAME="${APPLIANCE_NAME}-$(date +%Y.%m.%d).raw" +COMPRESSED_IMAGE_NAME="${IMAGE_NAME}.zst" if [[ ${EUID} -ne 0 ]]; then >&2 echo "ERROR: Please run this script as root" exit 1 fi -appliance-creator \ - --config "${KICKSTARTER_FILENAME}" \ - --name "${APPLIANCE_NAME}" \ - --format raw \ - --no-compress \ - --outdir "${PWD}" \ - --cache "/root/cache" \ - --debug \ - --verbose \ - 1> Rocky-9-aarch64-minimal.stdout.log \ - 2> Rocky-9-aarch64-minimal.stderr.log - #--checksum - # DO NOT USE THE '--checksum' OPTION BECAUSE, FOR SOME REASON - # UTF8 ERRORS ARE GENERATED DURING IMAGE CREATION - # AND THE IMAGE CREATION STEP FAILS +{ + appliance-creator \ + --config "${KICKSTARTER_FILENAME}" \ + --name "${APPLIANCE_NAME}" \ + --format raw \ + --no-compress \ + --outdir "${PWD}" \ + --cache "/root/cache" \ + --debug \ + --verbose + # DO NOT USE THE '--checksum' OPTION BECAUSE, FOR SOME REASON + # UTF8 ERRORS ARE GENERATED DURING IMAGE CREATION + # AND THE IMAGE CREATION STEP FAILS + #--checksum \ -if [[ -f "${APPLIANCE_NAME}-sda.raw" ]]; then - set -x + if [[ -d "${APPLIANCE_NAME}" ]]; then - IMAGE_NAME="${APPLIANCE_NAME}-$(date +%Y.%m.%d).raw" - COMPRESSED_IMAGE_NAME="${IMAGE_NAME}.zst" + pushd "${APPLIANCE_NAME}" || exit 1 + mv -v -f "${APPLIANCE_NAME}-sda.raw" "${IMAGE_NAME}" + zstd -9 -z "${IMAGE_NAME}" - touch "${APPLIANCE_NAME}-sda.raw" - mv -v "${APPLIANCE_NAME}-sda.raw" "${IMAGE_NAME}" - zstd -9 -z "${IMAGE_NAME}" + sha256sum "${IMAGE_NAME}" > "${IMAGE_NAME}.sha256" + sha512sum "${IMAGE_NAME}" > "${IMAGE_NAME}.sha512" + sha256sum "${COMPRESSED_IMAGE_NAME}" > "${COMPRESSED_IMAGE_NAME}.sha256" + sha512sum "${COMPRESSED_IMAGE_NAME}" > "${COMPRESSED_IMAGE_NAME}.sha512" + popd || exit 1 - sha256sum "${IMAGE_NAME}" > "${IMAGE_NAME}.sha256" - sha512sum "${IMAGE_NAME}" > "${IMAGE_NAME}.sha512" - - sha256sum "${COMPRESSED_IMAGE_NAME}" > "${COMPRESSED_IMAGE_NAME}.sha256" - sha512sum "${COMPRESSED_IMAGE_NAME}" > "${COMPRESSED_IMAGE_NAME}.sha512" - - chown -v "${REAL_USER}:${REAL_USER}" "${IMAGE_NAME}*" -fi + echo 'DONE' + echo "Please chown '${APPLIANCE_NAME}/' if necessary" + fi +} 1> "${APPLIANCE_NAME}.1.stdout.log" 2> "${APPLIANCE_NAME}.2.stderr.log"