-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnotarize.sh
More file actions
151 lines (130 loc) · 4.52 KB
/
Copy pathnotarize.sh
File metadata and controls
151 lines (130 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env bash
# notarize.sh — Notarize a pre-built SAMPSON.app
#
# Use this script to notarize an already-signed SAMPSON.app bundle.
# Useful for retrying failed notarization or notarizing a release build.
#
# Required environment variables:
# APPLE_ID — Apple ID email used for notarization
# APPLE_APP_PASSWORD — App-specific password from appleid.apple.com
# APPLE_TEAM_ID — 10-character team ID
#
# Optional:
# APPLE_CODESIGN_IDENTITY — Re-sign before notarizing (defaults to ad-hoc "-")
#
# Usage:
# APPLE_ID="you@example.com" \
# APPLE_APP_PASSWORD="xxxx-xxxx-xxxx-xxxx" \
# APPLE_TEAM_ID="XXXXXXXXXX" \
# ./notarize.sh dist/SAMPSON.app
set -e
APP_PATH="${1:-dist/SAMPSON.app}"
CODESIGN_ID="${APPLE_CODESIGN_IDENTITY:--}"
# Validate arguments
if [ ! -d "$APP_PATH" ]; then
echo "ERROR: App bundle not found: $APP_PATH"
echo "Usage: $0 /path/to/SAMPSON.app"
exit 1
fi
if [ -z "$APPLE_ID" ] || [ -z "$APPLE_APP_PASSWORD" ] || [ -z "$APPLE_TEAM_ID" ]; then
echo "ERROR: Missing required environment variables."
echo ""
echo "Please set:"
echo " APPLE_ID - Your Apple ID email"
echo " APPLE_APP_PASSWORD - App-specific password from appleid.apple.com"
echo " APPLE_TEAM_ID - Your 10-character Team ID"
echo ""
echo "Example:"
echo ' APPLE_ID="you@example.com" \'
echo ' APPLE_APP_PASSWORD="abcd-abcd-abcd-abcd" \'
echo ' APPLE_TEAM_ID="A1B2C3D4E5" \'
echo " $0 $APP_PATH"
exit 1
fi
# Resolve absolute path
ABS_APP_PATH="$(cd "$(dirname "$APP_PATH")" && pwd)/$(basename "$APP_PATH")"
echo "=== Notarizing SAMPSON.app ==="
echo "App path: $ABS_APP_PATH"
echo "Signing identity: ${CODESIGN_ID:0:60}..."
# Work in /tmp to avoid OneDrive xattr issues
TMPAPP="/tmp/SAMPSON_notarize_$$.app"
echo ""
echo "[1/5] Copying to /tmp (avoiding OneDrive xattrs)..."
ditto "$ABS_APP_PATH" "$TMPAPP"
xattr -cr "$TMPAPP" 2>/dev/null || true
# Re-sign if a Developer ID is provided
if [ "$CODESIGN_ID" != "-" ]; then
echo ""
echo "[2/5] Re-signing with Developer ID..."
sign() {
codesign --force --sign "$CODESIGN_ID" --options runtime --timestamp --entitlements entitlements.plist "$@" 2>&1 \
| grep -v "replacing existing signature" || true
}
# Sign all binaries
find "$TMPAPP" \( -name "*.dylib" -o -name "*.so" \) | while read f; do
sign "$f"
done
find "$TMPAPP" -path "*/static_ffmpeg/bin/*" \( -name "ffmpeg" -o -name "ffprobe" \) | while read f; do
sign "$f"
done
for LOC in Resources Frameworks; do
FW="$TMPAPP/Contents/$LOC/Python.framework"
if [ -d "$FW" ]; then
PYVER=$(ls "$FW/Versions/" | grep -E '^[0-9]' | head -1)
sign --identifier "org.python.python" "$FW/Versions/$PYVER/Python"
sign --identifier "org.python.python" "$FW"
fi
if [ -f "$TMPAPP/Contents/$LOC/Python" ]; then
sign --identifier "org.python.python" "$TMPAPP/Contents/$LOC/Python"
fi
done
sign "$TMPAPP"
echo "Re-signed successfully."
else
echo ""
echo "[2/5] Skipping re-sign (using ad-hoc identity '-')."
echo "WARNING: Notarization requires a Developer ID certificate."
fi
# Verify signature
echo ""
echo "[3/5] Verifying code signature..."
codesign -vv --deep --strict "$TMPAPP" 2>&1 || true
# Create zip for notarization
echo ""
echo "[4/5] Creating zip for notarization..."
ZIPPATH="/tmp/SAMPSON_notarize_$$.zip"
ditto -c -k --keepParent "$TMPAPP" "$ZIPPATH"
# Submit for notarization
echo ""
echo "[5/5] Submitting to Apple for notarization..."
echo "This may take a few minutes..."
xcrun notarytool submit "$ZIPPATH" \
--apple-id "$APPLE_ID" \
--password "$APPLE_APP_PASSWORD" \
--team-id "$APPLE_TEAM_ID" \
--wait
rm "$ZIPPATH"
# Staple the ticket
echo ""
echo "Stapling notarization ticket..."
xcrun stapler staple "$TMPAPP"
# Verify Gatekeeper acceptance
echo ""
echo "Verifying Gatekeeper acceptance..."
spctl --assess --type execute --verbose "$TMPAPP" || {
echo "WARNING: Gatekeeper assessment failed."
echo "The app may still work but users may see security warnings."
}
# Copy back
echo ""
echo "Copying notarized app back to original location..."
rm -rf "$ABS_APP_PATH"
ditto "$TMPAPP" "$ABS_APP_PATH"
rm -rf "$TMPAPP"
echo ""
echo "=== Notarization Complete ==="
echo "Notarized app: $ABS_APP_PATH"
echo ""
echo "To verify:"
echo " codesign -vv --deep --strict $ABS_APP_PATH"
echo " spctl --assess --type execute --verbose $ABS_APP_PATH"