|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Notarize |
| 4 | +# |
| 5 | +# Uploads to Apple's notarization service, polls until it completes, staples the ticket to the built app, then creates a new zip. |
| 6 | +# |
| 7 | +# Requires four arguments: |
| 8 | +# - Apple ID username |
| 9 | +# - Apple ID app-specific password (store this in your Keychain and use the @keychain:$NAME syntax to prevent your password from being added to your shell history) |
| 10 | +# - App Store Connect provider name |
| 11 | +# - Path to .app to upload |
| 12 | +# |
| 13 | +# Assumes that there's a .app beside the .zip with the same name so it can be stapled and re-zipped. |
| 14 | +# |
| 15 | +# E.g. notarize.sh "[email protected]" "@keychain:altool" MyOrg Xcodes.zip |
| 16 | +# |
| 17 | +# https://developer.apple.com/documentation/xcode/notarizing_macos_software_before_distribution/customizing_the_notarization_workflow |
| 18 | +# Adapted from https://github.com/keybase/client/blob/46f5df0aa64ff19198ba7b044bbb7cd907c0be9f/packaging/desktop/package_darwin.sh |
| 19 | + |
| 20 | +username="$1" |
| 21 | +password="$2" |
| 22 | +asc_provider="$3" |
| 23 | +file="$4" |
| 24 | + |
| 25 | +echo "Uploading to notarization service" |
| 26 | + |
| 27 | +uuid=$(xcrun altool \ |
| 28 | + --notarize-app \ |
| 29 | + --primary-bundle-id "com.robotsandpencils.XcodesApp.zip" \ |
| 30 | + --username "$username" \ |
| 31 | + --password "$password" \ |
| 32 | + --asc-provider "$asc_provider" \ |
| 33 | + --file "$file" 2>&1 | \ |
| 34 | + grep 'RequestUUID' | \ |
| 35 | + awk '{ print $3 }') |
| 36 | + |
| 37 | +echo "Successfully uploaded to notarization service, polling for result: $uuid" |
| 38 | + |
| 39 | +sleep 15 |
| 40 | + while : |
| 41 | + do |
| 42 | + fullstatus=$(xcrun altool \ |
| 43 | + --notarization-info "$uuid" \ |
| 44 | + --username "$username" \ |
| 45 | + --password "$password" \ |
| 46 | + --asc-provider "$asc_provider" 2>&1) |
| 47 | + status=$(echo "$fullstatus" | grep 'Status\:' | awk '{ print $2 }') |
| 48 | + if [ "$status" = "success" ]; then |
| 49 | + echo "Notarization success" |
| 50 | + exit 0 |
| 51 | + elif [ "$status" = "in" ]; then |
| 52 | + echo "Notarization still in progress, sleeping for 15 seconds and trying again" |
| 53 | + sleep 15 |
| 54 | + else |
| 55 | + echo "Notarization failed, full status below" |
| 56 | + echo "$fullstatus" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + done |
| 60 | + |
| 61 | +# Remove .zip |
| 62 | +rm $file |
| 63 | + |
| 64 | +# Staple ticket to .app |
| 65 | +app_path="$(basename -s ".zip" "$file").app" |
| 66 | +xcrun stapler staple "$app_path" |
| 67 | + |
| 68 | +# Zip the stapled app for distribution |
| 69 | +zip -r "$file" "$app_path" |
0 commit comments