Build script compresses the image and generates the sha1sum now.

This commit is contained in:
Storm Dragon
2026-05-24 21:27:07 -04:00
parent 973b2573c8
commit 040eecca09
+64 -4
View File
@@ -24,18 +24,52 @@ mounted=1
set -e # Don't want to destroy stuff if this goes majorly wrong.
trap cleanup EXIT # make sure the script cleans up after itself before closing.
# shellcheck disable=SC2329 # verify_image is invoked from cleanup, which is invoked via trap EXIT
verify_image() {
echo "Checking completed image filesystems..."
fsck.vfat -n "${loopdev}p1"
e2fsck -fn "${loopdev}p2"
}
# shellcheck disable=SC2329 # compress_image is invoked from cleanup, which is invoked via trap EXIT
compress_image() {
local compressedImage="${imageName}.xz"
if [[ ! -s "${imageName}" ]]; then
echo "Image file ${imageName} was not created or is empty."
return 1
fi
echo "Compressing ${imageName} to ${compressedImage}..."
xz -T0 -9 "${imageName}"
echo "Creating SHA-256 checksum for ${compressedImage}..."
sha1sum "${compressedImage}" > "${compressedImage}.sha1sum"
echo "Image build complete: ${compressedImage}"
echo "Checksum: ${compressedImage}.sha1sum"
}
# shellcheck disable=SC2329 # cleanup is invoked via trap EXIT
cleanup() {
status=$? # capture original exit status so failures propagate
cleanupStatus=0
if [[ $mounted -eq 0 ]]; then
umount -R /mnt || true
if ! umount -R /mnt; then
cleanupStatus=1
elif [[ $status -eq 0 ]]; then
if ! verify_image; then
cleanupStatus=1
fi
fi
fi
if [[ -n "${loopdev:-}" ]]; then
partx -d "${loopdev}" || true
losetup --detach "${loopdev}" || true
if ! partx -d "${loopdev}"; then
cleanupStatus=1
fi
if ! losetup --detach "${loopdev}"; then
cleanupStatus=1
fi
fi
# Clean up temporary pacman config directory
@@ -43,6 +77,15 @@ cleanup() {
rm -rf "${tmpDir}"
fi
if [[ $status -eq 0 && $cleanupStatus -eq 0 ]]; then
if ! compress_image; then
status=1
fi
elif [[ $status -eq 0 ]]; then
echo "Image build commands completed, but cleanup or filesystem verification failed."
status=1
fi
exit "$status"
}
@@ -100,6 +143,12 @@ if [[ -e "$imageName" ]]; then
echo "${imageName} exists, please remove or move it for this script to continue."
exit 1
fi
for outputFile in "${imageName}.xz" "${imageName}.xz.sha256sum"; do
if [[ -e "$outputFile" ]]; then
echo "${outputFile} exists, please remove or move it for this script to continue."
exit 1
fi
done
# Make sure this script is ran as root.
if [ "$(whoami)" != "root" ] ; then
@@ -124,6 +173,12 @@ for i in arch-install-scripts dosfstools parted ; do
exit 1
fi
done
for i in e2fsck fsck.vfat sha256sum xz ; do
if ! command -v "$i" &> /dev/null ; then
echo "Please install ${i} before continuing."
exit 1
fi
done
fallocate -l "$imageSize" "$imageName"
@@ -257,12 +312,17 @@ packages=(
fake-hwclock
fenrir
firmware-raspberrypi
linux-firmware
git
gstreamer
gst-plugins-base
gst-plugins-good
ii
# Keep Pi onboard firmware plus common USB/network chipset firmware without
# pulling in unrelated desktop/server GPU firmware.
linux-firmware-atheros
linux-firmware-broadcom
linux-firmware-mediatek
linux-firmware-realtek
magic-wormhole
man
man-pages