rocky-linux-generic-images/create-image.sh

56 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -x
APPLIANCE_NAME="Rocky-9-aarch64-Orange-Pi-5-minimal"
KICKSTARTER_FILENAME="${APPLIANCE_NAME}.ks"
IMAGE_NAME="${APPLIANCE_NAME}-$(TZ='UTC' date +%Y.%m.%d-%H%M%S).raw"
COMPRESSED_IMAGE_NAME="${IMAGE_NAME}.zst"
if [[ ${EUID} -ne 0 ]]; then
>&2 echo "$0: error: Please run this script as root"
exit 1
fi
if ! command -v appliance-creator > /dev/null; then
>&2 echo "$0: error: unable to find command 'appliance-creator'"
exit 1
fi
if ! command -v shasum > /dev/null; then
>&2 echo "$0: error: unable to find command 'shasum'"
exit 1
fi
appliance-creator \
--config "${KICKSTARTER_FILENAME}" \
--name "${APPLIANCE_NAME}" \
--format raw \
--no-compress \
--outdir "${PWD}" \
--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 \
# DO NOT USE THE '--cache' OPTION SINCE IT USES OLDER VERSIONS
# OF PACKAGES, WHICH IS THE WORST WHEN TESTING CHANGES:w
#--cache "/root/cache" \
if [[ -d "${APPLIANCE_NAME}" ]]; then
pushd "${APPLIANCE_NAME}" || exit 1
mv -v -f "${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
echo 'DONE'
echo "Please chown '${APPLIANCE_NAME}/' if necessary"
fi