#!/bin/bash
# The source to share beside the friends' game folder: dist/zone4-wine-source-<commit>.zip.
#   deploy/package-source
# Everything committed (git archive HEAD: the server, the launcher, the patch scripts, these deploy
# scripts, the docs), plus translate/, the English translation's scripts and tables from the Windows
# laptop's handover, which made the English files MANIFEST.txt names. Uncommitted changes are left
# out, so commit first.
set -euo pipefail
ROOT=$(cd "$(dirname "$0")/.." && pwd)
COMMIT=$(git -C "$ROOT" rev-parse --short HEAD)
[ -z "$(git -C "$ROOT" status --porcelain)" ] || echo "note: uncommitted changes are not in it (git status)"
NAME="zone4-wine-source-$COMMIT"
TMP=$(mktemp -d "$ROOT/dist/.source.XXXXXX")
trap 'rm -rf "$TMP"' EXIT
git -C "$ROOT" archive --prefix="$NAME/" HEAD | tar -x -C "$TMP"
rsync -a --exclude .venv --exclude __pycache__ "$ROOT/inbox/unpacked/zone4-589-handover/translate/" "$TMP/$NAME/translate/"
rm -f "$ROOT/dist/$NAME.zip"
(cd "$TMP" && zip -qr -X "$ROOT/dist/$NAME.zip" "$NAME")
echo "$ROOT/dist/$NAME.zip ($(du -h "$ROOT/dist/$NAME.zip" | cut -f1))"
