# vim: ft=sh:noml:
# commands used:
# - md5sum
# - pv
# - tar
#
# calculate a checksum for a directory
# taking into account the content, filename and metadata

(
  cd "$1" || return 1

  total_size="$(command -p -- du -s . | cut -f1)"

  find . \
    | LC_ALL=C sort \
    | tar --no-recursion -cf - -T - \
    | pv -s "${total_size}" -D3 -eb \
    | md5sum \
    | cut -d' ' -f1
)
