SPB Git

Repository Public License

release-mac.sh 5.6 KB 98 lines shellscript

1#!/bin/zsh2# ORIX Navigator — macOS release steps (Developer ID, hardened runtime, notarized DMG).3# usage: release-mac.sh build | verify | notarize-app | dmg | notarize-dmg | gatekeeper | all4# Notarization uses the keychain profile already on this Mac (NOTARY_PROFILE, default MacLustr-Notarize).5# Nothing is reported as notarized unless Apple's service answered "Accepted" and the ticket staples and validates.6set -euo pipefail7cd "$(dirname "$0")/.."8PROFILE="${NOTARY_PROFILE:-MacLustr-Notarize}"9NAME="ORIX Navigator"10BUNDLE_ID="ai.spboucher.orix.navigator"11TEAM="3YM54G49SN"12APP="dist/$NAME.app"13mkdir -p build/logs build/notary dist1415version() { /usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "$APP/Contents/Info.plist"; }16dmg_path() { echo "dist/ORIX-Navigator-$(version).dmg"; }17fail() { echo "FAIL: $1" >&2; exit 1; }1819build() {20  xcodegen generate --quiet21  local archive="build/NavigatorMac.xcarchive"; rm -rf "$archive"22  xcodebuild -project ORIXNavigator.xcodeproj -scheme NavigatorMac -configuration Release -destination "generic/platform=macOS" \23    -archivePath "$archive" -derivedDataPath build/dd-release-mac archive > build/logs/mac-archive.log 2>&1 \24    || { grep -E "error:|\*\* " build/logs/mac-archive.log | sort -u | head -20; exit 1; }25  # A running previous build must not be deleted from under the user: keep it aside.26  if [[ -d "$APP" ]]; then mkdir -p dist/previous; rm -rf "dist/previous/$NAME.app"; mv "$APP" "dist/previous/"; fi27  ditto "$archive/Products/Applications/$NAME.app" "$APP"28  echo "built $APP $(version) ($(/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' "$APP/Contents/Info.plist"))"29}3031verify() {32  [[ -d "$APP" ]] || fail "$APP not found (run: release-mac.sh build)"33  local info; info="$(codesign -dvv "$APP" 2>&1)"34  grep -q "^Authority=Developer ID Application: " <<<"$info" || fail "not signed with a Developer ID Application identity"35  grep -q "^TeamIdentifier=$TEAM$" <<<"$info" || fail "unexpected team"36  grep -q "flags=.*runtime" <<<"$info" || fail "Hardened Runtime is not enabled"37  grep -q "^Timestamp=" <<<"$info" || fail "no secure timestamp"38  grep -q "^Identifier=$BUNDLE_ID$" <<<"$info" || fail "unexpected bundle identifier"39  codesign --verify --deep --strict --verbose=2 "$APP" 2>&1 | tail -2 || fail "signature does not verify"40  local ent; ent="$(codesign -d --entitlements - --xml "$APP" 2>/dev/null | plutil -p - 2>/dev/null || true)"41  grep -q "get-task-allow" <<<"$ent" && fail "get-task-allow present in a release build"42  grep -q '"com.apple.security.app-sandbox" => true' <<<"$ent" || fail "App Sandbox is not enabled"43  if grep -rIlE "sk-ant-|sk-proj-|sk-or-|BEGIN (EC |RSA )?PRIVATE KEY" "$APP" 2>/dev/null | head -3 | grep -q .; then fail "secret-looking string in the bundle"; fi44  echo "Signature : $(sed -n 's/^Authority=\(Developer ID Application: .*\)$/\1/p' <<<"$info" | head -1)"45  echo "Runtime   : hardened; Timestamp: $(sed -n 's/^Timestamp=//p' <<<"$info")"46  echo "Entitlements:"; sed 's/^/  /' <<<"$ent"47  echo "OK: signature verified."48}4950notarize() {  # $1 artifact, $2 short name51  local artifact="$1" short="$2" submit="$1"52  if [[ -d "$artifact" ]]; then submit="build/notary/$short-submit.zip"; rm -f "$submit"; ditto -c -k --keepParent "$artifact" "$submit"; fi53  local out="build/notary/$short.json"54  if ! xcrun notarytool submit "$submit" --keychain-profile "$PROFILE" --wait --output-format json >"$out" 2>"$out.err"; then55    echo "Notary service refused the submission of $artifact:" >&2; sed 's/^/  /' "$out.err" | head -8 >&2; exit 256  fi57  local verdict id58  verdict="$(/usr/bin/python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("status",""))' "$out")"59  id="$(/usr/bin/python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("id",""))' "$out")"60  echo "Submission $id: $verdict"61  xcrun notarytool log "$id" --keychain-profile "$PROFILE" "build/notary/$short-log.json" >/dev/null 2>&1 || true62  [[ "$verdict" == "Accepted" ]] || { echo "RESULT: $artifact is NOT notarized. See build/notary/$short-log.json" >&2; exit 3; }63  xcrun stapler staple "$artifact" >/dev/null64  xcrun stapler validate "$artifact"65  echo "RESULT: $artifact is notarized by Apple (submission $id)."66}6768dmg() {69  local identity dmg stage70  identity="$(codesign -dvv "$APP" 2>&1 | sed -n 's/^Authority=\(Developer ID Application: .*\)$/\1/p' | head -1)"71  [[ -n "$identity" ]] || fail "the app is not signed with a Developer ID identity"72  dmg="$(dmg_path)"; stage="$(mktemp -d)"; ditto "$APP" "$stage/$NAME.app"; rm -f "$dmg"73  create-dmg --volname "$NAME $(version)" --window-pos 200 160 --window-size 660 440 --icon-size 128 \74    --icon "$NAME.app" 170 200 --app-drop-link 490 200 --hide-extension "$NAME.app" --no-internet-enable \75    "$dmg" "$stage" >/dev/null 2>build/logs/create-dmg.err || { [[ -f "$dmg" ]] || { cat build/logs/create-dmg.err >&2; exit 1; }; }76  rm -rf "$stage"77  codesign --force --timestamp --sign "$identity" "$dmg"; codesign --verify "$dmg"78  echo "built and signed $dmg"79}8081gatekeeper() {82  local dmg; dmg="$(dmg_path)"83  spctl --assess --type execute --verbose=2 "$APP" 2>&1 | sed 's/^/  /'84  [[ -f "$dmg" ]] && spctl --assess --type open --context context:primary-signature --verbose=2 "$dmg" 2>&1 | sed 's/^/  /'85  ( cd dist && shasum -a 256 "$(basename "$dmg")" | tee SHA256SUMS.txt )86}8788case "${1:?usage: release-mac.sh build | verify | notarize-app | dmg | notarize-dmg | gatekeeper | all}" in89  build) build ;;90  verify) verify ;;91  notarize-app) notarize "$APP" app ;;92  dmg) dmg ;;93  notarize-dmg) notarize "$(dmg_path)" dmg ;;94  gatekeeper) gatekeeper ;;95  all) build; verify; notarize "$APP" app; dmg; notarize "$(dmg_path)" dmg; gatekeeper ;;96  *) echo "unknown step" >&2; exit 2 ;;97esac98
Files main
Menu

Theme