Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
Mac: one script to sign (Developer ID, hardened runtime) and notarise the app dmg and the Terminal archive; Mac README text for notarised and not notarised builds
Niko1221a2367ca55b49
diff --git a/apps/desktop/tester/README-mac.txt.in b/apps/desktop/tester/README-mac.txt.innew file mode 100644index 000000000..e48f06391--- /dev/null+++ b/apps/desktop/tester/README-mac.txt.in@@ -0,0 +1,37 @@+STRATA FOR MAC - APP (Strata @APP_VERSION@)+==========================================++This is the Strata desktop app for Macs with Apple silicon (M1 or newer). The AI engine (it runs on the Mac's graphics processor through+Metal) is already inside the app, so there is nothing to install for it and no engine to download. Only the AI model itself is+downloaded (from Hugging Face), when you pick one.++File: @APPIMAGE@ (about @SIZE_GB:@APPIMAGE@@ GB)+Checks: sha256 @SHA256:@APPIMAGE@@+ To check your copy, in the Terminal app: shasum -a 256 @APPIMAGE@ - the long number must be the same.+++WHAT YOU NEED+-------------+* A Mac with Apple silicon (M1 or newer) and macOS 11 or newer. Intel Macs are not supported.+* Memory: 32 GB or more is best. The model list shows what fits your Mac.+* Disk: about 1 GB for the app, plus 40 to 70 GB for each model you download.+++START IT+--------+1. Double-click @APPIMAGE@. A window opens with Strata and the Applications folder.+2. Drag Strata onto Applications.+3. Open Strata from Applications (or Launchpad). The first start takes a little longer, because the engine inside the app is copied+ into your home folder. Then open the Models page, pick a model and press the install button. A model download is big; it carries+ on where it stopped if it is interrupted.++Closing the window stops Strata and its engine.+++@INCLUDE:common-gatekeeper-mac.txt@+++WHAT TO SEND BACK+-----------------+Open Settings > Engine > Diagnostics > View logs > Save logs. Send the saved file, plus a few words about what you did and what you saw+(a photo of the screen is fine).diff --git a/apps/desktop/tester/common-gatekeeper-mac.txt b/apps/desktop/tester/common-gatekeeper-mac.txtnew file mode 100644index 000000000..52e92303a--- /dev/null+++ b/apps/desktop/tester/common-gatekeeper-mac.txt@@ -0,0 +1,27 @@+IF MACOS WILL NOT OPEN IT ("damaged", "cannot be opened", "unidentified developer")+----------------------------------------------------------------------------------+Nothing is wrong with the file. macOS puts a "downloaded from the internet" mark (the quarantine flag) on everything a browser or+Mail saves, and it only lets a marked program run if Apple has checked it. There are two kinds of build:++* A NOTARISED build (Apple has checked it; Strata signs and notarises its release builds). It just opens:+ double-click the .dmg, drag Strata onto Applications, open Strata. The first time, macOS says "Strata is an app downloaded from+ the Internet. Are you sure you want to open it?" - press Open. That is the same for every app you download; there is nothing to+ type and no setting to change. A notarised .zip of the Terminal works the same way: unzip it and run it.+ To see which kind you have: spctl -a -vv /Applications/Strata.app+ A notarised build answers "accepted" and "source=Notarized Developer ID".++* A build that is NOT notarised (a test build sent to you before it was signed, or one you built yourself). macOS may say+ "Strata is damaged and can't be opened. You should move it to the Trash" or "Apple could not verify Strata is free of malware".+ Do NOT move it to the Trash. The file is fine; you tell macOS once that you trust it by removing the download mark.+ Open the Terminal app (Finder, Applications, Utilities, Terminal) and type ONE of these, matching what you have:++ the .dmg file, before opening it: xattr -dr com.apple.quarantine ~/Downloads/@APPIMAGE@+ the app, after dragging it over: xattr -dr com.apple.quarantine /Applications/Strata.app+ an unzipped Terminal folder: xattr -dr com.apple.quarantine <the folder you unzipped>++ (If the file is somewhere other than Downloads, type the path to it; you can drag the file from Finder into the Terminal window to+ write its path for you.) Then open it again as usual. If macOS only says "cannot be opened because the developer cannot be+ verified" (not "damaged"), there is a second way without the Terminal: try to open it once, then System Settings > Privacy &+ Security, scroll down to the message about Strata and press "Open Anyway".++ Installs that use "curl ... | sh" never get the download mark, so they need none of this.diff --git a/packaging/mac/README.md b/packaging/mac/README.mdnew file mode 100644index 000000000..7cfbf3746--- /dev/null+++ b/packaging/mac/README.md@@ -0,0 +1,75 @@+# Signing and notarising the Mac builds++`sign-and-notarize.sh` signs the Strata Mac app (a `.dmg` or a `.app`) and the Mac Terminal archive with the Developer ID Application+certificate, sends them to Apple's notary service, staples the ticket where that is possible, and checks the result. After it, macOS+opens the app without the "damaged" / "unidentified developer" warning.++It has to run on the Mac that holds the certificate. It never asks for, reads or stores a password or a key: `codesign` and+`notarytool` take them from the Keychain. The only names in it are the certificate (`Developer ID Application: Niko Veit (79LR4R7RSC)`)+and the notarytool profile (`strata-notary`); `SIGN_ID` and `NOTARY_PROFILE` override them.++## What to type (once per build)++1. Put these on the Mac in one folder: `sign-and-notarize.sh`, `entitlements-node.plist` (they must stay together), and the file(s) to sign,+ for example `Strata-tester-mac.dmg` and `Strata-Terminal-Mac.zip`.+2. Open Terminal and go to that folder: `cd ~/Downloads/sign`+3. Check the two things the script needs (both should answer without an error):++ security find-identity -v -p codesigning # lists "Developer ID Application: Niko Veit (79LR4R7RSC)"+ xcrun notarytool history --keychain-profile strata-notary++4. Run it (the app and the Terminal archive together; either part can be left out):++ bash sign-and-notarize.sh Strata-tester-mac.dmg --terminal Strata-Terminal-Mac.zip++ macOS may ask once whether `codesign` may use the key in your Keychain: type your Mac login password and choose "Always Allow".+ Then wait: Apple's check takes a few minutes per file (up to about 15 minutes each; the script waits and prints when it is done).+5. Read the summary at the end. Every line is `OK`; the finished files are in the `signed` folder next to the input, with their sha256+ (also in `signed/SHA256SUMS.txt`) and the full log (`signed/sign-and-notarize.log`).+6. If a line says `FAIL`, the run stopped there. If Apple rejected a file, the script prints Apple's log and saves it as+ `signed/notary-log-*.json`. Send us that file (it contains file names and reasons, no secrets).++A trial run that signs ad-hoc and sends nothing to Apple: add `--dry-run` (no certificate needed).++## What it does++1. Copies the `.app` out of the dmg into a temporary folder (the original is never changed).+2. Signs every Mach-O inside it, deepest first (node, python, every `.dylib`, `.so` and `.node`, the engine, `rg`, `spawn-helper`,+ the app's own program): hardened runtime and a secure timestamp. Then signs the `.app`.+3. Rewrites `engine-component.json` for the engine it just signed. Control checks every engine file against the SHA-256 in that file, and+ signing changes the engine binary, so without this step the signed app would refuse its own engine.+4. `codesign --verify --deep --strict`, `spctl -a -vvv`.+5. Runs the signed copy before Apple sees it: the app's own `--self-test` (private node, host, UI, Control), every native addon loaded in+ the signed node, the bundled python (numpy, PIL, ctypes callbacks), the engine's `--version` (no model is loaded), and Control's own+ check of the engine manifest. A signing mistake shows up here, not on a tester's Mac.+6. Notarises the `.app`, staples it, rebuilds the dmg (the app, an Applications link, the volume icon, as in+ `apps/desktop/scripts/make-dmg.sh`), signs the dmg, notarises and staples it, then `spctl -a -t open --context context:primary-signature -vv`.+7. Terminal archive: signs every Mach-O inside, packs it again in the format it came in (`.zip` or `.tar.gz`), and notarises it.+ A finished file is written to `signed/` only after every step for it has passed.++## Entitlements (each one is a hole in the hardened runtime)++Only the bundled Node gets one: `com.apple.security.cs.allow-jit` (`entitlements-node.plist`, with the measurements). Python, the engine,+the app shell and all libraries get none. `disable-library-validation` is not used: library validation only refuses a library signed+by somebody else, and every library in these bundles is re-signed with the one identity. If a tester ever reports a "different Team IDs"+error for a library that is not in the bundle (for example an addon an MCP server installs and loads with this node), add that key to+`entitlements-node.plist` and run the script again.++The engine components the app downloads later (`strata update`) are unpacked by Control without the download mark, run as their own+processes, and are not hardened by the app's runtime (a child process is not bound by its parent's hardened runtime), so unsigned+components keep working. The engine copied out of the app's bundle keeps our signature; it needs no entitlement (Metal compiles the+kernel sources through the system compiler service, tested under the hardened runtime).++## The Terminal zip++Apple cannot staple a ticket to bare command-line programs in a zip. The zip is still notarised (Apple records the programs by hash),+and macOS looks that up online the first time a browser-downloaded copy is opened. Installs done with `curl ... | sh` are not+quarantined at all, so this mainly helps zips downloaded in a browser.++Signing changes the bytes of the zip and of every program inside, so:++* a checksum list or signed feed (`strata-feed.json`, `*.manifest.json`) that names the old zip or archive must be rebuilt from the new one;+* an archive that holds a *feed* (the tester Terminal zip: scripts plus `feed/*.tar.gz`) has no program at its top level. By default+ the nested `.tar.gz` files are left alone (they are unpacked by command-line tools and carry no download mark). `--sign-nested`+ signs inside them and packs them again, but then the feed's `sha256` entries and its signature (`strata-feed.json.sig`, made with the+ release key) no longer match and the feed has to be regenerated and re-signed.diff --git a/packaging/mac/entitlements-node.plist b/packaging/mac/entitlements-node.plistnew file mode 100644index 000000000..415479c21--- /dev/null+++ b/packaging/mac/entitlements-node.plist@@ -0,0 +1,32 @@+<?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>+ <!-- The entitlements for the bundled Node runtime (Contents/Resources/node/node), the only program in the app or the Terminal+ archive that needs any. sign-and-notarize.sh gives every other Mach-O none.++ com.apple.security.cs.allow-jit+ V8 compiles JavaScript, regular expressions and WebAssembly to machine code at run time and writes it into memory mapped+ with MAP_JIT. The hardened runtime refuses that mapping unless this is set. Measured on a Mac mini M4 (macOS 27.2) with+ a hardened-runtime build of Node 24.12.0: without it node dies at start ("Fatal process out of memory: Failed to reserve+ virtual memory for CodeRange"); with only this one, a 30-million-iteration JIT loop, a backtracking regexp and a+ WebAssembly module run. The native addons of the Harness (koffi, node-pty, sharp, the system addon) load in a dry run, where+ an ad-hoc signature has no Team ID and library validation is therefore switched off for the test; with the real Developer+ ID they are checked for the same Team ID, which they share because sign-and-notarize.sh signs them all (it loads every one+ of them in the signed node before it asks Apple anything).++ Deliberately NOT here (Node's own release is signed with all of them, plus get-task-allow):+ com.apple.security.cs.allow-unsigned-executable-memory not needed, see above+ com.apple.security.cs.disable-executable-page-protection not needed+ com.apple.security.cs.allow-dyld-environment-variables we never rely on DYLD_* variables+ com.apple.security.get-task-allow debug builds only; Apple rejects it for notarisation+ com.apple.security.cs.disable-library-validation+ Library validation makes a hardened program load only libraries signed by Apple or by the same Team ID. Every addon and+ library in these bundles is re-signed by sign-and-notarize.sh with the one Developer ID, so they match. Add this key+ ONLY if a tester reports "code signature ... different Team IDs" when Strata loads a library that is not part of the+ bundle (for example a native addon an MCP server installs into the user's folder and loads with this node).+ -->+ <key>com.apple.security.cs.allow-jit</key>+ <true/>+</dict>+</plist>diff --git a/packaging/mac/sign-and-notarize.sh b/packaging/mac/sign-and-notarize.shnew file mode 100755index 000000000..8b1188f99--- /dev/null+++ b/packaging/mac/sign-and-notarize.sh@@ -0,0 +1,668 @@+#!/usr/bin/env bash+# Sign the Strata Mac app (dmg or .app) and, optionally, the Mac Terminal archive with the owner's Developer ID, then notarise+# them with Apple, so macOS opens them without the "damaged" / "unidentified developer" warning.+#+# bash sign-and-notarize.sh <Strata-tester-mac.dmg | Strata.app> [--terminal <Strata-Terminal-Mac.zip>] [--out DIR] [--dry-run]+# bash sign-and-notarize.sh --terminal <Strata-Terminal-Mac.zip> # the Terminal archive alone+#+# This script runs on the OWNER'S Mac, where the certificate "Developer ID Application: Niko Veit (79LR4R7RSC)" is in the Keychain and the+# notarytool keychain profile "strata-notary" exists. It never asks for, reads or stores a password or a key: codesign and notarytool+# take them from the Keychain themselves. Nothing is uploaded except what notarytool sends to Apple's notary service.+#+# Environment overrides (the defaults are the owner's values):+# SIGN_ID the signing identity (default: Developer ID Application: Niko Veit (79LR4R7RSC))+# NOTARY_PROFILE the notarytool keychain profile (default: strata-notary)+# TMPDIR where the work folder is made (needs about 4 x the size of the input free)+#+# --dry-run: no Apple account is touched. Signs with the ad-hoc identity (SIGN_ID=-), skips notarytool/stapler/spctl-accept, and is+# how this script is tested on a Mac that has no certificate. An ad-hoc signature has no Team ID, so in a dry run the hardened-runtime+# "library validation" cannot be satisfied by libraries signed with the same identity; the dry run therefore adds+# com.apple.security.cs.disable-library-validation to node and python ONLY so that the smoke tests can run. A real run never does.+#+# What it does, in order (each step prints OK or FAIL; the first FAIL stops the run and the summary says which):+# 1. copies the .app out of the dmg into a temporary folder;+# 2. signs every nested Mach-O inside-out (deepest first): hardened runtime, secure timestamp, entitlements only where needed;+# 3. rewrites the SHA-256 and size of every engine file it signed in the engine package's engine-component.json (Control refuses an+# engine whose files do not match that manifest), then signs the .app itself;+# 4. codesign --verify --deep --strict, spctl -a -vvv;+# 5. smoke tests of the SIGNED copy (the app's own --self-test, node loading every native addon, python imports, the engine's --version,+# and Control's own engine manifest check), so a signing mistake shows up here and not on a tester's Mac;+# 6. notarises the .app, staples it, rebuilds the dmg (same layout as apps/desktop/scripts/make-dmg.sh), signs the dmg, notarises the dmg,+# staples it, spctl -a -t open --context context:primary-signature -vv;+# 7. Terminal archive: signs every Mach-O inside, re-zips, notarises the zip (a zip cannot be stapled: see the note at the end).+set -u+set -o pipefail++SIGN_ID="${SIGN_ID:-Developer ID Application: Niko Veit (79LR4R7RSC)}"+NOTARY_PROFILE="${NOTARY_PROFILE:-strata-notary}"+HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"+ENT_NODE_SRC="$HERE/entitlements-node.plist"++INPUT=""; TERMINAL=""; OUT=""; DRY=0; KEEP=0; SIGN_NESTED=0+WORK=""+LOG=""+declare -a RESULTS=()+declare -a MOUNTS=()+declare -a FINAL=()+NOTARY_ID=""++usage() {+ sed -n '2,/^set -u$/p' "${BASH_SOURCE[0]}" | sed '$d' | sed 's/^# \{0,1\}//'+ exit "${1:-2}"+}++while [ $# -gt 0 ]; do+ case "$1" in+ --terminal) [ $# -ge 2 ] || usage; TERMINAL="$2"; shift 2 ;;+ --out) [ $# -ge 2 ] || usage; OUT="$2"; shift 2 ;;+ --dry-run) DRY=1; shift ;;+ --keep-work) KEEP=1; shift ;;+ --sign-nested) SIGN_NESTED=1; shift ;;+ -h|--help) usage 0 ;;+ -*) echo "unknown option: $1" >&2; usage ;;+ *) if [ -z "$INPUT" ]; then INPUT="$1"; shift; else echo "unexpected argument: $1" >&2; usage; fi ;;+ esac+done+[ -n "$INPUT" ] || [ -n "$TERMINAL" ] || usage++# ----------------------------------------------------------------------------------------------------------------- output helpers+say() { printf '%s\n' "$*"; [ -z "$LOG" ] || printf '%s\n' "$*" >>"$LOG"; }+rec() { RESULTS+=("$1|$2|${3:-}"); say " [$1] $2${3:+: $3}"; }++summary() {+ local rc=$1 line st name detail f sum+ say ""+ say "================================ SUMMARY ================================"+ if [ "${#RESULTS[@]}" -gt 0 ]; then+ for line in "${RESULTS[@]}"; do+ st="${line%%|*}"; line="${line#*|}"; name="${line%%|*}"; detail="${line#*|}"+ printf ' %-5s %s%s\n' "$st" "$name" "${detail:+ ($detail)}"+ done+ fi+ if [ "${#FINAL[@]}" -gt 0 ]; then+ say ""+ say "Final files:"+ for f in "${FINAL[@]}"; do+ sum="$(shasum -a 256 "$f" | awk '{print $1}')"+ say " $f"+ say " sha256 $sum"+ [ -z "$OUT" ] || printf '%s %s\n' "$sum" "$(basename "$f")" >>"$OUT/SHA256SUMS.txt"+ done+ fi+ say ""+ if [ "$rc" -eq 0 ]; then+ if [ "$DRY" -eq 1 ]; then say "RESULT: DRY RUN finished. Nothing was sent to Apple; these files are ad-hoc signed and are NOT for release."+ else say "RESULT: all steps OK."; fi+ else+ say "RESULT: FAILED. Read the FAIL line above. Full log: ${LOG:-none}"+ fi+ if [ -n "$TERMINAL" ]; then+ say ""+ say "Note on the Terminal zip: Apple cannot staple a ticket to bare command-line programs in a zip, so the zip carries no ticket. Notarisation is"+ say "still recorded at Apple by the programs' hashes, and macOS checks that online the first time a quarantined (browser-downloaded) copy is opened."+ say "Offline, the first open of such a copy needs a connection. Installs done with 'curl | sh' are not quarantined at all, so this mainly helps zips"+ say "downloaded in a browser. The zip's sha256 changed: any feed or checksum list that names the old zip must be rebuilt from this one."+ fi+}++finish() { summary "$1"; exit "$1"; }+fail() { rec FAIL "$1" "${2:-}"; finish 1; }++# shellcheck disable=SC2329 # run by the EXIT trap below+cleanup() {+ local m+ if [ "${#MOUNTS[@]}" -gt 0 ]; then+ for m in "${MOUNTS[@]}"; do hdiutil detach "$m" -force >/dev/null 2>&1 || true; done+ fi+ if [ -n "$WORK" ] && [ -d "$WORK" ]; then+ if [ "$KEEP" -eq 1 ]; then echo "work folder kept: $WORK" >&2; else rm -rf "$WORK"; fi+ fi+}+trap cleanup EXIT+trap 'echo "interrupted" >&2; exit 130' INT TERM HUP++# run a command, appending all its output to the log; on failure show the last lines of it+logged() {+ local tmp rc+ tmp="$(mktemp "${WORK:-${TMPDIR:-/tmp}}/cmd.XXXXXX")"+ "$@" >"$tmp" 2>&1; rc=$?+ cat "$tmp" >>"${LOG:-/dev/null}"+ [ "$rc" -eq 0 ] || { tail -n 12 "$tmp" | sed 's/^/ /' >&2; }+ rm -f "$tmp"+ return "$rc"+}++# run a command with a time limit (macOS has no timeout(1)); 124 = timed out+run_timeout() {+ local secs=$1 i=0 pid+ shift+ "$@" &+ pid=$!+ while kill -0 "$pid" 2>/dev/null; do+ if [ "$i" -ge $((secs * 2)) ]; then+ pkill -P "$pid" 2>/dev/null; kill "$pid" 2>/dev/null; sleep 1; kill -9 "$pid" 2>/dev/null+ wait "$pid" 2>/dev/null+ return 124+ fi+ sleep 0.5; i=$((i + 1))+ done+ wait "$pid"+}++# ----------------------------------------------------------------------------------------------------------------- preflight+[ "$(uname -s)" = Darwin ] || { echo "This script runs on a Mac (it needs codesign, hdiutil, notarytool)." >&2; exit 2; }+for tool in codesign hdiutil ditto shasum file xattr perl PlistBuddy; do+ if [ "$tool" = PlistBuddy ]; then [ -x /usr/libexec/PlistBuddy ] || { echo "missing /usr/libexec/PlistBuddy" >&2; exit 2; }+ else command -v "$tool" >/dev/null 2>&1 || { echo "missing tool: $tool" >&2; exit 2; }; fi+done++if [ "$DRY" -eq 1 ]; then+ SIGN_ID="-"+else+ command -v xcrun >/dev/null 2>&1 || { echo "missing xcrun (install the Xcode command line tools: xcode-select --install)" >&2; exit 2; }+fi+if [ "$DRY" -eq 1 ]; then :+elif [ "$SIGN_ID" = "-" ]; then+ echo "SIGN_ID=- is an ad-hoc signature, which Apple cannot notarise. Add --dry-run to test with it." >&2; exit 2+fi++[ -z "$INPUT" ] || [ -e "$INPUT" ] || { echo "not found: $INPUT" >&2; exit 2; }+[ -z "$TERMINAL" ] || [ -f "$TERMINAL" ] || { echo "not found: $TERMINAL" >&2; exit 2; }++if [ -z "$OUT" ]; then+ first="${INPUT:-$TERMINAL}"+ OUT="$(cd "$(dirname "$first")" && pwd)/signed"+fi+mkdir -p "$OUT" || { echo "cannot create $OUT" >&2; exit 2; }+OUT="$(cd "$OUT" && pwd)"+WORK="$(mktemp -d "${TMPDIR:-/tmp}/strata-sign.XXXXXX")" || { echo "cannot make a work folder" >&2; exit 2; }+LOG="$OUT/sign-and-notarize.log"+: >"$LOG"+: >"$OUT/SHA256SUMS.txt"+say "Strata sign-and-notarize, $(date '+%Y-%m-%d %H:%M:%S')"+say " identity : $SIGN_ID"+if [ "$DRY" -eq 1 ]; then say " mode : DRY RUN (ad-hoc, no notarisation)"; else say " profile : $NOTARY_PROFILE"; fi+say " work : $WORK"+say " output : $OUT"+say ""++need_kb=0+for f in "$INPUT" "$TERMINAL"; do+ [ -n "$f" ] || continue+ kb="$(du -sk "$f" | awk '{print $1}')"; need_kb=$((need_kb + kb * 5))+done+free_kb="$(df -k "$WORK" | awk 'NR==2 {print $4}')"+if [ "$free_kb" -lt "$need_kb" ]; then+ fail "free space" "about $((need_kb / 1048576)) GB needed in $WORK, $((free_kb / 1048576)) GB free; set TMPDIR to a bigger disk"+fi++if [ "$DRY" -eq 0 ]; then+ if ! security find-identity -v -p codesigning 2>/dev/null | grep -qF "\"$SIGN_ID\""; then+ fail "signing identity" "\"$SIGN_ID\" is not in your Keychain (security find-identity -v -p codesigning lists what is)"+ fi+ if ! xcrun notarytool history --keychain-profile "$NOTARY_PROFILE" >/dev/null 2>&1; then+ fail "notary profile" "profile \"$NOTARY_PROFILE\" does not work (create it once: xcrun notarytool store-credentials $NOTARY_PROFILE ...), or there is no internet"+ fi+ rec OK "preflight" "identity and notary profile found"+else+ rec OK "preflight" "dry run, ad-hoc identity"+fi++# ----------------------------------------------------------------------------------------------------------------- entitlements+# Every entitlement is a hole in the hardened runtime, so there are as few as work (each one was tested; see entitlements-node.plist).+# node: com.apple.security.cs.allow-jit (V8 writes machine code into MAP_JIT memory; without it node dies at start with+# "Failed to reserve virtual memory for CodeRange"). Nothing else: WebAssembly, regexp JIT and the native addons run with just this.+# python, the engine, the app shell, rg, spawn-helper, every .dylib/.so/.node: none. (Python's ctypes callbacks and numpy run without any;+# Metal compiles the engine's kernel sources through the system compiler service, which needs nothing from the engine process.)+# disable-library-validation: NOT used. It would only be needed if a hardened program loaded a library signed by somebody else; every+# library in these bundles is re-signed here with the one identity, so they share a Team ID. (Dry run only: see the header.)+ENT_NODE="$ENT_NODE_SRC"+ENT_DLV=""+if [ "$DRY" -eq 1 ]; then+ ENT_DLV="$WORK/dlv.plist"+ ENT_NODE="$WORK/node-dryrun.plist"+ cp "$ENT_NODE_SRC" "$ENT_NODE"+ /usr/libexec/PlistBuddy -c "Add :com.apple.security.cs.disable-library-validation bool true" "$ENT_NODE" >/dev/null+ printf '<?xml version="1.0" encoding="UTF-8"?>\n<plist version="1.0"><dict><key>com.apple.security.cs.disable-library-validation</key><true/></dict></plist>\n' >"$ENT_DLV"+fi+[ -f "$ENT_NODE_SRC" ] || fail "entitlements" "missing $ENT_NODE_SRC (keep it next to this script)"++ent_for() {+ case "$(basename "$1")" in+ node) printf '%s' "$ENT_NODE" ;;+ python|python3|python3.[0-9]*) printf '%s' "$ENT_DLV" ;; # empty in a real run+ *) printf '' ;;+ esac+}++# ----------------------------------------------------------------------------------------------------------------- signing helpers+# Every Mach-O (programs, .dylib, .so, .node, universal binaries), deepest path first. Object files cannot be signed and are skipped.+find_macho() {+ find "$1" -type f -print0 2>/dev/null | xargs -0 file --mime-type 2>/dev/null \+ | sed -n 's/:[[:space:]]*application\/x-mach-binary$//p' | sed 's/ (for architecture [^)]*)$//' | sort -u \+ | while IFS= read -r f; do+ case "$(file -b "$f")" in *object*|*"core file"*) continue ;; esac+ printf '%s\n' "$f"+ done \+ | awk '{ n = gsub("/", "/"); print n "\t" $0 }' | sort -rn | cut -f2-+}++codesign_item() { # path [extra codesign args...]+ local f=$1 ent try=1 rc=1+ shift+ local -a args=(--force --sign "$SIGN_ID" --options runtime)+ if [ "$SIGN_ID" = "-" ]; then args+=(--timestamp=none); else args+=(--timestamp); fi+ ent="$(ent_for "$f")"+ [ -z "$ent" ] || args+=(--entitlements "$ent")+ while [ "$try" -le 3 ]; do+ logged codesign "${args[@]}" "$@" "$f" && { rc=0; break; }+ say " (attempt $try of 3 failed; the timestamp server is sometimes slow)"+ try=$((try + 1)); sleep 3+ done+ return "$rc"+}++codesign_plain() { # a disk image: signature and secure timestamp, no hardened-runtime flag (that flag is for programs)+ local f=$1 try=1+ local -a args=(--force --sign "$SIGN_ID")+ if [ "$SIGN_ID" = "-" ]; then args+=(--timestamp=none); else args+=(--timestamp); fi+ while [ "$try" -le 3 ]; do+ logged codesign "${args[@]}" "$f" && return 0+ try=$((try + 1)); sleep 3+ done+ return 1+}++sign_tree() { # folder label: all Mach-O inside-out, then nested bundles+ local dir=$1 label=$2 f n=0 bad=0 d+ while IFS= read -r f; do+ [ -n "$f" ] || continue+ if codesign_item "$f"; then n=$((n + 1)); else say " could not sign: $f"; bad=$((bad + 1)); fi+ done < <(find_macho "$dir")+ [ "$bad" -eq 0 ] || fail "sign $label" "$bad file(s) could not be signed (see the log)"+ # nested bundles (frameworks, helper apps, XPC services), deepest first; there are none in today's app+ while IFS= read -r d; do+ [ -n "$d" ] || continue+ [ "$d" != "$dir" ] || continue+ if [ -f "$d/Contents/Info.plist" ] || [ -f "$d/Resources/Info.plist" ] || [ -d "$d/Versions" ]; then+ codesign_item "$d" || fail "sign $label" "nested bundle $d"+ fi+ done < <(find "$dir" -type d \( -name '*.app' -o -name '*.framework' -o -name '*.xpc' -o -name '*.appex' \) 2>/dev/null | awk '{ n = gsub("/", "/"); print n "\t" $0 }' | sort -rn | cut -f2-)+ rec OK "sign $label" "$n Mach-O file(s) signed"+}++# The engine packages inside the bundle carry engine-component.json with the SHA-256 and size of every file; Control checks them before it+# starts an engine. Signing changes the engine binary, so the manifest must be brought up to date, or the signed app would refuse its own engine.+update_engine_manifests() { # folder label+ local dir=$1 label=$2 m out rc n=0+ while IFS= read -r m; do+ [ -n "$m" ] || continue+ out="$(perl -MJSON::PP -MDigest::SHA -e '+ my ($file) = @ARGV; local $/; open my $fh, "<", $file or die "cannot read $file\n"; my $raw = <$fh>; close $fh;+ $raw =~ s/^\xEF\xBB\xBF//;+ my $json = JSON::PP->new->utf8->canonical->pretty; my $d = $json->decode($raw);+ (my $dir = $file) =~ s{/[^/]+$}{};+ if (defined $d->{signature}) { print "signed-manifest\n"; exit 3; }+ my $changed = 0;+ for my $e (@{ $d->{files} || [] }) {+ my $p = "$dir/$e->{path}"; next unless -f $p;+ open my $f, "<:raw", $p or die "cannot read $p\n"; my $sha = Digest::SHA->new(256); $sha->addfile($f); close $f;+ my $hex = $sha->hexdigest; my $size = -s $p;+ if (lc($e->{sha256}) ne $hex or $e->{bytes} != $size) { $e->{sha256} = $hex; $e->{bytes} = $size + 0; $changed++; }+ }+ if ($changed) { open my $o, ">", $file or die "cannot write $file\n"; print $o $json->encode($d); close $o; }+ print "$changed\n";+ ' "$m" 2>&1)"; rc=$?+ if [ "$rc" -eq 3 ]; then+ fail "engine manifest $label" "$m carries a release signature; changing a file would break it. Sign this engine package at its source, or re-sign its manifest with the release key"+ elif [ "$rc" -ne 0 ]; then+ fail "engine manifest $label" "$m: $out"+ fi+ n=$((n + 1)); say " $m: $out entry(ies) updated"+ done < <(find "$dir" -name engine-component.json -type f 2>/dev/null)+ rec OK "engine manifests $label" "$n manifest(s) checked"+}++verify_signed() { # path label+ local p=$1 label=$2+ if logged codesign --verify --deep --strict --verbose=2 "$p"; then rec OK "codesign --verify --deep --strict $label"+ else fail "codesign --verify --deep --strict $label" "see the log"; fi+}++# notarytool submit --wait; sets NOTARY_ID. On anything but Accepted, fetches Apple's log and fails.+notarize() { # file label+ local f=$1 label=$2 out status+ out="$WORK/notary-$label.txt"+ say " sending $(basename "$f") to Apple ($(du -h "$f" | awk '{print $1}')); this waits for the result, usually 2 to 15 minutes ..."+ xcrun notarytool submit "$f" --keychain-profile "$NOTARY_PROFILE" --wait --timeout 60m >"$out" 2>&1+ cat "$out" >>"$LOG"+ NOTARY_ID="$(awk '/^ *id:/ {print $2; exit}' "$out")"+ status="$(awk '/^ *status:/ {s = $2} END {print s}' "$out")"+ if [ "$status" = "Accepted" ]; then+ rec OK "notarise $label" "Accepted, submission $NOTARY_ID"+ return 0+ fi+ if [ -n "$NOTARY_ID" ]; then+ xcrun notarytool log --keychain-profile "$NOTARY_PROFILE" "$NOTARY_ID" "$OUT/notary-log-$label.json" >>"$LOG" 2>&1+ say ""+ say "---- Apple's notarisation log for $label (submission $NOTARY_ID), also saved to $OUT/notary-log-$label.json ----"+ cat "$OUT/notary-log-$label.json" 2>/dev/null | tee -a "$LOG"+ say "-------------------------------------------------------------------------------"+ else+ tail -n 15 "$out" | sed 's/^/ /'+ fi+ fail "notarise $label" "status: ${status:-no answer from notarytool}"+}++# a finished file goes to the output folder only when every step for it has passed, so a half-done file is never mistaken for a release+deliver() { # file original+ local f=$1 orig=$2 dest+ dest="$OUT/$(basename "$f")"+ if [ -e "$dest" ] && [ "$dest" -ef "$orig" ]; then fail "write the result" "$dest is the input file itself; choose another --out folder"; fi+ cp -p "$f" "$dest" || fail "write the result" "cannot write $dest"+ FINAL+=("$dest")+}++zip_dir() { # src_dir out.zip (keeps symlinks and permissions, no AppleDouble clutter)+ ditto -c -k --norsrc --noextattr --noqtn --noacl --keepParent "$1" "$2"+}++# ----------------------------------------------------------------------------------------------------------------- smoke tests (signed copy)+smoke_app() { # app+ local app=$1 res="$1/Contents/Resources" home="$WORK/smokehome" rep="$WORK/self-test.json" node py ctl rc f fails=0 out r engines=0+ mkdir -p "$home"+ node="$res/node/node"; ctl="$res/control"; py="$ctl/python/bin/python3"+ export PYTHONDONTWRITEBYTECODE=1 PYTHONNOUSERSITE=1 # a smoke test must not write into the sealed bundle++ # 1. the app's own headless self-test: private node, host, UI, Control on the bundled python+ run_timeout 150 env HOME="$home" "$app/Contents/MacOS/strata-desktop" --self-test="$rep" >"$WORK/selftest.out" 2>&1; rc=$?+ cat "$WORK/selftest.out" >>"$LOG"+ if [ "$rc" -eq 0 ]; then rec OK "smoke: app --self-test (host, UI, Control)"+ else+ grep -E '"(name|ok|detail)"' "$rep" 2>/dev/null | paste - - - | grep 'false' | sed 's/^/ /'+ fail "smoke: app --self-test" "exit $rc; the signed app cannot start its host (see the log)"+ fi++ # 2. every native addon loads in the signed, hardened node (library validation, JIT)+ if [ -x "$node" ]; then+ out="$WORK/addons.txt"; : >"$out"+ while IFS= read -r f; do+ case "$(file -b "$f")" in *arm64*) ;; *) continue ;; esac+ r="$("$node" -e 'try { process.dlopen({ exports: {} }, process.argv[1]); console.log("OK"); } catch (e) { console.log("ERR " + String(e.message).split("\n")[0]); }' "$f" 2>&1 | head -n 1)"+ [ -n "$r" ] || r="ERR killed by the system (code signature)"+ printf '%s: %s\n' "$f" "$r" >>"$out"+ done < <(find "$res" -name '*.node' -type f 2>/dev/null)+ cat "$out" >>"$LOG"+ if grep -qiE 'code signature|team id|library validation|not valid for use|killed' "$out"; then+ grep -iE 'code signature|team id|library validation|not valid for use' "$out" | sed 's/^/ /'+ fail "smoke: node loads its native addons" "library validation refuses an addon (a library with a different signature)"+ fi+ if ! "$node" -e 'WebAssembly.instantiate(new Uint8Array([0,97,115,109,1,0,0,0])).then(()=>{let s=0;for(let i=0;i<2e6;i++)s+=i%7;if(!/a+b/.test("aab"))process.exit(3);console.log("jit ok")})' >>"$LOG" 2>&1; then+ fail "smoke: node JIT and WebAssembly" "the hardened node cannot run JIT code (entitlement missing?)"+ fi+ rec OK "smoke: node JIT, WebAssembly and native addons" "$(grep -c ': OK' "$out") addon(s) loaded"+ else+ rec SKIP "smoke: node" "no bundled node"+ fi++ # 3. Control's python imports its compiled modules+ if [ -x "$py" ]; then+ if (cd "$ctl" && env HOME="$home" "$py" -c '+import ctypes, importlib, sys+for m in ("numpy", "PIL.Image", "psutil", "yaml", "regex", "charset_normalizer", "markupsafe", "ssl", "sqlite3", "zlib", "lzma", "hashlib"):+ try: importlib.import_module(m)+ except ModuleNotFoundError: pass+cb = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_void_p, ctypes.c_void_p)(lambda a, b: 0)+arr = (ctypes.c_int * 4)(4, 3, 2, 1); ctypes.CDLL(None).qsort(arr, 4, 4, cb)+print("python ok", sys.version.split()[0])' >>"$LOG" 2>&1); then rec OK "smoke: bundled python imports and ctypes callbacks"+ else fail "smoke: bundled python" "an import or a ctypes callback failed under the hardened runtime (see the log)"; fi+ fi++ # 4. every bundled engine starts, and Control accepts its manifest (hashes of the signed files)+ while IFS= read -r f; do+ [ -n "$f" ] || continue+ engines=$((engines + 1))+ if run_timeout 30 "$f" --version >"$WORK/engine-version.txt" 2>&1; then say " $(head -n 1 "$WORK/engine-version.txt")"; else+ cat "$WORK/engine-version.txt" >>"$LOG"; fails=$((fails + 1)); say " engine did not start: $f"+ fi+ done < <(find "$res/engine-bundle" -mindepth 2 -maxdepth 2 -type f \( -name strata -o -name strata-device \) 2>/dev/null)+ [ "$fails" -eq 0 ] || fail "smoke: bundled engine starts" "$fails engine(s) did not start under the hardened runtime"+ if [ -x "$py" ] && [ -d "$res/engine-bundle" ]; then+ out="$(cd "$ctl" && env HOME="$home" "$py" -c '+import sys, pathlib+from strata_control import engine_component as ec+bad = 0; n = 0+for m in sorted(pathlib.Path(sys.argv[1]).glob("*/engine-component.json")):+ n += 1+ try:+ c = ec.read_manifest(m.parent); ec.verify(c, full=True); print("manifest ok", c.version, c.platform, c.backend)+ except Exception as e:+ bad += 1; print("MANIFEST PROBLEM", m, type(e).__name__, e)+sys.exit(1 if bad or not n else 0)' "$res/engine-bundle" 2>&1)"; rc=$?+ printf '%s\n' "$out" >>"$LOG"+ if [ "$rc" -eq 0 ]; then rec OK "smoke: engine manifest matches the signed files (Control's own check)"+ else printf '%s\n' "$out" | sed 's/^/ /'; fail "smoke: engine manifest" "Control would refuse the signed engine"; fi+ fi+ if [ "$engines" -gt 0 ]; then rec OK "smoke: bundled engine --version" "$engines engine(s), no model loaded"; else rec SKIP "smoke: bundled engine" "this app carries no engine"; fi+}++smoke_terminal() { # extracted terminal folder+ local root=$1 py f strata home="$WORK/termhome" out+ mkdir -p "$home"+ export PYTHONDONTWRITEBYTECODE=1 PYTHONNOUSERSITE=1+ py="$(find "$root" -maxdepth 4 -path '*/python/bin/python3' -type f 2>/dev/null | head -n 1)"+ if [ -n "$py" ]; then+ if env HOME="$home" "$py" -c 'import ctypes, ssl, sqlite3, zlib; print("python ok")' >>"$LOG" 2>&1; then rec OK "smoke: terminal python starts"+ else fail "smoke: terminal python" "does not start under the hardened runtime"; fi+ strata="$(dirname "$py")/../../bin/strata"+ if [ -x "$strata" ]; then+ if out="$(env HOME="$home" STRATA_NO_ACQUIRE=1 "$strata" --version 2>&1)"; then rec OK "smoke: strata --version" "$(printf '%s' "$out" | head -n 1)"+ else printf '%s\n' "$out" | tail -n 5 | sed 's/^/ /'; fail "smoke: strata --version" "the Terminal launcher does not start"; fi+ fi+ else+ rec SKIP "smoke: terminal python" "no bundled python in this archive"+ fi+ while IFS= read -r f; do+ [ -n "$f" ] || continue+ run_timeout 30 "$f" --version >>"$LOG" 2>&1 || fail "smoke: engine in the Terminal archive" "$f does not start"+ done < <(find "$root" -type f \( -name strata -o -name strata-device \) -perm -u+x 2>/dev/null | while IFS= read -r c; do file "$c" | grep -q 'Mach-O' && printf '%s\n' "$c"; done)+}++# ----------------------------------------------------------------------------------------------------------------- the app+process_app() {+ local app_src="" appdir="$WORK/app" app version vol dmg_name zip out_dmg mnt bundle_real++ mkdir -p "$appdir"+ if [ -d "$INPUT" ] && { [[ "$INPUT" == *.app ]] || [[ "$INPUT" == *.app/ ]]; }; then+ app_src="${INPUT%/}"+ ditto --norsrc --noextattr --noqtn "$app_src" "$appdir/$(basename "$app_src")" || fail "copy the app" "ditto failed"+ app="$appdir/$(basename "$app_src")"+ dmg_name="Strata.dmg"+ rec OK "copy the app" "from $INPUT"+ elif [ -f "$INPUT" ] && [[ "$INPUT" == *.dmg ]]; then+ mnt="$WORK/mnt-in"; mkdir -p "$mnt"+ logged hdiutil attach -nobrowse -readonly -noautoopen -mountpoint "$mnt" "$INPUT" || fail "open the dmg" "hdiutil attach failed (is it already mounted?)"+ MOUNTS+=("$mnt")+ app_src="$(find "$mnt" -maxdepth 1 -name '*.app' -type d | head -n 1)"+ [ -n "$app_src" ] || fail "open the dmg" "no .app at the top of $INPUT"+ ditto --norsrc --noextattr --noqtn "$app_src" "$appdir/$(basename "$app_src")" || fail "copy the app" "ditto failed"+ hdiutil detach "$mnt" >/dev/null 2>&1 || hdiutil detach "$mnt" -force >/dev/null 2>&1+ app="$appdir/$(basename "$app_src")"+ dmg_name="$(basename "$INPUT")"+ rec OK "copy the app out of the dmg" "$(basename "$app") ($(du -sh "$app" | awk '{print $1}'))"+ else+ fail "input" "$INPUT is neither a .dmg nor a .app"+ fi+ [ -f "$app/Contents/Info.plist" ] || fail "input" "$app has no Contents/Info.plist"+ xattr -cr "$app" 2>/dev/null+ version="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$app/Contents/Info.plist" 2>/dev/null || echo "")"++ sign_tree "$app" "app contents"+ update_engine_manifests "$app" "app"+ if codesign_item "$app"; then rec OK "sign the .app itself"; else fail "sign the .app itself" "see the log"; fi++ verify_signed "$app" "app"+ if spctl -a -vvv -t exec "$app" >>"$LOG" 2>&1; then rec OK "spctl -a -vvv app" "accepted"+ elif [ "$DRY" -eq 1 ]; then rec INFO "spctl -a -vvv app" "rejected, as expected for an ad-hoc dry run"+ else rec INFO "spctl -a -vvv app" "rejected before notarisation (source=Unnotarized Developer ID); it is checked again after stapling"; fi++ smoke_app "$app"+ verify_signed "$app" "app after the smoke tests (nothing in the sealed bundle changed)"++ bundle_real="$app"+ if [ "$DRY" -eq 0 ]; then+ zip="$WORK/$(basename "$app" .app)-notarize.zip"+ zip_dir "$app" "$zip" || fail "zip the app for Apple" "ditto failed"+ notarize "$zip" "app"+ logged xcrun stapler staple "$app" || fail "staple the app" "stapler failed"+ logged xcrun stapler validate "$app" || fail "staple the app" "stapler validate failed"+ rec OK "staple the app"+ if spctl -a -vvv -t exec "$app" >>"$LOG" 2>&1; then rec OK "spctl -a -vvv app (after notarisation)" "accepted, Notarized Developer ID"+ else fail "spctl -a -vvv app (after notarisation)" "Gatekeeper still rejects the stapled app"; fi+ rm -f "$zip"+ fi++ # the dmg, same layout as apps/desktop/scripts/make-dmg.sh: the app, an Applications link, the volume icon, no Finder arrangement+ vol="Strata ${version:-app}"+ mkdir -p "$WORK/final"+ out_dmg="$WORK/final/$dmg_name"+ build_dmg "$bundle_real" "$out_dmg" "$vol" || fail "build the dmg" "hdiutil failed (see the log)"+ rec OK "build the dmg" "$vol"+ codesign_plain "$out_dmg" || fail "sign the dmg" "see the log"+ rec OK "sign the dmg"+ if [ "$DRY" -eq 0 ]; then+ notarize "$out_dmg" "dmg"+ logged xcrun stapler staple "$out_dmg" || fail "staple the dmg" "stapler failed"+ logged xcrun stapler validate "$out_dmg" || fail "staple the dmg" "stapler validate failed"+ rec OK "staple the dmg"+ if spctl -a -t open --context context:primary-signature -vv "$out_dmg" >>"$LOG" 2>&1; then rec OK "spctl -a -t open --context context:primary-signature -vv dmg" "accepted"+ else fail "spctl on the dmg" "Gatekeeper rejects the notarised dmg"; fi+ else+ rec INFO "notarise, staple and spctl on the dmg" "skipped in a dry run"+ fi+ logged hdiutil verify "$out_dmg" || fail "hdiutil verify" "the dmg is damaged"+ rec OK "hdiutil verify the dmg"++ # the app inside the finished dmg is still the signed one+ mnt="$WORK/mnt-out"; mkdir -p "$mnt"+ if logged hdiutil attach -nobrowse -readonly -noautoopen -mountpoint "$mnt" "$out_dmg"; then+ MOUNTS+=("$mnt")+ if logged codesign --verify --deep --strict "$mnt/$(basename "$app")"; then rec OK "the app inside the final dmg verifies"+ else hdiutil detach "$mnt" -force >/dev/null 2>&1; fail "the app inside the final dmg" "codesign --verify failed"; fi+ hdiutil detach "$mnt" >/dev/null 2>&1 || hdiutil detach "$mnt" -force >/dev/null 2>&1+ fi+ deliver "$out_dmg" "$INPUT"+}++build_dmg() { # app out.dmg volname+ local app=$1 out=$2 vol=$3 rw="$WORK/rw.dmg" mnt="$WORK/mnt-build" kb mb n=0 icon+ kb="$(du -sk "$app" | awk '{print $1}')"; mb=$((kb * 13 / 10240 + 80))+ rm -f "$rw" "$out"+ logged hdiutil create -size "${mb}m" -fs HFS+ -volname "$vol" -type UDIF -ov "$rw" || return 1+ mkdir -p "$mnt"+ logged hdiutil attach -nobrowse -noautoopen -noverify -mountpoint "$mnt" "$rw" || return 1+ MOUNTS+=("$mnt")+ ditto --norsrc --noextattr --noqtn "$app" "$mnt/$(basename "$app")" || return 1+ ln -s /Applications "$mnt/Applications"+ icon="$app/Contents/Resources/Strata.icns"+ if [ -f "$icon" ] && command -v SetFile >/dev/null 2>&1; then cp "$icon" "$mnt/.VolumeIcon.icns" && SetFile -a C "$mnt" 2>/dev/null; fi+ sync+ until hdiutil detach "$mnt" >/dev/null 2>&1; do+ n=$((n + 1)); [ "$n" -lt 6 ] || { hdiutil detach "$mnt" -force >/dev/null 2>&1; break; }+ sleep 2+ done+ logged hdiutil convert "$rw" -format UDZO -imagekey zlib-level=9 -o "$out" || return 1+ rm -f "$rw"+}++# ----------------------------------------------------------------------------------------------------------------- the Terminal archive+repack_nested() { # extracted root: sign inside .tar.gz/.tgz/.zip archives within the archive (opt-in)+ local root=$1 a tmp kind+ while IFS= read -r a; do+ [ -n "$a" ] || continue+ tmp="$WORK/nested.$$.$RANDOM"; mkdir -p "$tmp"+ case "$a" in+ *.zip) kind=zip; ditto -x -k "$a" "$tmp" ;;+ *) kind=tar; tar -xzf "$a" -C "$tmp" ;;+ esac || { rm -rf "$tmp"; continue; }+ if [ -z "$(find_macho "$tmp" | head -n 1)" ]; then rm -rf "$tmp"; continue; fi+ sign_tree "$tmp" "nested $(basename "$a")"+ update_engine_manifests "$tmp" "nested $(basename "$a")"+ if [ "$kind" = zip ]; then+ ( cd "$tmp" && ditto -c -k --norsrc --noextattr --noqtn --noacl . "$a" )+ else+ ( cd "$tmp" && COPYFILE_DISABLE=1 tar -czf "$a" . )+ fi+ rm -rf "$tmp"+ say " re-packed $(basename "$a"); a signed feed that pins its hash (strata-feed.json) must be regenerated and re-signed with the release key"+ done < <(find "$root" -type f \( -name '*.tar.gz' -o -name '*.tgz' -o -name '*.zip' \) 2>/dev/null)+}++process_terminal() {+ local src=$TERMINAL tdir="$WORK/terminal" top stem final notarize_zip name tops nested+ name="$(basename "$src")"+ mkdir -p "$tdir"+ case "$name" in+ *.zip) ditto -x -k "$src" "$tdir" || fail "unpack the Terminal archive" "ditto failed" ;;+ *.tar.gz|*.tgz) tar -xzf "$src" -C "$tdir" || fail "unpack the Terminal archive" "tar failed" ;;+ *) fail "unpack the Terminal archive" "$name is not a .zip or .tar.gz" ;;+ esac+ rm -rf "$tdir/__MACOSX"+ xattr -cr "$tdir" 2>/dev/null+ rec OK "unpack the Terminal archive" "$name"++ if [ -z "$(find_macho "$tdir" | head -n 1)" ]; then+ nested="$(find "$tdir" -type f \( -name '*.tar.gz' -o -name '*.tgz' -o -name '*.zip' \) 2>/dev/null | wc -l | tr -d ' ')"+ if [ "$SIGN_NESTED" -eq 0 ] && [ "$nested" -gt 0 ]; then+ rec INFO "Terminal archive holds no program directly" "it contains $nested nested archive(s) (a feed folder); use --sign-nested to sign inside them"+ fi+ fi+ sign_tree "$tdir" "terminal"+ update_engine_manifests "$tdir" "terminal"+ [ "$SIGN_NESTED" -eq 0 ] || repack_nested "$tdir"+ if [ "$SIGN_NESTED" -eq 0 ]; then+ nested="$(find "$tdir" -type f \( -name '*.tar.gz' -o -name '*.tgz' \) 2>/dev/null | wc -l | tr -d ' ')"+ [ "$nested" -eq 0 ] || say " $nested nested .tar.gz archive(s) were left untouched (they are installed by command-line tools and are not quarantined)"+ fi++ local bad=0 f+ while IFS= read -r f; do+ [ -n "$f" ] || continue+ codesign --verify --strict "$f" >>"$LOG" 2>&1 || { say " bad signature: $f"; bad=$((bad + 1)); }+ done < <(find_macho "$tdir")+ [ "$bad" -eq 0 ] || fail "codesign --verify --strict (terminal)" "$bad file(s)"+ rec OK "codesign --verify --strict (terminal)" "every Mach-O"++ smoke_terminal "$tdir"++ # pack it again in the format it came in; Apple only takes a zip, so a tar.gz is notarised through a zip of the same files+ tops="$(find "$tdir" -mindepth 1 -maxdepth 1 | wc -l | tr -d ' ')"+ stem="${name%.tar.gz}"; stem="${stem%.tgz}"; stem="${stem%.zip}"+ mkdir -p "$WORK/final"+ case "$name" in *.zip) final="$WORK/final/$stem.zip" ;; *) final="$WORK/final/$stem.tar.gz" ;; esac+ rm -f "$final"+ notarize_zip="$WORK/$stem-notarize.zip"; rm -f "$notarize_zip"+ if [ "$tops" -eq 1 ]; then+ top="$(find "$tdir" -mindepth 1 -maxdepth 1)"+ zip_dir "$top" "$notarize_zip" || fail "pack the Terminal archive" "ditto failed"+ case "$name" in *.zip) ;; *) ( cd "$tdir" && COPYFILE_DISABLE=1 tar -czf "$final" "$(basename "$top")" ) || fail "pack the Terminal archive" "tar failed" ;; esac+ else+ ( cd "$tdir" && ditto -c -k --norsrc --noextattr --noqtn --noacl . "$notarize_zip" ) || fail "pack the Terminal archive" "ditto failed"+ case "$name" in *.zip) ;; *) ( cd "$tdir" && COPYFILE_DISABLE=1 tar -czf "$final" . ) || fail "pack the Terminal archive" "tar failed" ;; esac+ fi+ case "$name" in *.zip) cp "$notarize_zip" "$final" ;; esac+ rec OK "pack the Terminal archive" "$(basename "$final")"++ if [ "$DRY" -eq 0 ]; then+ notarize "$notarize_zip" "terminal"+ rec INFO "staple the Terminal archive" "not possible for bare programs in a zip; Apple holds the ticket online"+ else+ rec INFO "notarise the Terminal archive" "skipped in a dry run"+ fi+ deliver "$final" "$src"+}++# ----------------------------------------------------------------------------------------------------------------- run+if [ -n "$INPUT" ]; then process_app; fi+if [ -n "$TERMINAL" ]; then process_terminal; fi+finish 0