summaryrefslogtreecommitdiff
path: root/scripts/sha256sum
blob: 2a7ffb6f7ee711ccf738124f4ea0dc8dcf30053c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env bash
# This file is part of the OpenADK project. OpenADK is copyrighted
# material, please see the LICENCE file in the top-level directory.

if [ -x /usr/bin/sha256sum ]; then
	/usr/bin/sha256sum "$@"
elif [ -x /bin/cksum ] && [ $(echo | cksum -a sha256) = 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b ]; then
	# we assume the arguments are exactly "-c" or "-c -"
	x=$(sed 's/^\([0-9a-fA-F]*\) *\([^ ].*\)$/SHA256 (\2) = \1/' | cksum -c -a sha256)
	[[ $x = *FAILED* ]] && exit 1
	exit 0
else
	tmp=$(mktemp -t yyy)
	cat - > $tmp
	shasum -a 256 "$@" $tmp
fi