72be67
#! /bin/bash -ex
72be67
72be67
# Download a release of Python (if missing) and remove .exe files from it
72be67
72be67
version=$1
72be67
72be67
if [ -z "${version}" ]; then
72be67
    echo "Usage: $0 VERSION" >& 2
72be67
    echo "" >& 2
72be67
    echo "example: $0 2.7.15" >& 2
72be67
    exit 1
72be67
fi
72be67
72be67
versionedname=Python-${version}
72be67
orig_archive=${versionedname}.tar.xz
72be67
new_archive=${versionedname}-noexe.tar.xz
72be67
72be67
if [ ! -e ${orig_archive} ]; then
72be67
    wget -N https://www.python.org/ftp/python/${version}/${orig_archive}
72be67
fi
72be67
72be67
deleted_names=$(tar --list -Jf ${orig_archive} | grep '\.exe$')
72be67
72be67
# tar --delete does not operate on compressed archives, so do
72be67
# xz compression/decompression explicitly
72be67
xz --decompress --stdout ${orig_archive} | \
72be67
    tar --delete -v ${deleted_names} | \
72be67
    xz --compress --stdout -3 -T0 > ${new_archive}