#!/bin/bash

VERSION=$1

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

echo "Downloading zoxide-$VERSION..."

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

tar xf zoxide-$VERSION.tar.gz

tar cf zoxide-$VERSION.tar zoxide-$VERSION

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

tar cf cargo-zoxide-$VERSION.tar cargo-zoxide-$VERSION

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

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