#!/bin/bash

VERSION=$1

rm -rf maturin-*.tar.?z cargo-maturin*

echo "Downloading maturin-$VERSION..."

wget "https://pypi.io/packages/source/m/maturin/maturin-$VERSION.tar.gz"

tar xf maturin-$VERSION.tar.gz

tar cf maturin-$VERSION.tar maturin-$VERSION

cd maturin-$VERSION/

# Configure cargo-vendor-filterer
  cat << EOF >> Cargo.toml
[package.metadata.vendor-filter]
platforms = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
all-features = true
EOF


  if ! [ -f /usr/bin/cargo-vendor-filterer ]; then
    echo "WARNING: Creating unfiltered vendor libs tarball!"
    cargo vendor
  else
    cargo vendor-filterer
  fi

  mv vendor ../cargo-maturin-$VERSION
cd ../

tar cf cargo-maturin-$VERSION.tar cargo-maturin-$VERSION

plzip -9 cargo-maturin-$VERSION.tar
plzip -9 maturin-$VERSION.tar

rm -rf maturin-$VERSION
rm -rf cargo-maturin-$VERSION
rm -f maturin-$VERSION.tar.gz
