diff options
Diffstat (limited to 'bash')
-rw-r--r-- | bash/util.sh | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/bash/util.sh b/bash/util.sh index b0db4ad..dfdfc12 100644 --- a/bash/util.sh +++ b/bash/util.sh @@ -21,3 +21,12 @@ extract () { echo "'$1' is not a valid file!" fi } + +merkle-tree () { + dirname="${1-.}" + find "$dirname" -type f | \ # get all files in the $dirname tree + sort | \ # sort them to get the same result on different filesystems + xargs sha256sum | \ # compute the SHA256 of each file, BONUS it outputs the filename, so if the content does not change but the filename does, the end hash will be different + sha256sum | \ # compute the final hash + awk '{print $1}' # omit the filename, which is `-` as stdin in this case +} |