#!/bin/bash

VERSION=$1

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

echo "Downloading zizmor-$VERSION..."

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

tar xf zizmor-$VERSION.tar.gz

tar cf zizmor-$VERSION.tar zizmor-$VERSION

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

tar cf cargo-zizmor-$VERSION.tar cargo-zizmor-$VERSION

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

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