#!/bin/bash

VERSION=$1

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

echo "Downloading just-$VERSION..."

wget --content-disposition "https://github.com/casey/just/archive/refs/tags/$VERSION.tar.gz"

tar xf just-$VERSION.tar.gz

tar cf just-$VERSION.tar just-$VERSION

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

tar cf cargo-just-$VERSION.tar cargo-just-$VERSION

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

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