#!/bin/bash

VERSION=$1

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

echo "Downloading delta-$VERSION..."

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

tar xf delta-$VERSION.tar.gz

tar cf delta-$VERSION.tar delta-$VERSION

cd delta-$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
exclude-crate-paths = [
  { name = "onig_sys", exclude = "oniguruma" },
  { name = "libz-sys", exclude = "src/zlib" },
  { name = "libz-sys", exclude = "src/zlib-ng" },
]
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-delta-$VERSION
cd ..

tar cf cargo-delta-$VERSION.tar cargo-delta-$VERSION

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

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