#!/bin/ash
# jamesbond 2011 & SFR 2017 GPLv3

export TEXTDOMAIN=fatdog
export OUTPUT_CHARSET=UTF-8

[ "$1" ] || exit 1

# Name|Command Name State
hashes="${FATDOG_CHECKSUM_HASHES:-
CRC|cksum CRC off
MD5|md5sum MD5 off
SHA1|sha1sum SHA1 off
SHA224|sha224sum SHA224 off
SHA256|sha256sum SHA256 off
SHA384|sha384sum SHA384 off
SHA512|sha512sum SHA512 off
SHA3|sha3sum SHA3 off
}"

hashes=$(Xdialog --stdout \
				 --no-tags \
				 --title "$(gettext "File checksums")" \
				 --checklist "$(gettext "Select which hashes to calculate:")" 0 0 8 ${hashes} | \
				 sed 's#/#\n#g')
				 
[ "$hashes" ] || exit 1

for hash in ${hashes}; do
	echo "${hash%%|*} $(gettext "sums"):" | sed "p; s/./=/g"
	find "$@" -type f -print0 | xargs -0 "${hash##*|}" 2>&1 | sed "s|/[^\/].*/||" | sort -k3 -t ' '
	echo
done | Xdialog --no-cancel \
			   --fixed-font \
			   --title "$(gettext "File checkums")" \
			   --tailbox - 20 100

exit
