SPB Git

Repository Public

release-mac.sh 4.1 KB 62 lines shellscript

1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/release-mac.sh4# Description: Builds the Release archive of SP Vault for macOS (app + AutoFill extension) signed with the EXISTING5#              Developer ID Application identity and the two Developer ID provisioning profiles, and exports6#              dist/SP Vault.app.7#8# Usage: Scripts/release-mac.sh9# Nothing secret is printed. No certificate is created: the script fails if no Developer ID Application identity exists.10set -euo pipefail11export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"12cd "$(dirname "$0")/.."13ROOT="$PWD"; LOG="$ROOT/build/logs/release-mac.log"; APPNAME="SP Vault"; DD="${SPV_DD:-$HOME/Library/Developer/SPVault}/DerivedData-Release"14mkdir -p build/logs dist1516IDENTITY="$(security find-identity -v -p codesigning | sed -n 's/.*"\(Developer ID Application: [^"]*\)".*/\1/p' | head -1)"17[[ -n "$IDENTITY" ]] || { echo "ERROR: no 'Developer ID Application' identity in the keychain." >&2; exit 1; }18TEAM="$(sed -n 's/.*(\([A-Z0-9]\{10\}\)).*/\1/p' <<<"$IDENTITY")"19echo "Signing identity : $IDENTITY"20echo "Team             : $TEAM"2122# the provisioning profiles carry the restricted entitlements (associated domains, AutoFill provider, keychain group)23for f in SPVault SPVaultAutoFill; do24  SRC="$ROOT/build/profiles/$f.provisionprofile"25  [[ -f "$SRC" ]] || { echo "ERROR: $SRC missing (create it with Scripts/provision.py)." >&2; exit 1; }26  PLIST="$(mktemp)"; security cms -D -i "$SRC" > "$PLIST" 2>/dev/null27  UUID="$(/usr/libexec/PlistBuddy -c 'Print :UUID' "$PLIST")"; PNAME="$(/usr/libexec/PlistBuddy -c 'Print :Name' "$PLIST")"; EXPIRES="$(/usr/libexec/PlistBuddy -c 'Print :ExpirationDate' "$PLIST")"; rm -f "$PLIST"28  for d in "$HOME/Library/Developer/Xcode/UserData/Provisioning Profiles" "$HOME/Library/MobileDevice/Provisioning Profiles"; do mkdir -p "$d"; cp "$SRC" "$d/$UUID.provisionprofile"; done29  echo "Profile          : $PNAME ($UUID), expires $EXPIRES"30done3132xcodegen generate --quiet33ARCHIVE="$ROOT/build/SPVault.xcarchive"34rm -rf "$ARCHIVE" "$ROOT/dist/$APPNAME.app"35echo "Archiving (log: build/logs/release-mac.log)…"36if ! xcodebuild -project SPVault.xcodeproj -scheme SPVault -configuration Release -derivedDataPath "$DD" \37    -destination 'generic/platform=macOS' -archivePath "$ARCHIVE" archive DEVELOPMENT_TEAM="$TEAM" >"$LOG" 2>&1; then38  sed 's/\x1b\[[0-9;]*m//g' "$LOG" | grep -E "error:|ARCHIVE FAILED" | sort -u | head -30 >&239  echo "ERROR: archive failed, see $LOG" >&2; exit 140fi41WARN="$(sed 's/\x1b\[[0-9;]*m//g' "$LOG" | { grep -E "warning: " || true; } | { grep -v appintentsmetadataprocessor || true; } | sort -u | wc -l | tr -d ' ')"42echo "Archive succeeded ($WARN compiler warning(s))"43ditto "$ARCHIVE/Products/Applications/$APPNAME.app" "$ROOT/dist/$APPNAME.app"44APP="dist/$APPNAME.app"; BIN="$APP/Contents/MacOS/$APPNAME"; EXT="$APP/Contents/PlugIns/SPVaultAutoFill.appex"45VERSION="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist")"; BUILD="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleVersion' "$APP/Contents/Info.plist")"46echo "Built $APP  version $VERSION ($BUILD)  archs: $(lipo -archs "$BIN")"4748# nothing of the development variant may survive in a Release build49FAIL=050for b in "$BIN" "$EXT/Contents/MacOS/SPVaultAutoFill"; do51  [[ -f "$b" ]] || { echo "ERROR: $b missing" >&2; FAIL=1; continue; }52  if strings -a "$b" | grep -Eq "SPV_DEV_|dev-passkeys|dev-device-keys|SPVaultDev"; then echo "ERROR: development artefact (SPV_DEV) in $(basename "$b")" >&2; FAIL=1; fi53done54for p in "$APP/Contents/Info.plist" "$EXT/Contents/Info.plist"; do55  if plutil -p "$p" | grep -q "NSAllowsLocalNetworking"; then echo "ERROR: App Transport Security exception in $p" >&2; FAIL=1; fi56done57[[ "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$APP/Contents/Info.plist")" == "ai.spboucher.spvault" ]] || { echo "ERROR: unexpected bundle identifier" >&2; FAIL=1; }58[[ $FAIL -eq 0 ]] || exit 159echo "Release checks   : no SPV_DEV artefact, no local-network exception, bundle id ai.spboucher.spvault"60codesign --verify --deep --strict --verbose=2 "$APP" 2>&1 | tail -261echo "Next: Scripts/verify-release.sh, then Scripts/notarize.sh"62
Files main
Menu

Theme