create_tarball: Modify the tarball creation so that it is reproducible.

Note: If gzip or pigz is used, it is necessary to use the "-n" option.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
pull/2/head
Slávek Banko 5 years ago
parent 5c39eb0954
commit 428c2d88b4
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -15,9 +15,9 @@ TARBALL_DIR=${TARBALL_DIR:-".."}
# Set compression method # Set compression method
case ${COMPRESS:="xz"} in case ${COMPRESS:="xz"} in
"gzip"|"pigz") TAR_SUFFIX="gz";; "gzip"*|"pigz"*) TAR_SUFFIX=".gz";;
"bzip2"|"pbzip2") TAR_SUFFIX="bz2";; "bzip2"|"pbzip2") TAR_SUFFIX=".bz2";;
"xz"|"pxz") TAR_SUFFIX="xz";; "xz"|"pxz") TAR_SUFFIX=".xz";;
esac esac
# Check git-dir # Check git-dir
@ -142,18 +142,25 @@ fi
# Create tarball # Create tarball
echo "Package name: $package" echo "Package name: $package"
if [ ! -e $TARBALL_DIR/$package.tar.$TAR_SUFFIX ]; then if [ ! -e $TARBALL_DIR/$package.tar$TAR_SUFFIX ]; then
echo "Creating tarball in $TARBALL_DIR." echo "Creating tarball in $TARBALL_DIR."
echo "# TDE SCM module information" > .tdescminfo echo "# TDE SCM module information" > .tdescminfo
echo "Name: $MODULE" >> .tdescminfo echo "Name: $MODULE" >> .tdescminfo
echo "Revision: $branch-$(git rev-parse HEAD)" >> .tdescminfo echo "Revision: $branch-$(git rev-parse HEAD)" >> .tdescminfo
git log -1 --pretty=format:"DateTime: %cd%n" --date=format:"%m/%d/%Y %H:%M" >> .tdescminfo git log -1 --pretty=format:"DateTime: %cd%n" --date=format:"%m/%d/%Y %H:%M" >> .tdescminfo
trap "rm $TARBALL_DIR/tar-$$; rm .tdescminfo; exit 1" INT trap "rm $TARBALL_DIR/tar-$$; rm .tdescminfo; exit 1" INT
tar c --owner=root --group=users --exclude .git --exclude .gitmodules --transform "s|^\.\(/\|$\)|$package\1|" ./ | \ find ./ -print0 | LC_ALL=C sort -z | \
tar c --no-recursion --null -T - \
--mtime "@$(git log -1 --pretty=format:"%ct")" \
--owner=root --group=users --exclude .git --exclude .gitmodules \
--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
--transform "s|^\.\(/\|$\)|$package\1|" ./ | \
$COMPRESS -9 >$TARBALL_DIR/tar-$$ && \ $COMPRESS -9 >$TARBALL_DIR/tar-$$ && \
mv $TARBALL_DIR/tar-$$ $TARBALL_DIR/$package.tar.$TAR_SUFFIX || \ mv $TARBALL_DIR/tar-$$ $TARBALL_DIR/$package.tar$TAR_SUFFIX || \
rm $TARBALL_DIR/tar-$$ rm $TARBALL_DIR/tar-$$
rm .tdescminfo rm .tdescminfo
[ -f $TARBALL_DIR/$package.tar$TAR_SUFFIX ] && \
touch -d "@$(git log -1 --pretty=format:"%ct")" $TARBALL_DIR/$package.tar$TAR_SUFFIX
else else
echo "Unchanged tarball in $TARBALL_DIR." echo "Unchanged tarball in $TARBALL_DIR."
exit 2 exit 2

Loading…
Cancel
Save