sbc-images/create-image.sh
2023-09-13 06:59:56 +05:30

45 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -x
KICKSTART_BASE="Rocky"
KICKSTART_FILE="${KICKSTART_BASE}.ks"
APPLIANCE_NAME="${KICKSTART_BASE}-$(dnf config-manager --dump-variables | grep releasever | awk '{print $3}')-$(uname -m)-minimal-$(TZ='UTC' date +%Y.%m.%d)"
IMAGE_NAME="${APPLIANCE_NAME}.raw"
Z_IMG_NAME="${IMAGE_NAME}.zst"
COMMANDS_TO_CHECK=('appliance-creator' 'shasum' 'zstd')
for COMMAND in "${COMMANDS_TO_CHECK[@]}"; do
if ! command -v "${COMMAND}" > /dev/null; then
>&2 echo "$0: ERROR: unable to find command '${COMMAND}' in PATH"
exit 1
fi
done
appliance-creator \
--config "${KICKSTART_FILE}" \
--name "${APPLIANCE_NAME}" \
--format raw \
--outdir "${PWD}" \
--no-compress \
--debug \
--cache /root/cache \
--verbose 2>&1 | tee "log-${APPLIANCE_NAME}"|| exit 1
if [[ -d "${APPLIANCE_NAME}" ]]; then
pushd "${APPLIANCE_NAME}" || exit 1
mv -f "${APPLIANCE_NAME}-sda.raw" "${IMAGE_NAME}"
zstd --compress -9 "${IMAGE_NAME}"
sha512sum "${IMAGE_NAME}" > SHA512SUMS
sha512sum "${Z_IMG_NAME}" >> SHA512SUMS
sha256sum "${IMAGE_NAME}" > SHA256SUMS
sha256sum "${Z_IMG_NAME}" >> SHA256SUMS
popd || exit 0
else
>&2 echo "$0: ERROR: unable to find the appliance output directory"
>&2 echo "$0: ${APPLIANCE_NAME}"
exit 1
fi