#!/bin/bash

VERSION=$1

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

echo "Downloading fd-$VERSION..."

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

tar xf fd-$VERSION.tar.gz

tar cf fd-$VERSION.tar fd-$VERSION

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

tar cf cargo-fd-$VERSION.tar cargo-fd-$VERSION

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

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