Skip to content

Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.

6.2 KB
Raw Blame
#!/bin/sh
# Signed (+ notarized) Mac installer to share: app/dist/Yogurt-mac-arm64.dmg
# Needs the Developer ID certificate in the keychain and, to notarize, a notarytool profile:
#   xcrun notarytool store-credentials yogurt-notary --apple-id <Apple ID> --team-id 2JNSQVN3N8
# YOGURT_NOTARIZE=0 signs and checks without sending anything to Apple (a build to try on this Mac).
# YOGURT_FUSES=0 leaves Electron's fuses as they come (the inspector on), for the local debugging only: never share it.
# Builds into dist/ only: with another output folder electron-builder packs the whole project.
# To build while a copy from dist/ is running, run this in a separate checkout (git worktree).
set -e
ID="${YOGURT_SIGN_ID:-Christian Mathiesen (2JNSQVN3N8)}"
LOCAL=0
if [ "$ID" = 'Yogurt Local' ]; then
  [ "${YOGURT_NOTARIZE:-1}" = 0 ] || { echo 'Yogurt Local requires YOGURT_NOTARIZE=0' >&2; exit 1; }
  LOCAL=1
fi
cd "$(dirname "$0")/.."
PROFILE="${YOGURT_NOTARY_PROFILE:-yogurt-notary}"
APP=dist/mac-arm64/Yogurt.app
set --
if [ "$LOCAL" = 1 ]; then
  # Pin the exact certificate; never silently fall back to ad-hoc or a different signer.
  CERT=$(security find-identity -v -p codesigning | awk '/"Yogurt Local"$/ { print $2 }')
  [ "${#CERT}" = 40 ] || { echo 'Create exactly one valid Yogurt Local code-signing identity.' >&2; exit 1; }
  LOCAL_DIR=$(mktemp -d "${TMPDIR:-/tmp}/yogurt-local-sign.XXXXXX")
  trap 'rm -rf "$LOCAL_DIR"' EXIT
  for ent in mac mac.inherit; do
    cp "build/entitlements.$ent.plist" "$LOCAL_DIR/$ent.plist"
    # Without an Apple Team ID, library validation rejects Electron's native libraries.
    /usr/libexec/PlistBuddy -c 'Add :com.apple.security.cs.disable-library-validation bool true' "$LOCAL_DIR/$ent.plist"
  done
  node - "$LOCAL_DIR" <<'JS' > "$LOCAL_DIR/config.json"
const path = require('node:path')
const dir = process.argv[2]
console.log(JSON.stringify({ extends: path.resolve('electron-builder.yml'), publish: null, forceCodeSigning: true,
  mac: { identity: 'Yogurt Local', notarize: false, entitlements: path.join(dir, 'mac.plist'),
    entitlementsInherit: path.join(dir, 'mac.inherit.plist') } }))
JS
  set -- --config "$LOCAL_DIR/config.json"
fi
rm -rf dist
sh scripts/native.sh
npx electron-vite build
EXTRA=""
# Electron's own defaults, fuse by fuse (the config file sets them; -c can't remove a setting)
[ "${YOGURT_FUSES:-1}" = 0 ] && EXTRA="-c.electronFuses.runAsNode=true -c.electronFuses.enableNodeOptionsEnvironmentVariable=true -c.electronFuses.enableNodeCliInspectArguments=true -c.electronFuses.onlyLoadAppFromAsar=false -c.electronFuses.enableEmbeddedAsarIntegrityValidation=false"
CSC_NAME="$ID" npx electron-builder --mac --publish never "$@" $EXTRA
# the app holds only the built code: a source folder inside means the build settings weren't applied
node scripts/asar-check.mjs "$APP/Contents/Resources/app.asar"
# the packaged notes engine starts and loads its dependencies (a local build is checked on release CI instead)
if [ "$LOCAL" = 0 ]; then npx electron scripts/engine-smoke.cjs "$APP/Contents/Resources/app.asar"; fi
codesign --verify --deep --strict "$APP"
verify_identity() {
  if [ "$LOCAL" = 1 ]; then
    codesign --verify --strict -R="certificate leaf = H\"$CERT\"" "$1"
    dr=$(codesign -d -r- "$1" 2>&1)
    echo "$dr" | grep -q 'designated =>' || { echo "$1 has no designated requirement" >&2; exit 1; }
    echo "$dr" | grep -q 'cdhash' && { echo "$1 has an unstable ad-hoc requirement" >&2; exit 1; }
  else
    codesign -dv "$1" 2>&1 | grep -q 'TeamIdentifier=2JNSQVN3N8' || { echo "$1 isn't signed with the Developer ID" >&2; exit 1; }
  fi
  return 0
}
# Main and helpers use one certificate, with hardened runtime and helper-specific entitlements.
for h in "$APP" "$APP"/Contents/Resources/bin/*; do
  verify_identity "$h"
  info=$(codesign -dv "$h" 2>&1)
  echo "$info" | grep -q "runtime" || { echo "$h has no hardened runtime" >&2; exit 1; }
done
# both speech programs are in, and the signed parakeet-server starts (hardened runtime, no entitlements)
for h in whisper-server parakeet-server; do [ -x "$APP/Contents/Resources/bin/$h" ] || { echo "$h is not in the app" >&2; exit 1; }; done
"$APP/Contents/Resources/bin/parakeet-server" --help >/dev/null 2>&1 || { echo "the packaged parakeet-server doesn't start" >&2; exit 1; }
# and it reads a clip on this Mac's graphics (Metal), as it will in meetings, when its model is here: the one this Mac's
# own Yogurt downloaded (only read), or YOGURT_PARAKEET_MODEL
PK_MODEL="${YOGURT_PARAKEET_MODEL:-$HOME/Library/Application Support/Yogurt/models/asr/ggml-parakeet-tdt-0.6b-v3-q8_0.bin}"
if [ -f "$PK_MODEL" ]; then
  node scripts/whisper-smoke.mjs --engine parakeet --bin "$APP/Contents/Resources/bin/parakeet-server" --model "$PK_MODEL" \
    --wav native/.whisper-build/samples/jfk.wav --expect country,ask --silence --runs 1 --label packaged-parakeet-metal \
    || { echo "the packaged parakeet-server doesn't transcribe on this Mac's graphics" >&2; exit 1; }
else
  echo "no Parakeet model on this Mac ($PK_MODEL): the packaged parakeet-server was started, not asked to transcribe"
fi
codesign -d --entitlements - "$APP/Contents/Resources/bin/yogurt-audio" 2>/dev/null | grep -q device.audio-input || { echo "yogurt-audio can't use the microphone" >&2; exit 1; }
if [ "${YOGURT_FUSES:-1}" != 0 ]; then
  pnpm exec electron-fuses read --app "$APP" | grep -q "RunAsNode is Disabled" || { echo "Electron's fuses aren't set" >&2; exit 1; }
fi
DMG=dist/Yogurt-mac-arm64.dmg
# electron-builder signed the disk image too (dmg.sign); signing it again here would change it after latest-mac.yml
verify_identity "$DMG"
if [ "$LOCAL" = 1 ]; then
  [ ! -e "$APP/Contents/Resources/app-update.yml" ] || { echo 'Local builds must not have a release feed' >&2; exit 1; }
  [ "$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$APP/Contents/Info.plist")" = so.yogurt.app ] || exit 1

fi
if [ "${YOGURT_NOTARIZE:-1}" = 0 ]; then
  echo "Signed, not notarized: $(pwd)/$DMG"
  exit 0
fi
xcrun notarytool submit "$DMG" --keychain-profile "$PROFILE" --wait
xcrun stapler staple "$DMG"
xcrun stapler staple "$APP"
# stapling changed the disk image: its checksum in latest-mac.yml again
node scripts/refresh-latest.mjs dist/latest-mac.yml
spctl -a -t open --context context:primary-signature -vv "$DMG"
echo "Ready to share: $(pwd)/$DMG"