Files

114 lines
5.6 KiB
Bash

#!/bin/bash
# Standalone macOS exporter for a Godot 4.5 project.
# Install this file at <project>/build-tools/Build-Mac.sh.
set -euo pipefail
project_root=$(cd "$(dirname "$0")/.." && pwd)
output_dir="$project_root/dist/macos"
app_path="$output_dir/BLOCKLINE.app"
archive_path="$output_dir/BLOCKLINE.zip"
work_dir=""
templates_work_dir=""
cleanup() {
[[ -n "$work_dir" && -d "$work_dir" ]] && /bin/rm -rf "$work_dir"
[[ -n "$templates_work_dir" && -d "$templates_work_dir" ]] && /bin/rm -rf "$templates_work_dir"
}
trap cleanup EXIT
fail() { echo "FEHLER: $*" >&2; exit 1; }
install_godot() {
local engine_dir archive archive_hash expected_hash
engine_dir="$project_root/tools/godot"
archive="$engine_dir/Godot_v4.5-stable_macos.universal.zip"
expected_hash="59d195d1876210fa0f8c36bc10b147339fc8e076c684b74111533992f1a1dcdc0f760461f4cadad627e5b11e74468b54b9355fc6ea0c507c52533dfa7aa0c617"
/bin/mkdir -p "$engine_dir"
if [[ ! -f "$archive" ]]; then
echo "Godot 4.5 fehlt; lade die offizielle Universal-Engine einmalig …" >&2
/usr/bin/curl --fail --location --retry 3 --connect-timeout 20 --max-time 600 \
--proto '=https' --tlsv1.2 \
'https://github.com/godotengine/godot-builds/releases/download/4.5-stable/Godot_v4.5-stable_macos.universal.zip' \
-o "$archive" || fail "Godot konnte nicht heruntergeladen werden."
fi
archive_hash=$(/usr/bin/shasum -a 512 "$archive" | /usr/bin/awk '{print $1}')
[[ "$archive_hash" == "$expected_hash" ]] || fail "Godot-Prüfsumme ungültig: $archive"
work_dir=$(/usr/bin/mktemp -d "${TMPDIR:-/tmp}/godot-engine.XXXXXX")
/usr/bin/ditto -x -k "$archive" "$work_dir"
[[ -x "$work_dir/Godot.app/Contents/MacOS/Godot" ]] || fail "Das Godot-Archiv enthält keine macOS-Engine."
/bin/rm -rf "$engine_dir/Godot.app"
/bin/mv "$work_dir/Godot.app" "$engine_dir/Godot.app"
/bin/rm -rf "$work_dir"
work_dir=""
}
find_godot() {
local candidate
if [[ -n "${GODOT_BIN:-}" ]]; then
[[ -x "$GODOT_BIN" ]] || fail "GODOT_BIN ist nicht ausführbar: $GODOT_BIN"
printf '%s\n' "$GODOT_BIN"; return
fi
for candidate in "$project_root/tools/godot/Godot.app/Contents/MacOS/Godot" "/Applications/Godot.app/Contents/MacOS/Godot"; do
[[ -x "$candidate" ]] && { printf '%s\n' "$candidate"; return; }
done
if command -v godot >/dev/null 2>&1; then command -v godot; return; fi
install_godot
printf '%s\n' "$project_root/tools/godot/Godot.app/Contents/MacOS/Godot"
}
ensure_templates() {
local target archive
target="$HOME/Library/Application Support/Godot/export_templates/4.5.stable"
[[ -f "$target/macos.zip" ]] && return
echo "Godot-Exportvorlagen fehlen; lade sie einmalig (ca. 700 MB) …"
templates_work_dir=$(/usr/bin/mktemp -d "${TMPDIR:-/tmp}/godot-templates.XXXXXX")
archive="$templates_work_dir/templates.tpz"
/usr/bin/curl --fail --location --retry 3 --connect-timeout 20 --max-time 1800 \
--proto '=https' --tlsv1.2 \
'https://github.com/godotengine/godot/releases/download/4.5-stable/Godot_v4.5-stable_export_templates.tpz' \
-o "$archive" || fail "Exportvorlagen konnten nicht heruntergeladen werden."
/usr/bin/ditto -x -k "$archive" "$templates_work_dir/unpacked"
[[ -f "$templates_work_dir/unpacked/templates/macos.zip" ]] || fail "macOS-Exportvorlage fehlt im Archiv."
/bin/mkdir -p "$target"
/usr/bin/ditto "$templates_work_dir/unpacked/templates/" "$target/"
}
godot=$(find_godot)
version=$(/usr/bin/env "$godot" --version 2>/dev/null || true)
[[ "$version" == 4.5* ]] || fail "Godot 4.5 erforderlich, gefunden: ${version:-unbekannt}"
[[ -f "$project_root/project.godot" && -f "$project_root/export_presets.cfg" ]] || fail "project.godot oder export_presets.cfg fehlt."
ensure_templates
mkdir -p "$output_dir" "$project_root/logs"
echo "01 / Godot-Import prüfen …"
/usr/bin/env "$godot" --headless --path "$project_root" --editor --import --quit --log-file "$project_root/logs/macos-import.log"
! /usr/bin/grep -q 'SCRIPT ERROR' "$project_root/logs/macos-import.log" || fail "SCRIPT ERROR im Import-Log."
echo "02 / Universelle App exportieren …"
/bin/rm -rf "$app_path"; /bin/rm -f "$archive_path"
work_dir=$(/usr/bin/mktemp -d "${TMPDIR:-/tmp}/macos-export.XXXXXX")
export_archive="$work_dir/export.zip"
/usr/bin/env "$godot" --headless --path "$project_root" --export-release macOS "$export_archive"
/usr/bin/unzip -t "$export_archive" >/dev/null
/usr/bin/ditto -x -k "$export_archive" "$work_dir/unpacked"
exported_app=$(/usr/bin/find "$work_dir/unpacked" -maxdepth 1 -type d -name '*.app' -print -quit)
[[ -n "$exported_app" ]] || fail "Godot-Export enthält kein .app-Bundle."
/bin/mv "$exported_app" "$app_path"
echo "03 / Bundle prüfen …"
plist="$app_path/Contents/Info.plist"
[[ -f "$plist" ]] || fail "Info.plist fehlt."
identifier=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$plist")
[[ "$identifier" == "com.blockline.relaydistrict" ]] || fail "Unerwartete Bundle-ID: $identifier"
executable=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleExecutable' "$plist")
binary="$app_path/Contents/MacOS/$executable"
[[ -x "$binary" ]] || fail "Startdatei fehlt: $executable"
architectures=$(/usr/bin/lipo -archs "$binary")
[[ " $architectures " == *" x86_64 "* && " $architectures " == *" arm64 "* ]] || fail "Nicht universal: $architectures"
/usr/bin/codesign --verify --deep --strict --verbose=2 "$app_path"
/usr/bin/find "$app_path/Contents/Resources" -type f -name '*.pck' -size +1024c -print -quit | /usr/bin/grep -q . || fail "Spieldaten fehlen."
/usr/bin/ditto -c -k --sequesterRsrc --keepParent "$app_path" "$archive_path"
/usr/bin/unzip -t "$archive_path" >/dev/null
echo "Fertig: $app_path"
echo "Weitergeben: $archive_path"