SPB Git

Repository Public

notarize.sh 3.6 KB 56 lines shellscript

1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/notarize.sh4# Description: Notarizes dist/SP Mail.app with the EXISTING notarytool keychain profile, staples it, then builds, signs, notarizes and staples the DMG.5#6# Usage: Scripts/notarize.sh7#   NOTARY_PROFILE  keychain profile created earlier with `xcrun notarytool store-credentials` (default: MacLustr-Notarize).8# The script never creates, prints or modifies credentials. "notarized" is printed only when Apple answered Accepted.9set -euo pipefail10cd "$(dirname "$0")/.."11PROFILE="${NOTARY_PROFILE:-MacLustr-Notarize}"; APPNAME="SP Mail"; APP="dist/$APPNAME.app"12[[ -d "$APP" ]] || { echo "ERROR: $APP not found. Run Scripts/release.sh first." >&2; exit 1; }13VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist")"14DMG="dist/SPMail-$VERSION.dmg"; ZIP="Build/SPMail-notarize.zip"; mkdir -p Build1516submit() {   # submit <file> <json-output>; returns 0 only when status is Accepted17  local file="$1" out="$2"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:" >&2; sed -e 's/^/  /' "$out.err" | head -8 >&2; [[ -s "$out" ]] && head -c 600 "$out" >&2 && echo >&2; return 120  fi21  local status id22  status="$(/usr/bin/python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("status",""))' "$out")"23  id="$(/usr/bin/python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("id",""))' "$out")"24  echo "Submission $id: $status"25  if [[ "$status" != "Accepted" ]]; then26    xcrun notarytool log "$id" --keychain-profile "$PROFILE" "Build/notary-log-$id.json" >/dev/null 2>&1 || true27    echo "See Build/notary-log-$id.json for the reasons." >&2; return 128  fi29}3031# every nested bundle (widgets, share extension, notification service) must already be signed with Developer ID, the hardened runtime32# and a secure timestamp: the notary service refuses the whole submission otherwise33for x in "$APP" "$APP"/Contents/PlugIns/*.appex; do34  [[ -e "$x" ]] || continue35  I="$(codesign -dvv "$x" 2>&1)"36  grep -q "Authority=Developer ID Application" <<<"$I" && grep -Eq "flags=.*runtime" <<<"$I" && grep -q "^Timestamp=" <<<"$I" || { echo "ERROR: $(basename "$x") is not signed for notarization (Developer ID, hardened runtime, timestamp). Run Scripts/release.sh and Scripts/verify-release.sh." >&2; exit 1; }37done38echo "== 1/4 Submitting the application =="39rm -f "$ZIP"; ditto -c -k --keepParent "$APP" "$ZIP"40submit "$ZIP" Build/notary-app.json || { echo "RESULT: NOT notarized. $APP is signed but carries no notarization ticket." >&2; exit 2; }41echo "== 2/4 Stapling the application =="42xcrun stapler staple "$APP"; xcrun stapler validate "$APP"4344echo "== 3/4 Building the disk image =="45IDENTITY="$(codesign -dvv "$APP" 2>&1 | sed -n 's/^Authority=\(Developer ID Application: .*\)$/\1/p' | head -1)"46rm -f "$DMG"; STAGE="$(mktemp -d)"47ditto "$APP" "$STAGE/$APPNAME.app"; ln -s /Applications "$STAGE/Applications"48hdiutil create -volname "$APPNAME" -srcfolder "$STAGE" -ov -format UDZO "$DMG" >/dev/null; rm -rf "$STAGE"49codesign --force --timestamp --sign "$IDENTITY" "$DMG"5051echo "== 4/4 Submitting and stapling the disk image =="52submit "$DMG" Build/notary-dmg.json || { echo "RESULT: the application is notarized and stapled, but the disk image is NOT." >&2; exit 3; }53xcrun stapler staple "$DMG"; xcrun stapler validate "$DMG"54(cd dist && shasum -a 256 "$(basename "$DMG")") | tee "$DMG.sha256"55echo "RESULT: notarized and stapled — $APP and $DMG"56
Files main
Menu

Theme