#!/bin/sh set -eu if [ "$#" -lt 1 ]; then echo "usage: $0 ROOT [ROOT ...]" >&2 exit 2 fi manifest_file="$(mktemp)" trap 'rm -f "$manifest_file"' EXIT INT TERM root_index=0 file_count=0 for root in "$@"; do if [ ! -d "$root" ]; then echo "library root is unavailable: $root" >&2 exit 3 fi root_index=$((root_index + 1)) count="$(find "$root" -type f -printf . | wc -c)" file_count=$((file_count + count)) (cd "$root" && find . -type f -printf "${root_index}\t%P\t%s\t%T@\0") >> "$manifest_file" done digest="$(LC_ALL=C sort -z "$manifest_file" | sha256sum | cut -d ' ' -f 1)" printf 'sha256=%s files=%s roots=%s\n' "$digest" "$file_count" "$#"