#!/bin/bash

VERSION=$1

rm -rf nextcloud-notify-push-*.tar.?z cargo-nextcloud-notify-push* notify_push-*.tar.?z

echo "Downloading nextcloud-notify-push-$VERSION..."

wget "https://github.com/nextcloud/notify_push/archive/v$VERSION/notify_push-$VERSION.tar.gz"

tar xf notify_push-$VERSION.tar.gz

mv notify_push-$VERSION nextcloud-notify-push-$VERSION
tar cf nextcloud-notify-push-$VERSION.tar nextcloud-notify-push-$VERSION

cd nextcloud-notify-push-$VERSION
  if ! [ -f /usr/bin/cargo-vendor-filterer ]; then
    echo "WARNING: Creating unfiltered vendor libs tarball!"
    cargo vendor
  else
    cargo vendor-filterer --platform="x86_64-unknown-linux-gnu" --platform="i686-unknown-linux-gnu"
  fi

  mv vendor ../cargo-nextcloud-notify-push-$VERSION
cd ..

tar cf cargo-nextcloud-notify-push-$VERSION.tar cargo-nextcloud-notify-push-$VERSION

plzip -9 cargo-nextcloud-notify-push-$VERSION.tar
plzip -9 nextcloud-notify-push-$VERSION.tar

rm -rf nextcloud-notify-push-$VERSION
rm -rf cargo-nextcloud-notify-push-$VERSION
rm -f notify_push-$VERSION.tar.gz
