#!/bin/bash

VERSION=$1

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

echo "Downloading xh-$VERSION..."

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

tar xf xh-$VERSION.tar.gz

tar cf xh-$VERSION.tar xh-$VERSION

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

tar cf cargo-xh-$VERSION.tar cargo-xh-$VERSION

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

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