diff options
Diffstat (limited to 'gen-checksums')
-rwxr-xr-x | gen-checksums | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/gen-checksums b/gen-checksums new file mode 100755 index 0000000..785aff6 --- /dev/null +++ b/gen-checksums @@ -0,0 +1,104 @@ +#!/bin/sh + +# Copyright © 2024, 2025 Mattias Andrée (m@maandree.se) +# +# Copying and distribution of this script, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This script is offered as-is, +# without any warranty. + + +set -e + +if ! test $# = 2 || test -t 0 || test -t 1; then + printf 'usage: %s tarball git-dir < version-info-file > checksum-listing\n' "$0" >&2 + exit 1 +fi + +tarball="$1" +gitdir="$2" + +urls="$(grep '^Tarball: ' | cut -d ' ' -f 2 | grep -v '^https://maandree.se/static/')" + +workdir="$$.tmpdir" +rm -rf -- "${workdir}" + +refdir="${workdir}/reference" +mkdir -p -- "${refdir}" +gunzip < "${tarball}" | (cd "${refdir}" && tar -x) +if test "$(printf '%s\n' "${refdir}"/* | wc -l)" = 1; then + refdir="$(printf '%s\n' "${refdir}"/*)" +fi + +ln -s -- "$(cd -- "${gitdir}" && pwd)" "${workdir}/gitdir" + +add_dirs () { + while read f; do + printf '%s\n' "$f" + while :; do + d="$(printf '%s\n' "$f" | sed 's|/[^/]*$||')" + if test "$d" = "$f"; then + break + fi + printf '%s\n' "$d" + f="$d" + done + done +} + +gitfiles="$( (cd -- "${gitdir}" && git ls-files) | add_dirs | sort -u | tee -- "${workdir}/gitfiles")" +test -n "${gitfiles}" +tarfiles="$( (cd -- "${refdir}" && find) | sed 's/^\.\///' | sed '/^\.$/d' | add_dirs | sort -u | tee -- "${workdir}/tarfiles")" +test -n "${tarfiles}" +diff -u -- "${workdir}/gitfiles" "${workdir}/tarfiles" >&2 +# the following line makes the safe assumption that $workdir (and $refdir) does not contain {} +xargs -I {} diff -u "${refdir}"/{} "${workdir}/gitdir"/{} < "${workdir}/gitfiles" >&2 + +getandcheck () { + url="$1" + number="$2" + curl -sL -- "${url}" > "${workdir}/downloaded-${number}.tar.gz" + checkdir="${workdir}/downloaded" + rm -rf -- "${checkdir}" + mkdir -p -- "${checkdir}" + gunzip < "${workdir}/downloaded-${number}.tar.gz" | (cd "${checkdir}" && tar -x) + if test "$(printf '%s\n' "${checkdir}"/* | wc -l)" = 1; then + checkdir="$(printf '%s\n' "${checkdir}"/*)" + fi + diff -ur -- "${refdir}" "${checkdir}" >&2 + rm -rf -- "${checkdir}" +} + +nr=1 +for url in $urls; do + getandcheck "${url}" $(( nr++ )) +done + +genfor () { + tool="$1" + name="$2" + sum="$(${tool} < "${tarball}" | cut -d ' ' -f 1)" + sums="$(printf '%s checksum: %s\n' "${name}" "${sum}")" + number=1 + for url in $urls; do + sum="$($tool < "${workdir}/downloaded-${number}.tar.gz" | cut -d ' ' -f 1)" + test -n "$sum" + sums="$(printf '%s\n%s checksum: %s\n' "${sums}" "${name}" "${sum}")" + : $(( number++ )) + done + printf '%s\n' "${sums}" | sort -u +} + +genfor sha224sum SHA224 +genfor sha256sum SHA256 +genfor sha384sum SHA384 +genfor sha512sum SHA512 +genfor sha512-224sum SHA512/224 +genfor sha512-256sum SHA512/256 +genfor sha3-224sum SHA3-224 +genfor sha3-256sum SHA3-256 +genfor sha3-384sum SHA3-384 +genfor sha3-512sum SHA3-512 +genfor b2sum BLAKE2b + +rm -rf -- "${workdir}" |