#!/bin/bash

VERSION=$1

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

echo "Downloading typos-$VERSION..."

wget --content-disposition "https://github.com/crate-ci/typos/archive/refs/tags/v$VERSION.tar.gz"

tar xf typos-$VERSION.tar.gz

tar cf typos-$VERSION.tar typos-$VERSION

cd typos-$VERSION

  # Configure cargo-vendor-filterer
  cat << EOF >> Cargo.toml
[workspace.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-typos-$VERSION
cd ..

tar cf cargo-typos-$VERSION.tar cargo-typos-$VERSION

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

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