#!/bin/bash

VERSION=$1

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

echo "Downloading netavark-$VERSION..."

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

tar xf netavark-$VERSION.tar.gz

tar cf netavark-$VERSION.tar netavark-$VERSION

cd netavark-$VERSION

  sed -i '/\[package.metadata.vendor-filter\]/,+2d' Cargo.toml

  # 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
tier = "2"
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-netavark-$VERSION
cd ..

tar cf cargo-netavark-$VERSION.tar cargo-netavark-$VERSION

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

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