This commit is contained in:
Mark Gregory
2026-10-23 07:52:57 +01:00
parent 46bd60d497
commit 9bca20cf60
11 changed files with 1115 additions and 1200 deletions
+65 -316
View File
@@ -1,318 +1,67 @@
#!/bin/bash
#!/bin/zsh
set -euo pipefail
# ============================================================
# OrionToolbar - Developer ID Release
# ============================================================
APP_NAME="OrionToolbar"
SCHEME="OrionToolbar"
PROJECT="OrionToolbar.xcodeproj"
SIGNING_IDENTITY="B99D353C88996866C49E4389B375645F76870A3F"
TEAM_ID="39R6U3437D"
NOTARY_PROFILE="orion-notary"
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
BUILD_DIR="$ROOT_DIR/build"
LOG_DIR="$ROOT_DIR/build-logs"
ARCHIVE_PATH="$BUILD_DIR/$APP_NAME.xcarchive"
EXPORT_DIR="$BUILD_DIR/export"
DMG_STAGE="$BUILD_DIR/dmg"
DMG_PATH="$ROOT_DIR/$APP_NAME.dmg"
EXPORT_OPTIONS="$BUILD_DIR/ExportOptions.plist"
mkdir -p "$LOG_DIR"
LOG_FILE="$LOG_DIR/release-$(date +%Y%m%d-%H%M%S).log"
exec > >(tee -a "$LOG_FILE") 2>&1
echo
echo "============================================================"
echo " ORION TOOLBAR - DIRECT DISTRIBUTION"
echo "============================================================"
echo
cd "$ROOT_DIR"
# ------------------------------------------------------------
# Prerequisites
# ------------------------------------------------------------
echo "==> Checking signing identity"
security find-identity -v -p codesigning
if ! security find-identity -v -p codesigning | \
grep -q "$SIGNING_IDENTITY"; then
echo "ERROR: Developer ID signing identity unavailable."
exit 1
fi
echo
echo "==> Checking notarization profile"
xcrun notarytool history \
--keychain-profile "$NOTARY_PROFILE" \
>/dev/null
echo "Notarization profile available."
# ------------------------------------------------------------
# Clean
# ------------------------------------------------------------
echo
echo "==> Cleaning previous release"
rm -rf "$BUILD_DIR"
rm -f "$DMG_PATH"
mkdir -p \
"$BUILD_DIR" \
"$EXPORT_DIR" \
"$DMG_STAGE"
# ------------------------------------------------------------
# Export options
# ------------------------------------------------------------
cat > "$EXPORT_OPTIONS" <<EOF
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
APP_NAME=OrionToolbar
PROJECT="$ROOT/OrionToolbar.xcodeproj"
DERIVED="$ROOT/.build"
WORK="$ROOT/.build/release"
DIST="$ROOT/dist"
SIGNING_IDENTITY="${SIGNING_IDENTITY:-B99D353C88996866C49E4389B375645F76870A3F}"
TEAM_ID="${TEAM_ID:-39R6U3437D}"
NOTARY_PROFILE="${NOTARY_PROFILE:-orion-notary}"
mkdir -p "$ROOT/build-logs" "$DIST"
LOG="$ROOT/build-logs/release-$(date +%Y%m%d-%H%M%S).log"
exec > >(tee "$LOG") 2>&1
command -v xcodebuild >/dev/null
command -v hdiutil >/dev/null
security find-identity -v -p codesigning | grep -q "$SIGNING_IDENTITY" || { echo 'Developer ID identity missing' >&2; exit 1; }
xcrun notarytool history --keychain-profile "$NOTARY_PROFILE" >/dev/null
rm -rf "$WORK"
mkdir -p "$WORK/export" "$WORK/dmg"
cat > "$WORK/ExportOptions.plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"\>
<plist version="1.0">
<dict>
<key>method</key>
<string>developer-id</string>
<key>signingStyle</key>
<string>automatic</string>
<key>teamID</key>
<string>$TEAM_ID</string>
</dict>
</plist>
EOF
# ------------------------------------------------------------
# Archive
# ------------------------------------------------------------
echo
echo "==> Creating Release archive"
xcodebuild \
-project "$PROJECT" \
-scheme "$SCHEME" \
-configuration Release \
-destination "generic/platform=macOS" \
-archivePath "$ARCHIVE_PATH" \
clean archive
echo
echo "==> Archive created"
# ------------------------------------------------------------
# Export
# ------------------------------------------------------------
echo
echo "==> Exporting Developer ID application"
xcodebuild \
-exportArchive \
-archivePath "$ARCHIVE_PATH" \
-exportPath "$EXPORT_DIR" \
-exportOptionsPlist "$EXPORT_OPTIONS"
APP_PATH="$EXPORT_DIR/$APP_NAME.app"
if [ ! -d "$APP_PATH" ]; then
echo "ERROR: Exported application not found."
exit 1
fi
# ------------------------------------------------------------
# Verify signature
# ------------------------------------------------------------
echo
echo "==> Verifying application signature"
codesign \
--verify \
--deep \
--strict \
--verbose=2 \
"$APP_PATH"
echo
echo "==> Checking signing team"
ACTUAL_TEAM=$(
codesign -dv --verbose=4 "$APP_PATH" 2>&1 |
sed -n 's/^TeamIdentifier=//p'
)
if [ "$ACTUAL_TEAM" != "$TEAM_ID" ]; then
echo "ERROR: Incorrect signing team: $ACTUAL_TEAM"
exit 1
fi
echo "Signing team verified: $ACTUAL_TEAM"
# ------------------------------------------------------------
# Notarize application
# ------------------------------------------------------------
echo
echo "==> Creating notarization ZIP"
APP_ZIP="$BUILD_DIR/$APP_NAME.zip"
ditto \
-c \
-k \
--keepParent \
"$APP_PATH" \
"$APP_ZIP"
echo
echo "==> Notarizing application"
xcrun notarytool submit \
"$APP_ZIP" \
--keychain-profile "$NOTARY_PROFILE" \
--wait
echo
echo "==> Stapling application"
xcrun stapler staple "$APP_PATH"
echo
echo "==> Validating application ticket"
xcrun stapler validate "$APP_PATH"
echo
echo "==> Gatekeeper application verification"
spctl \
--assess \
--type execute \
--verbose=4 \
"$APP_PATH"
# ------------------------------------------------------------
# Prepare DMG
# ------------------------------------------------------------
echo
echo "==> Preparing DMG"
rm -rf "$DMG_STAGE"
mkdir -p "$DMG_STAGE"
ditto "$APP_PATH" "$DMG_STAGE/$APP_NAME.app"
ln -s /Applications "$DMG_STAGE/Applications"
# ------------------------------------------------------------
# Create DMG
# ------------------------------------------------------------
echo
echo "==> Creating DMG"
hdiutil create \
-volname "$APP_NAME" \
-srcfolder "$DMG_STAGE" \
-ov \
-format UDZO \
"$DMG_PATH"
# ------------------------------------------------------------
# Sign DMG
# ------------------------------------------------------------
echo
echo "==> Signing DMG"
codesign \
--force \
--timestamp \
--sign "$SIGNING_IDENTITY" \
"$DMG_PATH"
echo
echo "==> Verifying DMG signature"
codesign \
--verify \
--verbose=2 \
"$DMG_PATH"
# ------------------------------------------------------------
# Notarize DMG
# ------------------------------------------------------------
echo
echo "==> Notarizing DMG"
xcrun notarytool submit \
"$DMG_PATH" \
--keychain-profile "$NOTARY_PROFILE" \
--wait
echo
echo "==> Stapling DMG"
xcrun stapler staple "$DMG_PATH"
echo
echo "==> Validating DMG ticket"
xcrun stapler validate "$DMG_PATH"
# ------------------------------------------------------------
# Final verification
# ------------------------------------------------------------
echo
echo "==> Final Gatekeeper verification"
spctl \
--assess \
--type open \
--context context:primary-signature \
--verbose=4 \
"$DMG_PATH"
echo
echo "==> Final DMG information"
ls -lh "$DMG_PATH"
echo
echo "==> SHA-256"
shasum -a 256 "$DMG_PATH"
echo
echo "============================================================"
echo " RELEASE BUILD COMPLETE"
echo "============================================================"
echo
echo "DMG:"
echo "$DMG_PATH"
echo
echo "Build log:"
echo "$LOG_FILE"
echo
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>method</key><string>developer-id</string>
<key>signingStyle</key><string>automatic</string>
<key>teamID</key><string>$TEAM_ID</string>
</dict></plist>
PLIST
xcodebuild -project "$PROJECT" -scheme "$APP_NAME" -configuration Release -destination 'generic/platform=macOS' -archivePath "$WORK/$APP_NAME.xcarchive" archive
xcodebuild -exportArchive -archivePath "$WORK/$APP_NAME.xcarchive" -exportPath "$WORK/export" -exportOptionsPlist "$WORK/ExportOptions.plist"
APP="$WORK/export/$APP_NAME.app"
[[ -d "$APP" ]] || { echo 'Exported app missing' >&2; exit 1; }
codesign --verify --deep --strict --verbose=2 "$APP"
ACTUAL_TEAM=$(codesign -dv --verbose=4 "$APP" 2>&1 | sed -n 's/^TeamIdentifier=//p')
[[ "$ACTUAL_TEAM" == "$TEAM_ID" ]] || { echo "Unexpected team: $ACTUAL_TEAM" >&2; exit 1; }
VERSION=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist")
[[ -n "$VERSION" ]] || { echo 'Missing marketing version' >&2; exit 1; }
DMG="$DIST/$APP_NAME-$VERSION.dmg"
ZIP="$WORK/$APP_NAME.zip"
ditto -c -k --keepParent "$APP" "$ZIP"
notarize() {
local file="$1" result status
result=$(xcrun notarytool submit "$file" --keychain-profile "$NOTARY_PROFILE" --wait --output-format json)
echo "$result"
status=$(printf '%s' "$result" | python3 -c 'import json,sys; print(json.load(sys.stdin).get("status", ""))')
[[ "$status" == Accepted ]] || { echo "Notarization not accepted for $file: $status" >&2; exit 1; }
}
notarize "$ZIP"
xcrun stapler staple "$APP"
xcrun stapler validate "$APP"
spctl --assess --type execute --verbose=4 "$APP"
ditto "$APP" "$WORK/dmg/$APP_NAME.app"
ln -s /Applications "$WORK/dmg/Applications"
rm -f "$DMG"
hdiutil create -volname "$APP_NAME" -srcfolder "$WORK/dmg" -ov -format UDZO "$DMG"
codesign --force --timestamp --sign "$SIGNING_IDENTITY" "$DMG"
codesign --verify --verbose=2 "$DMG"
notarize "$DMG"
xcrun stapler staple "$DMG"
xcrun stapler validate "$DMG"
spctl --assess --type open --context context:primary-signature --verbose=4 "$DMG"
shasum -a 256 "$DMG" | tee "$DMG.sha256"
echo "Release complete: $DMG"
echo "Checksum: $DMG.sha256"
echo "Log: $LOG"