Repository Public
1#!/usr/bin/env bash2# SP Lecture Studio3# File: scripts/notarize-macos.sh4# Description: Notarizes dist/SP Lecture Studio.app with the EXISTING notarytool keychain profile, staples it, then builds, signs,5# notarizes and staples the DMG. Never creates, prints or modifies credentials. "notarized" is printed only on Accepted.6# NOTARY_PROFILE: keychain profile created earlier with `xcrun notarytool store-credentials` (default: MacLustr-Notarize).7#8# Author: Simon-Pierre Boucher9# Contact: contact@spboucher.ai10set -euo pipefail11cd "$(dirname "$0")/.."12PROFILE="${NOTARY_PROFILE:-MacLustr-Notarize}"; APPNAME="SP Lecture Studio"; APP="dist/$APPNAME.app"13[[ -d "$APP" ]] || { echo "ERROR: $APP not found. Run scripts/archive-macos.sh first." >&2; exit 1; }14VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist")"15DMG="dist/SPLectureStudio-$VERSION.dmg"; ZIP="build/SPLectureStudio-notarize.zip"; mkdir -p build1617submit() { # submit <file> <json-output>; returns 0 only when the status is Accepted18 local file="$1" out="$2"19 if ! xcrun notarytool submit "$file" --keychain-profile "$PROFILE" --wait --output-format json >"$out" 2>"$out.err"; then20 echo "Notary service refused the submission of $file:" >&2; sed -e 's/^/ /' "$out.err" | head -8 >&2; return 121 fi22 local status id23 status="$(/usr/bin/python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("status",""))' "$out")"24 id="$(/usr/bin/python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("id",""))' "$out")"25 echo "Submission $id: $status"26 if [[ "$status" != "Accepted" ]]; then27 xcrun notarytool log "$id" --keychain-profile "$PROFILE" "build/notary-log-$id.json" >/dev/null 2>&1 || true28 echo "See build/notary-log-$id.json for the reasons." >&2; return 129 fi30}3132echo "== 1/4 Submitting the application =="33rm -f "$ZIP"; ditto -c -k --keepParent "$APP" "$ZIP"34submit "$ZIP" build/notary-app.json || { 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"37echo "== 3/4 Building the disk image =="38IDENTITY="$(codesign -dvv "$APP" 2>&1 | sed -n 's/^Authority=\(Developer ID Application: .*\)$/\1/p' | head -1)"39rm -f "$DMG"; STAGE="$(mktemp -d)"40ditto "$APP" "$STAGE/$APPNAME.app"; ln -s /Applications "$STAGE/Applications"41hdiutil create -volname "$APPNAME" -srcfolder "$STAGE" -ov -format UDZO "$DMG" >/dev/null; rm -rf "$STAGE"42codesign --force --timestamp --sign "$IDENTITY" "$DMG"43echo "== 4/4 Submitting and stapling the disk image =="44submit "$DMG" build/notary-dmg.json || { echo "RESULT: the application is notarized and stapled, but the disk image is NOT." >&2; exit 3; }45xcrun stapler staple "$DMG"; xcrun stapler validate "$DMG"46(cd dist && shasum -a 256 "$(basename "$DMG")") | tee "$DMG.sha256"47spctl --assess --type execute --verbose=2 "$APP" 2>&1 | head -248echo "RESULT: notarized and stapled — $APP and $DMG"49