227 lines
9.6 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
# ═══════════════════════════════════════════════════════════
# Rebreak Magic macOS — DMG Build Script
# ═══════════════════════════════════════════════════════════
#
# Erstellt einen distributable .dmg für Rebreak Magic.app
#
# Voraussetzungen:
# - Xcode Command Line Tools
# - xcodegen (brew install xcodegen)
# - create-dmg (brew install create-dmg)
#
# Usage:
# ./build-dmg.sh
#
# Output:
# build/RebreakMagic-<version>.dmg
#
# ═══════════════════════════════════════════════════════════
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "════════════════════════════════════════════════════════════"
echo "Rebreak Magic DMG Build"
echo "════════════════════════════════════════════════════════════"
echo ""
# ─────────────────────────────────────────────────────────────
# 1. Dependency-Checks
# ─────────────────────────────────────────────────────────────
echo "→ Prüfe Dependencies..."
if ! command -v xcodegen &>/dev/null; then
echo "❌ xcodegen nicht gefunden. Installiere via: brew install xcodegen"
exit 1
fi
if ! command -v create-dmg &>/dev/null; then
echo "❌ create-dmg nicht gefunden. Installiere via: brew install create-dmg"
exit 1
fi
if ! command -v xcodebuild &>/dev/null; then
echo "❌ xcodebuild nicht gefunden. Installiere Xcode Command Line Tools."
exit 1
fi
echo "✓ Dependencies OK"
echo ""
# ─────────────────────────────────────────────────────────────
# 2. Version auslesen aus project.yml
# ─────────────────────────────────────────────────────────────
VERSION=$(grep 'MARKETING_VERSION:' project.yml | sed 's/.*"\(.*\)"/\1/')
if [ -z "$VERSION" ]; then
echo "❌ Konnte Version nicht aus project.yml lesen"
exit 1
fi
echo "→ Version: $VERSION"
echo ""
# ─────────────────────────────────────────────────────────────
# 3. Xcode-Projekt generieren
# ─────────────────────────────────────────────────────────────
echo "→ Generiere Xcode-Projekt..."
xcodegen generate
if [ ! -f "RebreakMagic.xcodeproj/project.pbxproj" ]; then
echo "❌ Xcode-Projekt konnte nicht generiert werden"
exit 1
fi
echo "✓ Projekt generiert"
echo ""
# ─────────────────────────────────────────────────────────────
# 4. macOS Icon-Cache killen (damit neues Icon sofort sichtbar)
# ─────────────────────────────────────────────────────────────
echo "→ Lösche macOS Icon-Cache..."
sudo rm -rf /Library/Caches/com.apple.iconservices.store 2>/dev/null || true
killall Dock Finder 2>/dev/null || true
echo "✓ Icon-Cache geleert"
echo ""
# ─────────────────────────────────────────────────────────────
# 5. Release-Build
# ─────────────────────────────────────────────────────────────
echo "→ Baue Release-Build..."
BUILD_DIR="$SCRIPT_DIR/build"
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
xcodebuild \
-project RebreakMagic.xcodeproj \
-scheme RebreakMagic \
-configuration Release \
-derivedDataPath "$BUILD_DIR" \
clean build
APP_PATH="$BUILD_DIR/Build/Products/Release/RebreakMagic.app"
if [ ! -d "$APP_PATH" ]; then
echo "❌ Build fehlgeschlagen — RebreakMagic.app nicht gefunden"
exit 1
fi
echo "✓ Build erfolgreich: $APP_PATH"
echo ""
# ─────────────────────────────────────────────────────────────
# 6. Icon-Verifikation
# ─────────────────────────────────────────────────────────────
echo "→ Prüfe App-Icon..."
if [ -f "$APP_PATH/Contents/Resources/Assets.car" ]; then
echo "✓ Assets.car vorhanden"
ICON_COUNT=$(assetutil --info "$APP_PATH/Contents/Resources/Assets.car" 2>&1 | grep -c "Name.*AppIcon" || true)
echo "$ICON_COUNT AppIcon-Einträge kompiliert"
else
echo "⚠️ Assets.car nicht gefunden — Icons könnten fehlen"
fi
INFO_PLIST="$APP_PATH/Contents/Info.plist"
ICON_FILE=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIconFile" "$INFO_PLIST" 2>/dev/null || echo "")
if [ -n "$ICON_FILE" ]; then
echo "✓ CFBundleIconFile: $ICON_FILE"
if [ -f "$APP_PATH/Contents/Resources/$ICON_FILE.icns" ]; then
ICNS_SIZE=$(du -h "$APP_PATH/Contents/Resources/$ICON_FILE.icns" | cut -f1)
echo "$ICON_FILE.icns gefunden ($ICNS_SIZE)"
fi
else
echo "⚠️ CFBundleIconFile nicht in Info.plist — macOS könnte Default-Icon zeigen"
fi
echo ""
# ─────────────────────────────────────────────────────────────
# 7. Code-Signing-Status (Info-Only)
# ─────────────────────────────────────────────────────────────
echo "→ Code-Signing-Status..."
SIGNING_IDENTITY=$(codesign -dvv "$APP_PATH" 2>&1 | grep "Authority=" | head -1 || echo "")
if [ -z "$SIGNING_IDENTITY" ]; then
echo "⚠️ App ist unsigned (ad-hoc signature)"
echo " → User braucht Right-Click → Öffnen beim ersten Start (Gatekeeper)"
echo " → Für Production-Distribution: Developer ID Application Cert nötig"
else
echo "✓ Signiert: $SIGNING_IDENTITY"
fi
echo ""
# ─────────────────────────────────────────────────────────────
# 8. DMG erstellen
# ─────────────────────────────────────────────────────────────
DMG_NAME="RebreakMagic-${VERSION}.dmg"
DMG_PATH="$BUILD_DIR/$DMG_NAME"
echo "→ Erstelle DMG: $DMG_NAME"
echo ""
# create-dmg mit Standard-Layout:
# - App-Icon links
# - Applications-Link rechts
# - Drag-to-install-Hinweis
create-dmg \
--volname "Rebreak Magic" \
--window-pos 200 120 \
--window-size 600 400 \
--icon-size 100 \
--icon "RebreakMagic.app" 175 190 \
--hide-extension "RebreakMagic.app" \
--app-drop-link 425 190 \
--no-internet-enable \
"$DMG_PATH" \
"$APP_PATH" \
2>&1 | grep -v "^hdiutil:" || true # Filter verbose hdiutil-Output
if [ ! -f "$DMG_PATH" ]; then
echo "❌ DMG konnte nicht erstellt werden"
exit 1
fi
DMG_SIZE=$(du -h "$DMG_PATH" | cut -f1)
echo ""
echo "════════════════════════════════════════════════════════════"
echo "✓ DMG erfolgreich erstellt"
echo "════════════════════════════════════════════════════════════"
echo ""
echo " Pfad: $DMG_PATH"
echo " Größe: $DMG_SIZE"
echo " Version: $VERSION"
echo ""
echo "Installation:"
echo " 1. DMG öffnen (doppelklick)"
echo " 2. RebreakMagic.app nach /Applications ziehen"
echo " 3. Beim ersten Start: Right-Click → Öffnen (Gatekeeper-Warning)"
echo ""
echo "Hinweis: Falls das Icon nicht sofort erscheint:"
echo " sudo rm -rf /Library/Caches/com.apple.iconservices.store && killall Dock Finder"
echo ""
echo "────────────────────────────────────────────────────────────"
echo "TODO für Production-Distribution:"
echo "────────────────────────────────────────────────────────────"
echo " - Developer ID Application Cert für Code-Signing"
echo " - Notarization via Apple (xcrun notarytool)"
echo " - Staple Notarization-Ticket: xcrun stapler staple"
echo " - DMG dann ohne Gatekeeper-Warning installierbar"
echo ""