#!/bin/bash

VERSION=$1

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

echo "Downloading harper-$VERSION..."

wget --content-disposition "https://github.com/Automattic/harper/archive/refs/tags/v$VERSION.tar.gz"

tar xf harper-$VERSION.tar.gz

tar cf harper-$VERSION.tar harper-$VERSION

cd harper-$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-harper-$VERSION
cd ..

tar cf cargo-harper-$VERSION.tar cargo-harper-$VERSION

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

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