#!/usr/bin/env bash

cd "$(dirname "$(readlink -f "$0")")/.." || error "Failed to switch to correct directory"

./gradlew packageReleaseUberJarForCurrentOS

flatpak-builder --ccache --force-clean  --repo=flatpak/_repo ./flatpak/_build ./flatpak/ch.dissem.YAEP.yml

if [ "$1" = "bundle" ] || [ "$1" = "install" ]; then
  echo "Build is done, creating bundle now. This may take a while..."
  flatpak build-bundle flatpak/_repo "flatpak/YAEP-$(arch)-1.0.0.flatpak" ch.dissem.YAEP
fi

if [ "$1" = "install" ]; then
  flatpak install "flatpak/YAEP-$(arch)-1.0.0.flatpak"
fi
