Files
cutdex/tool/macos/sign_macos_app.sh
T
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

45 lines
1.7 KiB
Bash

#!/bin/bash
set -euo pipefail
if [ "$#" -eq 1 ] && { [ "$1" = "--help" ] || [ "$1" = "-h" ]; }; then
echo "Usage: $0 <app-bundle>"
exit 0
fi
if [[ $# != 1 ]]; then
echo "Usage: $0 <app-bundle>" >&2
exit 2
fi
repo_root="$(cd "$(dirname "$0")/../.." && pwd)"
app="$1"
signing_identity="${CUTDEX_CODESIGN_IDENTITY:--}"
# Flutter's prebuilt engine carries an unused Homebrew search path. Remove it
# from our copy before signing; the audit rejects any remaining external paths.
engine="$app/Contents/Frameworks/FlutterMacOS.framework/Versions/A/FlutterMacOS"
if /usr/bin/otool -l "$engine" | grep -F 'path /usr/local/lib/. (offset' >/dev/null; then
/usr/bin/install_name_tool -delete_rpath /usr/local/lib/. "$engine"
fi
codesign_args=(--force --sign "$signing_identity")
if [[ "$signing_identity" == "-" ]]; then
codesign_args+=(--timestamp=none)
else
codesign_args+=(--timestamp --options runtime)
fi
while IFS= read -r binary; do
if file "$binary" | grep -q 'Mach-O'; then
codesign "${codesign_args[@]}" --preserve-metadata=entitlements "$binary"
fi
done < <(find "$app/Contents" -type f -print | sort)
# Every nested bundle must use the same identity as the outer app. Mixing the
# Xcode development signature with an ad-hoc or Developer ID signature causes
# dyld to reject FlutterMacOS.framework on a clean launch.
while IFS= read -r bundle; do
codesign "${codesign_args[@]}" --preserve-metadata=entitlements "$bundle"
done < <(find "$app/Contents" -type d \( \
-name '*.framework' -o -name '*.appex' -o -name '*.xpc' -o -name '*.app' \
\) -print | awk '{ print length, $0 }' | sort -rn | cut -d' ' -f2-)
codesign "${codesign_args[@]}" \
--entitlements "$repo_root/macos/Runner/Release.entitlements" "$app"