Files
2026-10-19 18:19:14 -07:00

40 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Fetches the engine release engine.json pins into <dir> (default .engine/) and refuses a bundle whose
# engine.json is not the pin:
# <dir>/YGOLegacy.Engine.dll the C# binding (ygol-engine-binding.zip)
# <dir>/linux-x64/libygol-engine.so ygol-engine-linux-x64.tar.gz
# <dir>/win-x64/ygol-engine.dll ygol-engine-win64.zip
# Needs curl, jq, tar, unzip.
set -euo pipefail
repo=$(cd "$(dirname "$0")/.." && pwd)
out=${1:-$repo/.engine}
releases=${ENGINE_RELEASES:-https://gitea.dev.blueoceanswim.com/donny/yugioh-legacy-engine/releases/download}
pin=$repo/engine.json
version=$(jq -r .version "$pin")
[ "$(jq -r .binding "$pin")" = "$version" ] || { echo "the pin's binding $(jq -r .binding "$pin") is not its version $version" >&2; exit 1; }
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
for asset in ygol-engine-linux-x64.tar.gz ygol-engine-win64.zip ygol-engine-binding.zip; do
curl -fsSL -o "$tmp/$asset" "$releases/$version/$asset"
done
mkdir -p "$tmp/linux" "$tmp/win"
tar xzf "$tmp/ygol-engine-linux-x64.tar.gz" -C "$tmp/linux" libygol-engine.so engine.json
unzip -q "$tmp/ygol-engine-win64.zip" ygol-engine.dll engine.json -d "$tmp/win"
unzip -q "$tmp/ygol-engine-binding.zip" YGOLegacy.Engine.dll -d "$tmp"
for bundle in linux win; do
# exports is per platform; everything else must be the pin's
got=$(jq -S 'del(.exports)' "$tmp/$bundle/engine.json")
want=$(jq -S 'del(.exports)' "$pin")
[ "$got" = "$want" ] || { echo "the $version $bundle bundle's engine.json differs from the pin:" >&2; cat "$tmp/$bundle/engine.json" >&2; exit 1; }
done
[ "$(jq -S . "$tmp/linux/engine.json")" = "$(jq -S . "$pin")" ] \
|| { echo "the pin is the Linux bundle's engine.json, verbatim; it differs:" >&2; cat "$tmp/linux/engine.json" >&2; exit 1; }
mkdir -p "$out/linux-x64" "$out/win-x64"
cp "$tmp/YGOLegacy.Engine.dll" "$out/"
cp "$tmp/linux/libygol-engine.so" "$out/linux-x64/"
cp "$tmp/win/ygol-engine.dll" "$out/win-x64/"
cp "$pin" "$out/engine.json"
echo "ygol-engine $version -> $out"