#!/bin/bash

VERSION=$1

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

echo "Downloading lsd-$VERSION..."

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

tar xf lsd-$VERSION.tar.gz

tar cf lsd-$VERSION.tar lsd-$VERSION

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

tar cf cargo-lsd-$VERSION.tar cargo-lsd-$VERSION

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

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