Repository Public
1#!/bin/bash2# Notarizes dist/SP Term.app with an EXISTING notarytool keychain profile, staples the ticket,3# then builds, signs, notarizes and staples dist/SPTerm-<version>.dmg and writes its SHA-256.4# NOTARY_PROFILE keychain profile created earlier with `xcrun notarytool store-credentials`5# (default: MacLustr-Notarize). This script never creates, prints or changes credentials.6# The word "notarized" is printed only when Apple's service answered Accepted.7set -euo pipefail8cd "$(dirname "$0")/.."9PROFILE="${NOTARY_PROFILE:-MacLustr-Notarize}"10APP="dist/SP Term.app"11[[ -d "$APP" ]] || { echo "ERROR: $APP not found. Run Scripts/release.sh first." >&2; exit 1; }12VERSION="$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "$APP/Contents/Info.plist")"13DMG="dist/SPTerm-$VERSION.dmg"14mkdir -p build/notary1516submit() { # submit <file> <name>; succeeds only when the status is Accepted17 local file="$1" out="build/notary/$2.json"18 if ! xcrun notarytool submit "$file" --keychain-profile "$PROFILE" --wait --output-format json >"$out" 2>"$out.err"; then19 echo "Notary service refused the submission of $file:" >&220 sed -e 's/^/ /' "$out.err" | head -8 >&221 return 122 fi23 local status id24 status="$(/usr/bin/python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("status",""))' "$out")"25 id="$(/usr/bin/python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("id",""))' "$out")"26 echo "Submission $id: $status"27 xcrun notarytool log "$id" --keychain-profile "$PROFILE" "build/notary/$2-log.json" >/dev/null 2>&1 || true28 [[ "$status" == "Accepted" ]]29}3031echo "== 1/4 Submitting the application =="32ZIP="build/notary/SPTerm.zip"; rm -f "$ZIP"33ditto -c -k --keepParent "$APP" "$ZIP"34submit "$ZIP" app || { echo "RESULT: NOT notarized. $APP is signed but carries no notarization ticket." >&2; exit 2; }35echo "== 2/4 Stapling the application =="36xcrun stapler staple "$APP"; xcrun stapler validate "$APP"3738echo "== 3/4 Building the disk image =="39IDENTITY="$(codesign -dvv "$APP" 2>&1 | sed -n 's/^Authority=\(Developer ID Application: .*\)$/\1/p' | head -1)"40rm -f "$DMG"; STAGE="$(mktemp -d)"41ditto "$APP" "$STAGE/SP Term.app"42ln -s /Applications "$STAGE/Applications"43cp docs/RELEASE_NOTES.md "$STAGE/Release Notes.md" 2>/dev/null || true44hdiutil create -volname "SP Term $VERSION" -srcfolder "$STAGE" -ov -format UDZO "$DMG" >/dev/null45rm -rf "$STAGE"46codesign --force --timestamp --sign "$IDENTITY" "$DMG"4748echo "== 4/4 Submitting and stapling the disk image =="49submit "$DMG" dmg || { echo "RESULT: the app is notarized and stapled, the DMG is NOT." >&2; exit 3; }50xcrun stapler staple "$DMG"; xcrun stapler validate "$DMG"51shasum -a 256 "$DMG" | tee "$DMG.sha256"52echo "== Gatekeeper =="53spctl --assess --type execute --verbose=2 "$APP" 2>&1 | sed 's/^/ /'54spctl --assess --type open --context context:primary-signature --verbose=2 "$DMG" 2>&1 | sed 's/^/ /'55echo "RESULT: $APP and $DMG are notarized by Apple and stapled."56