Skip to content
Source
Sign inSign up
samwillis/jerry
Open History to see the last commit

package-signed.sh

49 lines2.5 KB

1#!/bin/zsh
2# Build a Developer ID package. Credentials stay in the user's Keychain.
3set -eu
4if [[ $# -lt 2 || $# -gt 3 ]]; then
5 print -u2 'Usage: ./scripts/package-signed.sh "Developer ID Application: Company (TEAMID)" TEAMID [notary-keychain-profile]'
6 exit 2
7fi
8task_identity="$1"
9task_team="$2"
10task_profile="${3:-}"
11task_root="$(cd "$(dirname "$0")/.." && pwd)"
12task_arch="$(uname -m)"
13# Keep signed bundles outside iCloud-synced Documents; Finder metadata can
14# otherwise arrive after signing and invalidate strict verification.
15task_derived="$HOME/Library/Developer/Jerry/SignedRelease"
16if [[ "$task_identity" != 'Developer ID Application: '* ]]; then
17 print -u2 'Use a Developer ID Application identity for direct distribution.'
18 exit 2
19fi
20# Check that the matching certificate has its private key before building.
21if ! /usr/bin/security find-identity -v -p codesigning | /usr/bin/grep -F -- "\"$task_identity\"" >/dev/null; then
22 print -u2 'The specified signing identity and private key are not available in Keychain.'
23 exit 1
24fi
25xcodebuild -project "$task_root/Jerry.xcodeproj" -scheme Jerry \
26 -configuration Release -destination "platform=macOS,arch=$task_arch" \
27 -derivedDataPath "$task_derived" ONLY_ACTIVE_ARCH=YES \
28 CODE_SIGN_STYLE=Manual CODE_SIGNING_ALLOWED=YES \
29 CODE_SIGN_IDENTITY="$task_identity" DEVELOPMENT_TEAM="$task_team" \
30 ENABLE_HARDENED_RUNTIME=YES ENABLE_APP_SANDBOX=NO CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO \
31 OTHER_CODE_SIGN_FLAGS=--timestamp build
32# Use the fresh build directly; do not merge it into an older app bundle.
33task_app="$task_derived/Build/Products/Release/Jerry.app"
34/usr/bin/codesign --verify --deep --strict --verbose=2 "$task_app"
35task_version=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$task_app/Contents/Info.plist")
36mkdir -p "$task_root/build/SignedDistribution"
37task_zip="$task_root/build/SignedDistribution/Jerry-v$task_version-macos-$task_arch.zip"
38/usr/bin/ditto -c -k --sequesterRsrc --keepParent "$task_app" "$task_zip"
39if [[ -n "$task_profile" ]]; then
40 xcrun notarytool submit "$task_zip" --keychain-profile "$task_profile" --wait
41 xcrun stapler staple "$task_app"
42 xcrun stapler validate "$task_app"
43 /usr/sbin/spctl --assess --type execute --verbose=2 "$task_app"
44 /usr/bin/ditto -c -k --sequesterRsrc --keepParent "$task_app" "$task_zip"
45 print "Signed and notarised archive: $task_zip"
46else
47 print "Signed archive: $task_zip"
48 print 'Not notarised. Supply a notarytool Keychain profile before distributing.'
49fi