SPB Git

Repository Public

sign.sh 4.1 KB 66 lines shellscript

1#!/bin/bash2# Builds the Release configuration (universal, hardened runtime) signed with the Developer ID Application3# identity already in the keychain, re-signs every nested binary inside-out with a secure timestamp, and4# verifies the result. Produces dist/ORIX Sheet.app. Nothing is uploaded here (see Scripts/notarize.sh).5set -euo pipefail6cd "$(dirname "$0")/.."7DD="build/DerivedData-release"8APP="dist/ORIX Sheet.app"9IDENTITY="$(security find-identity -v -p codesigning | sed -n 's/.*"\(Developer ID Application: [^"]*\)".*/\1/p' | head -1)"10[[ -n "$IDENTITY" ]] || { echo "ERROR: no Developer ID Application identity in the keychain." >&2; exit 1; }11Scripts/fetch-duckdb.sh >/dev/null12xcodegen generate --quiet13echo "== Building Release (signing as: $IDENTITY) =="14rm -rf "$DD/Build/Products/Release/ORIX Sheet.app"15xcodebuild -project ORIXSheet.xcodeproj -scheme ORIXSheet -configuration Release -derivedDataPath "$DD" build 2>&1 \16  | sed 's/\x1b\[[0-9;]*m//g' | grep -E "error:|\*\* BUILD" | grep -v "^    |" | sort -u17BUILT="$DD/Build/Products/Release/ORIX Sheet.app"18[[ -d "$BUILT" ]] || { echo "ERROR: Release build failed." >&2; exit 1; }19rm -rf "$APP" && mkdir -p dist && ditto "$BUILT" "$APP"2021echo "== Building and embedding the orix-sheet command-line tool =="22( cd Packages/SheetAutomation && swift build -c release --arch arm64 --arch x86_64 --product orix-sheet 2>&1 | sed 's/\x1b\[[0-9;]*m//g' | grep -E "error|Build complete" )23CLI="$APP/Contents/MacOS/orix-sheet"24cp Packages/SheetAutomation/.build/out/Products/Release/orix-sheet "$CLI"25# the tool finds libduckdb.dylib in the app's Frameworks folder; build-machine runpaths are removed26for rp in $(otool -l "$CLI" | awk '/LC_RPATH/{getline; getline; print $2}' | sort -u); do27  case "$rp" in /usr/lib/swift) ;; *) while install_name_tool -delete_rpath "$rp" "$CLI" 2>/dev/null; do :; done ;; esac28done29install_name_tool -add_rpath "@executable_path/../Frameworks" "$CLI"3031echo "== Signing nested code inside-out =="32ENT="App/Resources/ORIXSheet.entitlements"33# libraries, helper executables and bundles first, the app last34while IFS= read -r -d '' f; do35  if file -b "$f" | grep -q "Mach-O"; then36    codesign --force --timestamp --options runtime --sign "$IDENTITY" "$f"37  fi38done < <(find "$APP/Contents" \( -name "*.dylib" -o -path "*/Helpers/*" -o -path "*/Resources/*" \) -type f -print0)39while IFS= read -r -d '' b; do40  codesign --force --timestamp --options runtime --sign "$IDENTITY" "$b"41done < <(find "$APP/Contents" -depth \( -name "*.framework" -o -name "*.bundle" \) -print0)42codesign --force --timestamp --options runtime --sign "$IDENTITY" "$CLI"43codesign --force --timestamp --options runtime --entitlements "$ENT" --sign "$IDENTITY" "$APP"4445echo "== Verifying =="46codesign --verify --deep --strict --verbose=2 "$APP"47echo "-- architectures: $(lipo -archs "$APP/Contents/MacOS/ORIX Sheet")"48codesign -dvv "$APP" 2>&1 | grep -E "^(Identifier|Authority|TeamIdentifier|Timestamp|Runtime Version)" | sed 's/^/   /'49echo "-- flags: $(codesign -dv "$APP" 2>&1 | sed -n 's/.*flags=\([^ ]*\).*/\1/p')"50if codesign -d --entitlements - --xml "$APP" 2>/dev/null | grep -q "get-task-allow"; then51  echo "ERROR: the build carries get-task-allow; it must not be distributed." >&2; exit 152fi53# every Mach-O in the bundle must be signed by the same team with the hardened runtime54bad=055while IFS= read -r -d '' f; do56  if file -b "$f" | grep -q "Mach-O"; then57    info="$(codesign -dvv "$f" 2>&1 || true)"58    echo "$info" | grep -q "TeamIdentifier=3YM54G49SN" || { echo "   NOT SIGNED BY TEAM: $f"; bad=1; }59    echo "$info" | grep -q "flags=.*runtime" || { echo "   NO HARDENED RUNTIME: $f"; bad=1; }60  fi61done < <(find "$APP" -type f -print0)62[[ $bad -eq 0 ]] || { echo "ERROR: some nested binaries are not correctly signed." >&2; exit 1; }63echo "-- embedded CLI: $("$CLI" version 2>&1 | head -1)"64echo "-- version: $(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "$APP/Contents/Info.plist") ($(/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' "$APP/Contents/Info.plist"))"65echo "RESULT: $APP is built and signed. It is NOT notarized yet (run Scripts/notarize.sh)."66
Files main
Menu

Theme