#!/bin/bash

VERSION=$1

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

echo "Downloading atuin-$VERSION..."

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

tar xf atuin-$VERSION.tar.gz

tar cf atuin-$VERSION.tar atuin-$VERSION

cd atuin-$VERSION

  # Configure cargo-vendor-filterer
  cat << EOF >> Cargo.toml
[workspace.metadata.vendor-filter]
platforms = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
all-features = true
exclude-crate-paths = [
  { name = "libsodium-sys", exclude = "libsodium" },
]
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-atuin-$VERSION
cd ..

tar cf cargo-atuin-$VERSION.tar cargo-atuin-$VERSION

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

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