#!/usr/bin/env bash # R1: exports the Linux x86_64 game, which is also the dedicated server, with the # official Godot export templates and packs them into build/dist/tidewall--linux-x86_64.tar.gz. # # tools/dist.sh # # The templates come from tools/godot/ (git-ignored), checked against # tools/engine.sha512 before use, and are installed into the repo-local engine data # (.godot-home/), never the user's home. The version is project.godot's # application/config/version; the commit is written into the export as # build_commit.txt, which BuildInfo reads. # # The package holds: # tidewall.x86_64 the engine (the official release template) # tidewall.pck the game # tidewall-server runs the same game headless as a dedicated server, with # clean SIGTERM handling # server.cfg an example server configuration # LICENSE, LICENSE-ASSETS, README.md, PROVENANCE.md, VERSION set -euo pipefail repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$repo" engine_version="$(cut -d. -f1-3 tools/engine.version)" # 4.7.2 engine_tag="${engine_version}.$(cut -d. -f4 tools/engine.version)" # 4.7.2.stable templates_zip="tools/godot/Godot_v${engine_version}-stable_export_templates.tpz" templates_dir=".godot-home/data/godot/export_templates/$engine_tag" version="$(sed -n 's/^config\/version="\(.*\)"$/\1/p' project.godot)" [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "dist FAIL: no version in project.godot" >&2; exit 1; } commit="$(git rev-parse --short=12 HEAD)" if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then commit="$commit-dirty" fi name="tidewall-$version-linux-x86_64" out="build/dist" stage="$out/stage" package="$out/$name" tools/godot.sh --verify >/dev/null # The official templates, checked, then only the Linux x86_64 ones installed. if [[ ! -f "$templates_dir/linux_release.x86_64" || "$(cat "$templates_dir/.verified" 2>/dev/null)" != "$(grep 'export_templates\.tpz$' tools/engine.sha512 | cut -d' ' -f1)" ]]; then [[ -f "$templates_zip" ]] || { echo "dist FAIL: missing $templates_zip (see tools/godot.sh)" >&2; exit 1; } echo "dist: checking the export templates against tools/engine.sha512" >&2 grep 'export_templates\.tpz$' tools/engine.sha512 | sha512sum --check --quiet mkdir -p "$templates_dir" unzip -q -o -j "$templates_zip" templates/linux_release.x86_64 templates/linux_debug.x86_64 templates/version.txt -d "$templates_dir" [[ "$(cat "$templates_dir/version.txt")" == "$engine_tag" ]] || { echo "dist FAIL: templates are for $(cat "$templates_dir/version.txt"), not $engine_tag" >&2; exit 1; } grep 'export_templates\.tpz$' tools/engine.sha512 | cut -d' ' -f1 >"$templates_dir/.verified" fi rm -rf "$stage" "$package" "$out/$name.tar.gz" "$out/$name.tar.gz.sha256" mkdir -p "$stage" "$package" trap 'rm -f "$repo/build_commit.txt"' EXIT printf '%s\n' "$commit" >build_commit.txt tools/godot.sh --import --quit >/dev/null 2>&1 || true export_preset() { local preset="$1" target="$2" raw echo "dist: exporting '$preset'" >&2 if ! raw="$(tools/godot.sh --export-release "$preset" "$repo/$target" 2>&1)"; then echo "dist FAIL: exporting '$preset' failed" >&2 tail -n 20 <<<"$raw" >&2 exit 1 fi if grep -E '^(ERROR|SCRIPT ERROR)' <<<"$raw" >&2; then echo "dist FAIL: errors while exporting '$preset'" >&2 exit 1 fi [[ -f "$repo/$target" ]] || { echo "dist FAIL: '$preset' wrote no $target" >&2; exit 1; } } export_preset "Linux" "$stage/tidewall.x86_64" rm -f build_commit.txt # The exported binary must be the verified official template, unchanged. cmp -s "$stage/tidewall.x86_64" "$templates_dir/linux_release.x86_64" || { echo "dist FAIL: the exported binary isn't the release template" >&2; exit 1; } install -m 0755 "$stage/tidewall.x86_64" "$package/tidewall.x86_64" install -m 0644 "$stage/tidewall.pck" "$package/tidewall.pck" install -m 0755 packaging/dist/tidewall-server "$package/tidewall-server" install -m 0644 LICENSE LICENSE-ASSETS "$package/" install -m 0644 packaging/server/server.cfg "$package/server.cfg" install -m 0644 packaging/dist/README.md "$package/README.md" install -m 0644 assets/PROVENANCE.md "$package/PROVENANCE.md" printf 'Tidewall %s\ncommit %s\nengine Godot %s\n' "$version" "$commit" "$(cat tools/engine.version)" >"$package/VERSION" # Reproducible-ish archive: fixed owner, sorted names, mtimes from the commit. stamp="$(git log -1 --format=%ct)" tar --sort=name --owner=0 --group=0 --numeric-owner --mtime="@$stamp" \ -C "$out" -czf "$out/$name.tar.gz" "$name" (cd "$out" && sha256sum "$name.tar.gz" >"$name.tar.gz.sha256") rm -rf "$stage" echo "dist: $out/$name.tar.gz ($(du -h "$out/$name.tar.gz" | cut -f1)), commit $commit" tar -tzvf "$out/$name.tar.gz" | awk '{print " " $3 "\t" $6}'