From 21d63cea4fdccf43b2fa4340289753e8e1146c39 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Tue, 24 Jul 2018 16:27:15 -0300 Subject: Add useful merkle-tree bash function --- bash/util.sh | 9 +++++++++ 1 file changed, 9 insertions(+) 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 +} -- cgit v1.2.3