#!/bin/bash # ============================================================================ # PointCab Renamer - Windows Build unter Linux (Wine-Methode) # Version: 4.2.1 # ============================================================================ # # WICHTIG: Wine-basierte Builds sind EXPERIMENTELL und können fehlschlagen! # # BEKANNTE EINSCHRÄNKUNGEN: # - Headless Server (ohne GUI): Python-Installation kann fehlschlagen # - Manche Wine-Versionen haben Kompatibilitätsprobleme # - GUI-basierte Python-Installer benötigen X11/Display # # EMPFOHLENE ALTERNATIVEN: # 1. Windows-PC: build_windows.bat direkt ausführen # 2. GitHub Actions: CI/CD für automatisierte Builds # 3. Dual-Boot/VM: Windows-Build in echter Windows-Umgebung # # ============================================================================ # Farben für Ausgabe RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Konfiguration PYTHON_VERSION="3.10.11" PYTHON_INSTALLER="python-${PYTHON_VERSION}-amd64.exe" PYTHON_URL="https://www.python.org/ftp/python/${PYTHON_VERSION}/${PYTHON_INSTALLER}" WINE_PREFIX="$HOME/.wine_python" # Banner echo -e "${BLUE}" echo "============================================================================" echo " PointCab Renamer - Windows Cross-Compilation (Wine-Methode)" echo " Version 4.2.1 - EXPERIMENTELL" echo "============================================================================" echo -e "${NC}" echo -e "${YELLOW}╔════════════════════════════════════════════════════════════════════╗${NC}" echo -e "${YELLOW}║ WARNUNG: Diese Methode ist EXPERIMENTELL und kann fehlschlagen! ║${NC}" echo -e "${YELLOW}╚════════════════════════════════════════════════════════════════════╝${NC}" echo "" echo "Bekannte Probleme:" echo " • Headless Server ohne X11: Python-Installer kann hängen" echo " • Wine-Kompatibilität variiert je nach Version" echo " • ~500MB Download und 10+ Minuten Installationszeit" echo "" echo "Empfohlene Alternativen:" echo " 1. Windows-PC: build_windows.bat ausführen" echo " 2. GitHub Actions: Automatisierte CI/CD Builds" echo "" read -p "Trotzdem fortfahren? (j/N): " -n 1 -r echo if [[ ! $REPLY =~ ^[Jj]$ ]]; then echo "" echo "Abgebrochen. Alternative Methoden:" echo " • Kopiere das Projekt auf einen Windows-PC" echo " • Führe dort build_windows.bat aus" exit 0 fi echo "" # Arbeitsverzeichnis SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" # Funktion für Fehlerbehandlung fail_with_alternatives() { echo "" echo -e "${RED}╔════════════════════════════════════════════════════════════════════╗${NC}" echo -e "${RED}║ BUILD FEHLGESCHLAGEN ║${NC}" echo -e "${RED}╚════════════════════════════════════════════════════════════════════╝${NC}" echo "" echo -e "${YELLOW}Alternative Methoden:${NC}" echo "" echo " 1. ${GREEN}Windows-PC (EMPFOHLEN):${NC}" echo " - Kopiere das gesamte Projektverzeichnis" echo " - Führe build_windows.bat aus" echo "" echo " 2. ${GREEN}GitHub Actions:${NC}" echo " - Push zu GitHub mit Actions Workflow" echo " - Automatisierter Windows-Build" echo "" echo " 3. ${GREEN}Virtual Machine:${NC}" echo " - Windows-VM mit VirtualBox/VMware" echo " - Shared Folder für Projektdateien" echo "" exit 1 } # Prüfe Wine echo -e "${BLUE}[1/7] Prüfe Wine-Installation...${NC}" if ! command -v wine &> /dev/null; then echo -e "${RED}FEHLER: Wine ist nicht installiert!${NC}" echo "" echo "Installation auf Ubuntu/Debian:" echo " sudo dpkg --add-architecture i386" echo " sudo apt update" echo " sudo apt install wine64 wine32" echo "" echo "Installation auf Fedora:" echo " sudo dnf install wine" echo "" fail_with_alternatives fi WINE_VERSION=$(wine --version 2>/dev/null || echo "unknown") echo -e "${GREEN}✓ Wine installiert: $WINE_VERSION${NC}" # Prüfe auf Display (wichtig für GUI-Installer) echo -e "${BLUE}[2/7] Prüfe Display-Umgebung...${NC}" if [ -z "$DISPLAY" ]; then echo -e "${YELLOW}⚠ Kein DISPLAY gesetzt - Headless-Modus erkannt${NC}" echo "" echo "Python-Installer benötigt möglicherweise X11/GUI." echo "Dies kann in Headless-Umgebungen fehlschlagen." echo "" echo "Optionen:" echo " • Virtuelles Display mit Xvfb (experimentell)" echo " • X11 Forwarding bei SSH (-X Option)" echo " • Desktop-Umgebung verwenden" echo "" # Versuche Xvfb falls verfügbar if command -v Xvfb &> /dev/null; then echo "Xvfb gefunden - starte virtuelles Display..." Xvfb :99 -screen 0 1024x768x24 & XVFB_PID=$! export DISPLAY=:99 sleep 2 echo -e "${GREEN}✓ Virtuelles Display gestartet (:99)${NC}" else echo -e "${YELLOW}Xvfb nicht installiert. Versuche ohne Display...${NC}" echo " Installation: sudo apt install xvfb" fi else echo -e "${GREEN}✓ Display vorhanden: $DISPLAY${NC}" fi # Prüfe Projektdateien echo -e "${BLUE}[3/7] Prüfe Projektdateien...${NC}" if [ ! -f "pointcab_renamer.py" ]; then echo -e "${RED}FEHLER: pointcab_renamer.py nicht gefunden!${NC}" exit 1 fi if [ ! -f "cluster_cleanup.txt" ]; then echo -e "${RED}FEHLER: cluster_cleanup.txt nicht gefunden!${NC}" exit 1 fi echo -e "${GREEN}✓ Projektdateien vorhanden${NC}" # Wine-Prefix initialisieren echo -e "${BLUE}[4/7] Initialisiere Wine-Umgebung...${NC}" export WINEPREFIX="$WINE_PREFIX" export WINEARCH=win64 export WINEDEBUG=-all # Unterdrücke Wine Debug-Meldungen if [ ! -d "$WINE_PREFIX" ]; then echo "Erstelle Wine-Prefix unter: $WINE_PREFIX" echo "Dies kann einige Minuten dauern..." wineboot --init 2>/dev/null || true sleep 5 fi echo -e "${GREEN}✓ Wine-Umgebung bereit${NC}" # Python-Pfade in Wine WINE_PYTHON="$WINE_PREFIX/drive_c/Python310/python.exe" WINE_PIP="$WINE_PREFIX/drive_c/Python310/Scripts/pip.exe" WINE_PYINSTALLER="$WINE_PREFIX/drive_c/Python310/Scripts/pyinstaller.exe" # Python installieren falls nicht vorhanden echo -e "${BLUE}[5/7] Prüfe Windows-Python...${NC}" if [ ! -f "$WINE_PYTHON" ]; then echo "Windows-Python nicht gefunden, installiere..." echo "" # Download Python installer if [ ! -f "/tmp/$PYTHON_INSTALLER" ]; then echo "Lade Python herunter: $PYTHON_URL" echo "Größe: ~28MB" wget -q --show-progress -O "/tmp/$PYTHON_INSTALLER" "$PYTHON_URL" || { echo -e "${RED}FEHLER: Python-Download fehlgeschlagen!${NC}" fail_with_alternatives } fi # Installiere Python echo "" echo "Installiere Python in Wine..." echo "Dies kann 5-10 Minuten dauern..." echo "" # Silent Installation mit Timeout timeout 300 wine "/tmp/$PYTHON_INSTALLER" /quiet InstallAllUsers=0 PrependPath=1 Include_test=0 2>/dev/null || { echo -e "${YELLOW}⚠ Python-Installation möglicherweise fehlgeschlagen oder Timeout${NC}" } sleep 5 # Prüfe Installation if [ ! -f "$WINE_PYTHON" ]; then echo "" echo -e "${RED}FEHLER: Python-Installation fehlgeschlagen!${NC}" echo "" echo "Mögliche Ursachen:" echo " • Headless-Umgebung ohne GUI" echo " • Wine-Kompatibilitätsproblem" echo " • Nicht genug Speicherplatz" echo "" # Cleanup Xvfb falls gestartet [ -n "$XVFB_PID" ] && kill $XVFB_PID 2>/dev/null fail_with_alternatives fi fi echo -e "${GREEN}✓ Windows-Python installiert${NC}" # PyInstaller installieren echo -e "${BLUE}[6/7] Prüfe PyInstaller...${NC}" if [ ! -f "$WINE_PYINSTALLER" ]; then echo "Installiere PyInstaller..." wine "$WINE_PIP" install pyinstaller 2>/dev/null || { echo -e "${RED}FEHLER: PyInstaller-Installation fehlgeschlagen!${NC}" fail_with_alternatives } fi echo -e "${GREEN}✓ PyInstaller installiert${NC}" # Aufräumen echo -e "${BLUE}[7/7] Erstelle Windows .exe...${NC}" rm -rf build/ dist/ *.spec 2>/dev/null || true echo "Build läuft... (kann einige Minuten dauern)" echo "" # Führe PyInstaller aus wine "$WINE_PYINSTALLER" \ --onefile \ --windowed \ --name "PointCab_Renamer" \ --add-data "cluster_cleanup.txt;." \ pointcab_renamer.py 2>&1 | grep -v "^fixme:" | grep -v "^err:" || true # Cleanup Xvfb falls gestartet [ -n "$XVFB_PID" ] && kill $XVFB_PID 2>/dev/null # Prüfe Ergebnis echo "" if [ -f "dist/PointCab_Renamer.exe" ]; then echo -e "${GREEN}╔════════════════════════════════════════════════════════════════════╗${NC}" echo -e "${GREEN}║ BUILD ERFOLGREICH! ║${NC}" echo -e "${GREEN}╚════════════════════════════════════════════════════════════════════╝${NC}" # Kopiere zusätzliche Dateien cp cluster_cleanup.txt dist/ cp BENUTZERHANDBUCH.md dist/ 2>/dev/null || true echo "" echo "Erstellte Dateien:" ls -lh dist/ echo "" echo "Die .exe befindet sich in: $SCRIPT_DIR/dist/" echo "" echo -e "${YELLOW}WICHTIG:${NC}" echo " Die .exe sollte auf einem echten Windows-System" echo " getestet werden, bevor sie verteilt wird!" echo "" else fail_with_alternatives fi