commit 0e1df6cf59afc9818a54a4e1cfc26060c97442a5
parent 01447982a2fa4c275f8bc6a6f278c3106453b7c7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Sun, 26 Jan 2025 14:09:32 +0100
Fix checksum implementation using sha256 command
Checksum options were not handled correctly, and sha256 results were
parsed incorrectly.
Note that the use of sha256 is aimed at BSD systems such as
DragonFlyBSD, FreeBSD, NetBSD and OpenBSD. However, this commit has not
been directly tested on these systems; the sha256 command has been
verified on some of them, but not its use in git-wad. Instead, git-wad
"BSD" was "emulated" on GNU/Linux by writing a sha256 command from
sha256sum, which was possible given that sha256 is called by git-wad in
a single way, without any options, by submitting the file to be
processed via standard input. But in any case, tests on the targeted
systems still need to be carried out to ensure portability.
Diffstat:
| M | git-wad | | | 27 | +++++++++++++-------------- |
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/git-wad b/git-wad
@@ -316,27 +316,26 @@ checksum() # [-c]
shasum -a 256 "$@"
elif command -v sha256 1> /dev/null 2>&1; then
- sha256re='SHA256 (\([^)]\+\)) = \([0-9a-zA-Z]\{64\}\)$'
# Calculate checksum
- if [ "$#" -eq 1 ] || [ "$1" != "-c" ]; then
- sha256 | sed__ "s/${sha256re}/\2 \1/"
+ if [ "$#" -eq 0 ] || [ "$1" != "-c" ]; then
+ sha256
# Check checksum
else
shift 1 # Discard the -c option
- in="$(cat -)"
- ref="$(echo "${in}" | cut -d' ' -f1)"
- file="$(echo "${in}" | cut -d' ' -f3)"
-
- sum="$(sha256 "${file}" | sed__ "s/${sha256re}/\2 \1/")"
- if [ "${ref}" = "${sum}" ]; then
- printf '%s: OK\n' "${file}"
- else
- printf '%s: FAILED\n' "${file}"
- return 1
- fi
+ while read -r i; do
+ ref="$(echo "${i}" | cut -d' ' -f1)"
+ file="$(echo "${i}" | cut -d' ' -f3)"
+
+ sum="$(sha256 < "${file}")"
+ if [ "${ref}" = "${sum}" ]; then
+ printf '%s: OK\n' "${file}"
+ else
+ printf '%s: FAILED\n' "${file}"
+ fi
+ done
fi
fi
}