diff options
author | EuAndreh <eu@euandre.org> | 2018-07-24 16:27:15 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2018-07-24 16:33:35 -0300 |
commit | 21d63cea4fdccf43b2fa4340289753e8e1146c39 (patch) | |
tree | d257db6f11e18ba540930d1150ad3063dfd8de48 /bash | |
parent | Add guix repo to geiser load-path (diff) | |
download | dotfiles-21d63cea4fdccf43b2fa4340289753e8e1146c39.tar.gz dotfiles-21d63cea4fdccf43b2fa4340289753e8e1146c39.tar.xz |
Add useful merkle-tree bash function
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 +} |