-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-and-notarize.sh
More file actions
executable file
·393 lines (314 loc) · 10.7 KB
/
Copy pathbuild-and-notarize.sh
File metadata and controls
executable file
·393 lines (314 loc) · 10.7 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#!/bin/bash
# PrinceUI Build and Notarization Script
# This script builds, signs, notarizes, and packages PrinceUI for distribution
set -e # Exit on any error
# Configuration
PROJECT_NAME="PrinceUI"
SCHEME="PrinceUI"
CONFIGURATION="Release"
TEAM_ID="4E5NT753KC"
SIGNING_IDENTITY="Developer ID Application: YesLogic Pty. Ltd. (4E5NT753KC)"
KEYCHAIN_PROFILE="PrinceUI-Notary"
# Directories
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="$PROJECT_DIR/build"
ARCHIVE_PATH="$BUILD_DIR/${PROJECT_NAME}.xcarchive"
EXPORT_PATH="$BUILD_DIR/export"
EXPORT_OPTIONS="$BUILD_DIR/ExportOptions.plist"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Functions
log_info() {
echo -e "${BLUE}ℹ ${NC} $1"
}
log_success() {
echo -e "${GREEN}✓${NC} $1"
}
log_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
log_error() {
echo -e "${RED}✗${NC} $1"
}
log_step() {
echo ""
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
echo -e "${BLUE} $1${NC}"
echo -e "${BLUE}═══════════════════════════════════════════════════════════${NC}"
}
# Check prerequisites
check_prerequisites() {
log_step "Checking Prerequisites"
# Check Xcode
if ! command -v xcodebuild &> /dev/null; then
log_error "Xcode command line tools not found"
exit 1
fi
log_success "Xcode found: $(xcodebuild -version | head -1)"
# Check signing identity
if ! security find-identity -v -p codesigning | grep -q "$SIGNING_IDENTITY"; then
log_error "Signing identity not found: $SIGNING_IDENTITY"
log_info "Available identities:"
security find-identity -v -p codesigning
exit 1
fi
log_success "Signing identity verified"
# Check keychain profile
if ! xcrun notarytool history --keychain-profile "$KEYCHAIN_PROFILE" &> /dev/null; then
log_warning "Keychain profile '$KEYCHAIN_PROFILE' not found"
log_info "You'll need to set it up with:"
log_info " xcrun notarytool store-credentials \"$KEYCHAIN_PROFILE\" \\"
log_info " --apple-id \"your-apple-id@example.com\" \\"
log_info " --team-id \"$TEAM_ID\" \\"
log_info " --password \"your-app-specific-password\""
echo ""
read -p "Continue without notarization? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
SKIP_NOTARIZATION=true
else
log_success "Keychain profile verified"
SKIP_NOTARIZATION=false
fi
}
# Clean build directory
clean_build() {
log_step "Cleaning Build Directory"
if [ -d "$BUILD_DIR" ]; then
rm -rf "$BUILD_DIR"
log_success "Removed old build directory"
fi
mkdir -p "$BUILD_DIR"
log_success "Created fresh build directory"
}
# Archive the application
archive_app() {
log_step "Archiving Application"
log_info "Building $PROJECT_NAME in $CONFIGURATION configuration..."
xcodebuild archive \
-project "$PROJECT_DIR/${PROJECT_NAME}.xcodeproj" \
-scheme "$SCHEME" \
-configuration "$CONFIGURATION" \
-archivePath "$ARCHIVE_PATH" \
CODE_SIGN_IDENTITY="$SIGNING_IDENTITY" \
CODE_SIGN_STYLE=Manual \
DEVELOPMENT_TEAM="$TEAM_ID" \
| xcpretty || xcodebuild archive \
-project "$PROJECT_DIR/${PROJECT_NAME}.xcodeproj" \
-scheme "$SCHEME" \
-configuration "$CONFIGURATION" \
-archivePath "$ARCHIVE_PATH" \
CODE_SIGN_IDENTITY="$SIGNING_IDENTITY" \
CODE_SIGN_STYLE=Manual \
DEVELOPMENT_TEAM="$TEAM_ID"
if [ ! -d "$ARCHIVE_PATH" ]; then
log_error "Archive failed"
exit 1
fi
log_success "Archive created: $ARCHIVE_PATH"
}
# Export the application
export_app() {
log_step "Exporting Application"
# Create export options plist
log_info "Creating export options..."
cat > "$EXPORT_OPTIONS" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>developer-id</string>
<key>signingStyle</key>
<string>manual</string>
<key>teamID</key>
<string>$TEAM_ID</string>
<key>signingCertificate</key>
<string>Developer ID Application</string>
</dict>
</plist>
EOF
log_info "Exporting archive..."
xcodebuild -exportArchive \
-archivePath "$ARCHIVE_PATH" \
-exportPath "$EXPORT_PATH" \
-exportOptionsPlist "$EXPORT_OPTIONS"
if [ ! -d "$EXPORT_PATH/${PROJECT_NAME}.app" ]; then
log_error "Export failed"
exit 1
fi
log_success "Application exported: $EXPORT_PATH/${PROJECT_NAME}.app"
}
# Verify code signing
verify_signing() {
log_step "Verifying Code Signing"
APP_PATH="$EXPORT_PATH/${PROJECT_NAME}.app"
log_info "Checking signature..."
codesign -dv --verbose=4 "$APP_PATH" 2>&1 | head -10
log_info "Checking entitlements..."
codesign -d --entitlements - "$APP_PATH"
log_info "Verifying with spctl..."
if spctl -a -vv "$APP_PATH" 2>&1 | grep -q "accepted"; then
log_success "Code signature verified"
else
log_warning "spctl verification returned warnings (this is normal before notarization)"
fi
}
# Create ZIP for notarization
create_zip() {
log_step "Creating ZIP for Notarization"
cd "$EXPORT_PATH"
ZIP_NAME="${PROJECT_NAME}.zip"
log_info "Creating $ZIP_NAME..."
ditto -c -k --keepParent "${PROJECT_NAME}.app" "$ZIP_NAME"
cd "$PROJECT_DIR"
log_success "ZIP created: $EXPORT_PATH/$ZIP_NAME"
}
# Notarize the application
notarize_app() {
if [ "$SKIP_NOTARIZATION" = true ]; then
log_warning "Skipping notarization (keychain profile not configured)"
return
fi
log_step "Notarizing Application"
ZIP_PATH="$EXPORT_PATH/${PROJECT_NAME}.zip"
log_info "Submitting to Apple for notarization..."
log_info "This may take several minutes..."
SUBMISSION_OUTPUT=$(xcrun notarytool submit "$ZIP_PATH" \
--keychain-profile "$KEYCHAIN_PROFILE" \
--wait 2>&1)
echo "$SUBMISSION_OUTPUT"
if echo "$SUBMISSION_OUTPUT" | grep -q "status: Accepted"; then
log_success "Notarization successful!"
# Extract submission ID for reference
SUBMISSION_ID=$(echo "$SUBMISSION_OUTPUT" | grep "id:" | head -1 | awk '{print $2}')
log_info "Submission ID: $SUBMISSION_ID"
return 0
else
log_error "Notarization failed"
# Try to extract submission ID for logs
SUBMISSION_ID=$(echo "$SUBMISSION_OUTPUT" | grep "id:" | head -1 | awk '{print $2}')
if [ ! -z "$SUBMISSION_ID" ]; then
log_info "Fetching detailed log..."
xcrun notarytool log "$SUBMISSION_ID" --keychain-profile "$KEYCHAIN_PROFILE"
fi
exit 1
fi
}
# Staple notarization ticket
staple_app() {
if [ "$SKIP_NOTARIZATION" = true ]; then
log_warning "Skipping stapling (notarization was skipped)"
return
fi
log_step "Stapling Notarization Ticket"
APP_PATH="$EXPORT_PATH/${PROJECT_NAME}.app"
log_info "Stapling ticket to application..."
xcrun stapler staple "$APP_PATH"
log_info "Verifying staple..."
xcrun stapler validate "$APP_PATH"
log_success "Notarization ticket stapled successfully"
log_info "Final verification with spctl..."
spctl -a -vv "$APP_PATH"
}
# Create DMG
create_dmg() {
log_step "Creating DMG"
APP_PATH="$EXPORT_PATH/${PROJECT_NAME}.app"
DMG_PATH="$BUILD_DIR/${PROJECT_NAME}.dmg"
log_info "Creating disk image..."
hdiutil create -volname "$PROJECT_NAME" \
-srcfolder "$APP_PATH" \
-ov -format UDZO \
"$DMG_PATH"
if [ ! -f "$DMG_PATH" ]; then
log_error "DMG creation failed"
exit 1
fi
log_success "DMG created: $DMG_PATH"
# Get DMG size
DMG_SIZE=$(du -h "$DMG_PATH" | cut -f1)
log_info "DMG size: $DMG_SIZE"
}
# Notarize DMG
notarize_dmg() {
if [ "$SKIP_NOTARIZATION" = true ]; then
log_warning "Skipping DMG notarization"
return
fi
log_step "Notarizing DMG"
DMG_PATH="$BUILD_DIR/${PROJECT_NAME}.dmg"
log_info "Submitting DMG for notarization..."
SUBMISSION_OUTPUT=$(xcrun notarytool submit "$DMG_PATH" \
--keychain-profile "$KEYCHAIN_PROFILE" \
--wait 2>&1)
echo "$SUBMISSION_OUTPUT"
if echo "$SUBMISSION_OUTPUT" | grep -q "status: Accepted"; then
log_success "DMG notarization successful!"
log_info "Stapling ticket to DMG..."
xcrun stapler staple "$DMG_PATH"
log_info "Verifying DMG staple..."
xcrun stapler validate "$DMG_PATH"
log_success "DMG notarization complete"
else
log_error "DMG notarization failed"
exit 1
fi
}
# Print summary
print_summary() {
log_step "Build Summary"
APP_PATH="$EXPORT_PATH/${PROJECT_NAME}.app"
DMG_PATH="$BUILD_DIR/${PROJECT_NAME}.dmg"
echo ""
log_success "Build and notarization complete!"
echo ""
echo " Application: $APP_PATH"
if [ -f "$DMG_PATH" ]; then
echo " DMG: $DMG_PATH"
fi
echo ""
if [ "$SKIP_NOTARIZATION" = true ]; then
log_warning "Application was NOT notarized"
log_info "To notarize, set up keychain profile and run again"
else
log_success "Application is signed and notarized"
log_info "Ready for distribution"
fi
echo ""
log_info "You can now distribute:"
echo " - The .app bundle (in a ZIP)"
if [ -f "$DMG_PATH" ]; then
echo " - The .dmg file"
fi
echo ""
}
# Main execution
main() {
echo ""
echo "╔════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ PrinceUI Build & Notarization Script ║"
echo "║ ║"
echo "╚════════════════════════════════════════════════════════════╝"
echo ""
check_prerequisites
clean_build
archive_app
export_app
verify_signing
create_zip
notarize_app
staple_app
create_dmg
notarize_dmg
print_summary
}
# Run main function
main "$@"