#! /bin/sh

# This is a wrapper around GNU tar that will generate a tarball that should be
# bit-for-bit identical each time it is run against the same directory. It wipes
# user ids, removes PAX timestamp headers, sets the modification time to the
# unix epoch and sorts the files by name.

ts="1970-01-01 00:00:00"

find "$@" \( \! -type d -o -type d -empty \) -print0 \
    | sort -z \
    | tar --format=posix \
       --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime,delete=mtime \
       --mtime="$ts" \
       --numeric-owner \
       --owner=0 \
       --group=0 \
       --mode="go-rwx,u+rw" \
       --null \
       --files-from - \
       -cvf -
