80 lines
3.1 KiB
Bash
Executable File
80 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
||
# Startet das Habegger Loader Game auf macOS und Linux.
|
||
#
|
||
# Beim ersten Start wird eine lokale virtuelle Umgebung (.venv) angelegt und
|
||
# requirements.txt installiert. Ändert sich requirements.txt oder das Python,
|
||
# wird neu installiert bzw. die Umgebung neu gebaut. Alles Weitere siehe
|
||
# MAC-START.md.
|
||
#
|
||
# ./run.sh # Fenster
|
||
# ./run.sh --fullscreen # Vollbild (Eventbetrieb)
|
||
# ./run.sh --smoke 10 # Selbsttest ohne Eingabegeräte
|
||
# PYTHON=python3.12 ./run.sh # bestimmtes Python erzwingen
|
||
set -euo pipefail
|
||
cd "$(dirname "$0")"
|
||
|
||
VENV=".venv"
|
||
REQ_STAMP="$VENV/.requirements.sha256"
|
||
PY_STAMP="$VENV/.python-version"
|
||
|
||
# --------------------------------------------------------------------------
|
||
# 1. Passendes Python finden (neueste zuerst, 3.12 ist die sichere Wahl für
|
||
# pygame-Wheels; das alte python3 aus den Xcode-Tools bleibt aussen vor)
|
||
# --------------------------------------------------------------------------
|
||
if [ -z "${PYTHON:-}" ]; then
|
||
for candidate in python3.12 python3.13 python3.11 python3.10 python3.9 python3; do
|
||
if command -v "$candidate" >/dev/null 2>&1; then
|
||
PYTHON="$candidate"
|
||
break
|
||
fi
|
||
done
|
||
fi
|
||
if [ -z "${PYTHON:-}" ]; then
|
||
echo "✗ Kein Python gefunden."
|
||
echo " Installiere Python 3.12: brew install python@3.12"
|
||
echo " (Details siehe MAC-START.md)"
|
||
exit 1
|
||
fi
|
||
PY_VERSION="$("$PYTHON" -V 2>&1)"
|
||
|
||
# --------------------------------------------------------------------------
|
||
# 2. Virtuelle Umgebung anlegen bzw. erneuern
|
||
# --------------------------------------------------------------------------
|
||
if [ -d "$VENV" ] && [ -f "$PY_STAMP" ] && [ "$(cat "$PY_STAMP")" != "$PY_VERSION" ]; then
|
||
echo "→ Python hat sich geändert ($(cat "$PY_STAMP") → $PY_VERSION) – .venv wird neu angelegt"
|
||
rm -rf "$VENV"
|
||
fi
|
||
|
||
if [ ! -x "$VENV/bin/python" ]; then
|
||
echo "→ Lege virtuelle Umgebung an ($PY_VERSION)"
|
||
"$PYTHON" -m venv "$VENV"
|
||
fi
|
||
echo "$PY_VERSION" >"$PY_STAMP"
|
||
|
||
if ! "$VENV/bin/python" -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 9) else 1)'; then
|
||
echo "✗ Python 3.9 oder neuer wird benötigt (gefunden: $PY_VERSION)"
|
||
echo " Tipp: brew install python@3.12, danach: rm -rf .venv"
|
||
exit 1
|
||
fi
|
||
|
||
# --------------------------------------------------------------------------
|
||
# 3. Abhängigkeiten installieren (nur wenn sich requirements.txt geändert hat)
|
||
# --------------------------------------------------------------------------
|
||
if command -v shasum >/dev/null 2>&1; then
|
||
REQ_HASH="$(shasum -a 256 requirements.txt | cut -d' ' -f1)"
|
||
else
|
||
REQ_HASH="$(sha256sum requirements.txt | cut -d' ' -f1)"
|
||
fi
|
||
|
||
if [ ! -f "$REQ_STAMP" ] || [ "$(cat "$REQ_STAMP")" != "$REQ_HASH" ]; then
|
||
echo "→ Installiere Abhängigkeiten aus requirements.txt"
|
||
"$VENV/bin/python" -m pip install --quiet --upgrade pip
|
||
"$VENV/bin/python" -m pip install --quiet -r requirements.txt
|
||
echo "$REQ_HASH" >"$REQ_STAMP"
|
||
fi
|
||
|
||
# --------------------------------------------------------------------------
|
||
# 4. Spiel starten (alle Argumente werden weitergegeben)
|
||
# --------------------------------------------------------------------------
|
||
exec "$VENV/bin/python" main.py "$@"
|