#!/bin/bash

set -e
set -u
set -o pipefail

VERSION=$(./version | sed 's/-.*//')
TMPFILE=$(mktemp --suffix='.zip')
ARCHIVE="https://gitlab.com/box-stacker/box-stacker/-/archive"

curl -s \
    "${ARCHIVE}/${VERSION}/box-stacker-${VERSION}.zip" \
    -o "${TMPFILE}"

unzip -q "${TMPFILE}"
rm -rf "cordova/www"
mv "box-stacker-${VERSION}/public" "cordova/www"
mkdir -p lib-src
mv cordova/www/lib/phaser.js cordova/www/lib/planck-with-testbed.js lib-src/
rm -rf "box-stacker-${VERSION}/"

# Remove popularity stats for F-Droid. This is re-added when we do the
# Play Store build.
./disable-stats
