|
| 1 | +#!/usr/bin/env bash |
| 2 | +# build/macos/codesign.sh |
| 3 | +# Ad-hoc code signing for LTX Desktop macOS app bundle. |
| 4 | +# |
| 5 | +# No Apple Developer account or Apple ID is required. By default this script |
| 6 | +# uses ad-hoc signing (identity "-"), which prevents the "app is damaged" Gatekeeper |
| 7 | +# warning without needing a paid Apple Developer certificate. |
| 8 | +# |
| 9 | +# For production releases with a real Developer ID, set the MACOS_SIGNING_IDENTITY |
| 10 | +# environment variable to your certificate name (e.g. "Developer ID Application: …"). |
| 11 | +# |
| 12 | +# Adapted from: https://github.com/audiohacking/AceForge/blob/main/build/macos/codesign.sh |
| 13 | +# Original reference: https://github.com/dylanwh/lilguy/blob/main/macos/build.sh |
| 14 | +# |
| 15 | +# Usage: |
| 16 | +# bash build/macos/codesign.sh <path-to-app.bundle> |
| 17 | + |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +APP_PATH="${1:?Usage: $0 <path-to-app.bundle>}" |
| 21 | +SIGNING_IDENTITY="${MACOS_SIGNING_IDENTITY:--}" # Default: ad-hoc ("-") |
| 22 | +ENTITLEMENTS_PATH="resources/entitlements.mac.plist" |
| 23 | + |
| 24 | +echo "==================================================" |
| 25 | +echo " LTX Desktop macOS Code Signing" |
| 26 | +echo "==================================================" |
| 27 | +echo " App: $APP_PATH" |
| 28 | +echo " Identity: $SIGNING_IDENTITY" |
| 29 | +echo " Entitlements: $ENTITLEMENTS_PATH" |
| 30 | +echo "" |
| 31 | + |
| 32 | +# ── Pre-flight checks ──────────────────────────────────────────────────────── |
| 33 | +if [ ! -d "$APP_PATH" ]; then |
| 34 | + echo "Error: App bundle not found at $APP_PATH" |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +if [ ! -f "$ENTITLEMENTS_PATH" ]; then |
| 39 | + echo "Error: Entitlements file not found at $ENTITLEMENTS_PATH" |
| 40 | + echo " Run this script from the project root." |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | + |
| 44 | +# ── Signing helper ──────────────────────────────────────────────────────────── |
| 45 | +# Ad-hoc signing ("-") does not support --timestamp (requires a CA). |
| 46 | +sign_target() { |
| 47 | + local target="$1" |
| 48 | + echo " Signing: $(basename "$target")" |
| 49 | + |
| 50 | + if [ "$SIGNING_IDENTITY" = "-" ]; then |
| 51 | + xcrun codesign \ |
| 52 | + --sign "$SIGNING_IDENTITY" \ |
| 53 | + --force \ |
| 54 | + --options runtime \ |
| 55 | + --entitlements "$ENTITLEMENTS_PATH" \ |
| 56 | + --deep \ |
| 57 | + "$target" |
| 58 | + else |
| 59 | + xcrun codesign \ |
| 60 | + --sign "$SIGNING_IDENTITY" \ |
| 61 | + --force \ |
| 62 | + --options runtime \ |
| 63 | + --entitlements "$ENTITLEMENTS_PATH" \ |
| 64 | + --deep \ |
| 65 | + --timestamp \ |
| 66 | + "$target" |
| 67 | + fi |
| 68 | + |
| 69 | + echo " ✓ Signed: $(basename "$target")" |
| 70 | +} |
| 71 | + |
| 72 | +# ── Step 1: Sign bundled Python native libraries ────────────────────────────── |
| 73 | +# Sign leaf Mach-O binaries first so the bundle signature remains valid. |
| 74 | +# The Python embed directory contains .dylib/.so native extensions. |
| 75 | +echo "Step 1: Signing bundled Python native libraries..." |
| 76 | +PYTHON_DIR="$APP_PATH/Contents/Resources/python" |
| 77 | +if [ -d "$PYTHON_DIR" ]; then |
| 78 | + find "$PYTHON_DIR" -type f \( -name "*.dylib" -o -name "*.so" \) -print0 | \ |
| 79 | + while IFS= read -r -d '' lib; do |
| 80 | + sign_target "$lib" || true # keep going on individual failures |
| 81 | + done |
| 82 | + echo " Python native libraries signed." |
| 83 | +else |
| 84 | + echo " No bundled Python directory found at Contents/Resources/python — skipping." |
| 85 | +fi |
| 86 | + |
| 87 | +# ── Step 2: Sign Electron framework libraries ──────────────────────────────── |
| 88 | +echo "" |
| 89 | +echo "Step 2: Signing Electron framework libraries..." |
| 90 | +if [ -d "$APP_PATH/Contents/Frameworks" ]; then |
| 91 | + find "$APP_PATH/Contents/Frameworks" -type f \( -name "*.dylib" -o -name "*.so" \) -print0 | \ |
| 92 | + while IFS= read -r -d '' f; do |
| 93 | + sign_target "$f" || true |
| 94 | + done |
| 95 | +fi |
| 96 | + |
| 97 | +# ── Step 3: Sign main executables ──────────────────────────────────────────── |
| 98 | +echo "" |
| 99 | +echo "Step 3: Signing main executables..." |
| 100 | +for exe in "$APP_PATH/Contents/MacOS/"*; do |
| 101 | + if [ -f "$exe" ] && [ -x "$exe" ]; then |
| 102 | + sign_target "$exe" |
| 103 | + fi |
| 104 | +done |
| 105 | + |
| 106 | +# ── Step 4: Sign the whole app bundle ──────────────────────────────────────── |
| 107 | +echo "" |
| 108 | +echo "Step 4: Signing app bundle..." |
| 109 | +sign_target "$APP_PATH" |
| 110 | + |
| 111 | +# ── Verification ───────────────────────────────────────────────────────────── |
| 112 | +echo "" |
| 113 | +echo "Verification:" |
| 114 | +xcrun codesign --verify --deep --strict --verbose=2 "$APP_PATH" 2>&1 || true |
| 115 | + |
| 116 | +echo "" |
| 117 | +echo "Signature info:" |
| 118 | +xcrun codesign -dv "$APP_PATH" 2>&1 || true |
| 119 | + |
| 120 | +echo "" |
| 121 | +echo "==================================================" |
| 122 | +echo " ✓ Code signing complete!" |
| 123 | +echo "==================================================" |
0 commit comments