SPB Git

Repository Public

notarize.sh 2.9 KB 49 lines shellscript

1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/notarize.sh4# Description: Notarizes dist/VQuant.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="VQuant"; 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/VQuant-$VERSION.dmg"; ZIP="build/VQuant-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}3031echo "== 1/4 Submitting the application =="32rm -f "$ZIP"; ditto -c -k --keepParent "$APP" "$ZIP"33submit "$ZIP" build/notary-app.json || { echo "RESULT: NOT notarized. $APP is signed but carries no notarization ticket." >&2; exit 2; }34echo "== 2/4 Stapling the application =="35xcrun stapler staple "$APP"; xcrun stapler validate "$APP"3637echo "== 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"4344echo "== 4/4 Submitting and stapling the disk image =="45submit "$DMG" build/notary-dmg.json || { echo "RESULT: the application is notarized and stapled, but the disk image is NOT." >&2; exit 3; }46xcrun stapler staple "$DMG"; xcrun stapler validate "$DMG"47(cd dist && shasum -a 256 "$(basename "$DMG")") | tee "$DMG.sha256"48echo "RESULT: notarized and stapled — $APP and $DMG"49
Files main
Menu

Theme