!/bin/bash
# Create _sha256tree.txt with checksums for each file in tree
# Excludes file starting with . or ^
# Uses /tmp for temp files
# May fail with some chars in file names
# Check with shasum -c _sha256tree.txt
# Based on
https://superuser.com/questions/458326/sha1sum-for-a-directory-of-directories
#
# Create two temp files
tsort=$(mktemp /tmp/shar256srt.XXXXXXXX)
tsh=$(mktemp /tmp/shar256sh.XXXXXXXX)
# Get sorted list of files excluding starting with . or ^
find . -type f \! -name ".*" \! -name "^*" \! -name "_sha*" | sort > $tsort
# Create script to shasum each file
awk '{print "shasum -a 256 \""$0"\""}' $tsort > $tsh
# Run scrip to create file with the shasum of each file
bash $tsh > _sha256tree.txt
# clean up
rm $tsort
rm $tsh