notarize_app.sh (2196B)
1 #!/usr/bin/env bash 2 # from https://github.com/metabrainz/picard/blob/e1354632d2db305b7a7624282701d34d73afa225/scripts/package/macos-notarize-app.sh 3 4 5 if [ -z "$1" ]; then 6 echo "Specify app bundle as first parameter" 7 exit 1 8 fi 9 10 if [ -z "$APPLE_ID_USER" ] || [ -z "$APPLE_ID_PASSWORD" ]; then 11 echo "You need to set your Apple ID credentials with \$APPLE_ID_USER and \$APPLE_ID_PASSWORD." 12 exit 1 13 fi 14 15 APP_BUNDLE=$(basename "$1") 16 APP_BUNDLE_DIR=$(dirname "$1") 17 18 cd "$APP_BUNDLE_DIR" || exit 1 19 20 # Package app for submission 21 echo "Generating ZIP archive ${APP_BUNDLE}.zip..." 22 ditto -c -k --rsrc --keepParent "$APP_BUNDLE" "${APP_BUNDLE}.zip" 23 24 # Submit for notarization 25 echo "Submitting $APP_BUNDLE for notarization..." 26 RESULT=$(xcrun altool --notarize-app --type osx \ 27 --file "${APP_BUNDLE}.zip" \ 28 --primary-bundle-id org.electrum.electrum \ 29 --username $APPLE_ID_USER \ 30 --password @env:APPLE_ID_PASSWORD \ 31 --output-format xml) 32 33 if [ $? -ne 0 ]; then 34 echo "Submitting $APP_BUNDLE failed:" 35 echo "$RESULT" 36 exit 1 37 fi 38 39 REQUEST_UUID=$(echo "$RESULT" | xpath \ 40 "//key[normalize-space(text()) = 'RequestUUID']/following-sibling::string[1]/text()" 2> /dev/null) 41 42 if [ -z "$REQUEST_UUID" ]; then 43 echo "Submitting $APP_BUNDLE failed:" 44 echo "$RESULT" 45 exit 1 46 fi 47 48 echo "$(echo "$RESULT" | xpath \ 49 "//key[normalize-space(text()) = 'success-message']/following-sibling::string[1]/text()" 2> /dev/null)" 50 51 # Poll for notarization status 52 echo "Submitted notarization request $REQUEST_UUID, waiting for response..." 53 sleep 60 54 while : 55 do 56 RESULT=$(xcrun altool --notarization-info "$REQUEST_UUID" \ 57 --username "$APPLE_ID_USER" \ 58 --password @env:APPLE_ID_PASSWORD \ 59 --output-format xml) 60 STATUS=$(echo "$RESULT" | xpath \ 61 "//key[normalize-space(text()) = 'Status']/following-sibling::string[1]/text()" 2> /dev/null) 62 63 if [ "$STATUS" = "success" ]; then 64 echo "Notarization of $APP_BUNDLE succeeded!" 65 break 66 elif [ "$STATUS" = "in progress" ]; then 67 echo "Notarization in progress..." 68 sleep 20 69 else 70 echo "Notarization of $APP_BUNDLE failed:" 71 echo "$RESULT" 72 exit 1 73 fi 74 done 75 76 # Staple the notary ticket 77 xcrun stapler staple "$APP_BUNDLE"