Created
April 29, 2020 19:05
-
-
Save EvanBalster/63c0901c829c8905cc8a578aa1c93faf to your computer and use it in GitHub Desktop.
Mac OS X notarization script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -u | |
ASC_PROVIDER="$1" | |
ASC_USERNAME="$2" | |
ASC_PASSWORD="$3" | |
BUNDLE_ID="$4" | |
BUNDLE_PKG="$5" | |
# create temporary files | |
NOTARIZE_APP_LOG=$(mktemp -t notarize-app) | |
NOTARIZE_INFO_LOG=$(mktemp -t notarize-info) | |
# delete temporary files on exit | |
function finish { | |
rm "$NOTARIZE_APP_LOG" "$NOTARIZE_INFO_LOG" | |
} | |
trap finish EXIT | |
# submit app for notarization | |
if xcrun altool --notarize-app --primary-bundle-id "$BUNDLE_ID" --asc-provider "$ASC_PROVIDER" --username "$ASC_USERNAME" --password "$ASC_PASSWORD" -f "$BUNDLE_PKG" > "$NOTARIZE_APP_LOG" 2>&1; then | |
cat "$NOTARIZE_APP_LOG" | |
RequestUUID=$(awk -F ' = ' '/RequestUUID/ {print $2}' "$NOTARIZE_APP_LOG") | |
# check status periodically | |
while sleep 60 && date; do | |
# check notarization status | |
if xcrun altool --notarization-info "$RequestUUID" --asc-provider "$ASC_PROVIDER" --username "$ASC_USERNAME" --password "$ASC_PASSWORD" > "$NOTARIZE_INFO_LOG" 2>&1; then | |
cat "$NOTARIZE_INFO_LOG" | |
# once notarization is complete, run stapler and exit | |
if ! grep -q "Status: in progress" "$NOTARIZE_INFO_LOG"; then | |
xcrun stapler staple "$BUNDLE_PKG" | |
exit | |
fi | |
else | |
cat "$NOTARIZE_INFO_LOG" 1>&2 | |
exit 1 | |
fi | |
done | |
else | |
cat "$NOTARIZE_APP_LOG" 1>&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script uploads an app for notarization by Apple, waits for notarization to complete, and if successful staples the notarization ticket to the DMG bundle.
Parameters:
† Putting cleartext passwords in your script is sketchy, so I suggest installing the password into your Mac's keychain, with an ID like
my-altool-password
. Then, supply@keychain:my-altool-password
as the password in the script.