Files
makronix/tools/keep-images.sh
T
lotherkandClaude Opus 5.5 118b19a171 make usb: remove the image's work files before and after the build; keep one image backup
The install image left about 34 GB of work files in build/obj/distrib/amd64/
installimage (work/, work.rootfs, imgroot.fs, work.img), and a killed run
left install(1)'s temporary copy in RELEASEDIR/images (6.3 GB,
Makronix-0.99.11-amd64-install.img.inst.f7YyCj).  The root disk was at 99%
(15 GB free) while make usb still had 20 GB to write.

make usb now runs NetBSD's clean target of Makefile.bootimage before and
after install-image and removes *.img.inst.* first.  keep-images.sh keeps
one build/keep-* by default instead of two (each holds 10-20 GB).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 19:31:40 +00:00

67 lines
2.1 KiB
Bash

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# keep-images.sh -- copy the install images out of the release directory
#
# usage: tools/keep-images.sh NAME
#
# `make stamp' (and with it the next `make release') removes what the build
# derived from sources that have changed, the release directory with its
# images among it. A medium that was built and is good should not go with it
# before the next one is: this copies the images and their checksums to
# build/keep-NAME/ and verifies the copy against SHA512. It only reads the
# release directory; it never writes there.
set -eu
TOP=$(cd "$(dirname "$0")/.." && pwd)
N=1
while [ $# -gt 0 ]; do
case "$1" in
-n) shift; N=${1:-1}; shift ;;
*) break ;;
esac
done
[ $# -eq 1 ] || { echo "usage: $0 [-n N] NAME" >&2; exit 2; }
NAME=$1
SRC=$TOP/build/obj/releasedir/images
DST=$TOP/build/keep-$NAME
[ -d "$SRC" ] || { echo "keep-images: no $SRC" >&2; exit 1; }
mkdir -p "$DST"
n=0
for f in "$SRC"/*.img "$SRC"/*.iso "$SRC"/MD5 "$SRC"/SHA512; do
[ -f "$f" ] || continue
cp -p "$f" "$DST/"
n=$((n + 1))
done
[ "$n" -gt 0 ] || { echo "keep-images: nothing in $SRC" >&2; exit 1; }
# the copy must be what the build wrote
if [ -f "$DST/SHA512" ]; then
(cd "$DST" && while read -r line; do
f=${line#SHA512 (}; f=${f%%)*}
want=${line##*= }
[ -f "$f" ] || continue
got=$(sha512sum "$f" | cut -d' ' -f1)
[ "$got" = "$want" ] || { echo "keep-images: $f differs from SHA512" >&2; exit 1; }
echo "keep-images: $f ok"
done < SHA512)
fi
echo "keep-images: $n file(s) in build/keep-$NAME"
# retain only the newest N build/keep-* backups (N=${N}); never touch
# releasedir. Newest by time (ls -t), not by name, and the one just made is
# always kept: sorted by name, `keep-0.99.10-0211' would have lost to
# `keep-sourcedvd' and been removed right after it was written.
cd "$TOP/build"
set -- "keep-$NAME" $(ls -1td keep-* 2>/dev/null | head -n "$N")
for d in keep-*; do
[ -d "$d" ] || continue
keep=
for k in "$@"; do
[ "$k" = "$d" ] && keep=yes
done
[ -n "$keep" ] || rm -rf "$d"
done