913b70
#!/bin/sh
913b70
set -o errexit
913b70
set -o nounset
913b70
913b70
if [ "$#" != '1' ]
913b70
then
913b70
	cat 1>&2 <
913b70
Usage: $0 VERSION
913b70
913b70
Downloads the requested version and creates a filtered source tarball.
913b70
EOF
913b70
	exit 1
913b70
fi
913b70
913b70
VERSION="${1}"
913b70
OUTDIR="${PWD}"
913b70
TMPDIR="$(mktemp -d)"
913b70
trap "rm -rf '${TMPDIR}'" INT TERM EXIT
913b70
913b70
cd "${TMPDIR}"
913b70
URL="$(rpm -E "%{pypi_source chardet ${VERSION}}")"
913b70
echo "--> Downloading: ${URL}" 1>&2
913b70
curl -L -O "${URL}"
913b70
913b70
ARCHIVE="$(find . -mindepth 1 -maxdepth 1 -type f -name '*.tar.gz' -print -quit)"
913b70
echo "--> Extracting: $(basename "${ARCHIVE}")" 1>&2
913b70
tar -xzf "${ARCHIVE}"
913b70
echo '--> Removing tests due to licensing issues' 1>&2
913b70
TARDIR="$(basename "${ARCHIVE}" '.tar.gz')"
913b70
MTIME="$(stat -c '%Y' "${TARDIR}")"
913b70
rm -rvf "${TARDIR}/tests/"
913b70
# Restore the original mtime even though we modified the base directory by
913b70
# removing the tests.
913b70
touch -d @"${MTIME}" "${TARDIR}"
913b70
FILTERED="$(basename "${ARCHIVE}" .tar.gz)-filtered.tar.zst"
913b70
echo "--> Re-archiving: ${FILTERED}" 1>&2
913b70
# https://www.gnu.org/software/tar/manual/html_section/Reproducibility.html
913b70
TZ=UTC LC_ALL=C tar \
913b70
    --create --verbose \
913b70
    --sort=name \
913b70
    --format=posix \
913b70
    --numeric-owner --owner=0 --group=0 \
913b70
    --mode=go+u,go-w \
913b70
    --pax-option='delete=atime,delete=ctime' \
913b70
    "${TARDIR}/" |
913b70
  zstdmt --ultra -22 > "${FILTERED}"
913b70
mv -v "${FILTERED}" "${OUTDIR}"
913b70
echo 'Done.' 1>&2