#!/bin/bash

VERSION=$1

rm -rf aardvark-dns-*.tar.?z cargo-aardvark-dns*

echo "Downloading aardvark-dns-$VERSION..."

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

tar xf aardvark-dns-$VERSION.tar.gz

tar cf aardvark-dns-$VERSION.tar aardvark-dns-$VERSION

cd aardvark-dns-$VERSION

  sed -i '/\[package.metadata.vendor-filter\]/,+5d' 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
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-aardvark-dns-$VERSION
cd ..

tar cf cargo-aardvark-dns-$VERSION.tar cargo-aardvark-dns-$VERSION

plzip -9 cargo-aardvark-dns-$VERSION.tar
plzip -9 aardvark-dns-$VERSION.tar

rm -rf aardvark-dns-$VERSION
rm -rf cargo-aardvark-dns-$VERSION
rm -f aardvark-dns-$VERSION.tar.gz
