#!/bin/bash
# Create a second tarball of the autogen'd files in Heimdal.
# It's useful to pregenerate this data before building in mock, because
# GNU autoconf on RHEL 5 is too old to parse the autoconf syntax in Heimdal.
COMMIT=719523251eba1d2635b63f9245005b0a02cdec6d
SHORT_COMMIT=${COMMIT:0:7}
set -e
# Get the tarball
TARBALL=$(ls heimdal-*-$SHORT_COMMIT.tar.gz | tail -1)
# Sanity check that the tarball exists
if [[ ! -f $TARBALL ]]; then
echo could not find a heimdal tarball for git commit $SHORT_COMMIT
exit 1
fi
# Untar, and set aside a "pristine" copy
tar xzf $TARBALL
cp -r heimdal-$COMMIT heimdal-$COMMIT-pristine
# autogen
pushd heimdal-$COMMIT
./autogen.sh
popd
# Get a list of all chagned files from the "pristine" version.
CHANGES=$(diff -qr heimdal-${COMMIT}-pristine heimdal-${COMMIT} \
| sed "s/^Only in heimdal-${COMMIT}//" \
| sed "s/: /\//" \
| sed "s/Files heimdal-${COMMIT}-pristine//" \
| sed "s/and heimdal-${COMMIT}\/.* differ//" \
| sed "s/^\///")
# This tarball will contain only the new autoconf-generated files.
AUTOCONF_TARBALL=heimdal-${SHORT_COMMIT}-autoconf.tar
# (delete the old tarball if it exists.)
rm $AUTOCONF_TARBALL 2>/dev/null || :
# Append each of the files in $CHANGES onto $AUTOCONF_TARBALL.
while read -r line; do
tar -f $AUTOCONF_TARBALL -r heimdal-$COMMIT/$line
done <<< "$CHANGES"
# Compress the autoconf tarball.
gzip -f $AUTOCONF_TARBALL
# We're done.
echo Created ${AUTOCONF_TARBALL}.gz
# Clean up dirs
rm -rf heimdal-$COMMIT heimdal-$COMMIT-pristine