yahtzee-py/build_all.sh

103 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
APP_NAME="Yahtzee"
MAIN_FILE="main.py"
RES_DIR="ressources"
echo "===================================================="
echo " 🦇 Starte Multi-Plattform Build für $APP_NAME"
echo "===================================================="
# ----------------------------------------------------
# TEIL 1: LINUX EXECUTABLE BAUEN
# ----------------------------------------------------
echo ""
echo "---> [1/2] Baue Linux Executable..."
# Prüfen, ob eine virtuelle Umgebung (.venv / venv) existiert, sonst System-pip nutzen
if [ -d ".venv" ]; then
LINUX_PY=".venv/bin/python3"
elif [ -d "venv" ]; then
LINUX_PY="venv/bin/python3"
else
LINUX_PY="python3"
fi
# Sicherstellen, dass PyInstaller und Pillow unter Linux installiert sind
$LINUX_PY -m pip install --upgrade pillow pyinstaller --break-system-packages 2>/dev/null || $LINUX_PY -m pip install --upgrade pillow pyinstaller
# WICHTIG: Unter Linux wird bei --add-data ein Doppelpunkt (:) als Trennzeichen genutzt!
$LINUX_PY -m PyInstaller \
--noconsole \
--onefile \
--clean \
--distpath "dist/linux" \
--workpath "build/linux" \
--add-data "${RES_DIR}:${RES_DIR}" \
--name "${APP_NAME}_Linux" \
"$MAIN_FILE"
chmod +x "dist/linux/${APP_NAME}_Linux"
echo "✔ Linux-Build fertig: dist/linux/${APP_NAME}_Linux"
# ----------------------------------------------------
# TEIL 2: WINDOWS .EXE BAUEN (VIA WINE)
# ----------------------------------------------------
echo ""
echo "---> [2/2] Baue Windows .exe (via Wine)..."
if ! command -v wine &> /dev/null; then
echo "❌ Fehler: 'wine' ist unter Linux noch nicht installiert!"
echo "Bitte führe erst 'sudo apt update && sudo apt install wine' aus."
exit 1
fi
# Suche nach einer vorhandenen python.exe innerhalb von Wine
WINE_PY=$(find ~/.wine/drive_c -iname "python.exe" 2>/dev/null | grep -i "Python3" | head -n 1 || true)
# Falls Windows-Python noch nicht in Wine installiert ist -> automatisch installieren
if [ -z "$WINE_PY" ]; then
echo "⚙️ Windows-Python wurde in Wine noch nicht gefunden. Installiere Python 3.11.9 automatisch..."
INSTALLER="python-3.11.9-amd64.exe"
if [ ! -f "$INSTALLER" ]; then
wget -O "$INSTALLER" https://www.python.org/ftp/python/3.11.9/python-3.11.9-amd64.exe
fi
wine "$INSTALLER" /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
wineserver -w
rm -f "$INSTALLER"
WINE_PY=$(find ~/.wine/drive_c -iname "python.exe" 2>/dev/null | grep -i "Python3" | head -n 1 || true)
fi
if [ -z "$WINE_PY" ]; then
echo "❌ Konnte python.exe in Wine nicht finden!"
exit 1
fi
echo "✔ Nutze Wine-Python: $WINE_PY"
# Pillow und PyInstaller in Wine-Python installieren
wine "$WINE_PY" -m pip install --upgrade pip pillow pyinstaller
# WICHTIG: Unter Windows/Wine wird bei --add-data ein Semikolon (;) genutzt!
wine "$WINE_PY" -m PyInstaller \
--noconsole \
--onefile \
--clean \
--distpath "dist/windows" \
--workpath "build/windows" \
--add-data "${RES_DIR};${RES_DIR}" \
--name "${APP_NAME}" \
"$MAIN_FILE"
# Aufräumen der temporären .spec Dateien
rm -f "${APP_NAME}.spec" "${APP_NAME}_Linux.spec"
echo ""
echo "===================================================="
echo " ✅ BUILD ERFOLGREICH ABGESCHLOSSEN!"
echo " 🐧 Linux-Version: dist/linux/${APP_NAME}_Linux"
echo " 🪟 Windows-Version: dist/windows/${APP_NAME}.exe"
echo "===================================================="