Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

3.6 KB
Raw Blame
#!/bin/sh
set -eu

if [ "$#" -ne 2 ]; then
  echo "usage: create-macos-dmg.sh <Avibe.app> <output.dmg>" >&2
  exit 2
fi

app=$1
output=$2

if [ ! -d "$app/Contents/MacOS" ]; then
  echo "input is not a macOS application bundle: $app" >&2
  exit 2
fi
if [ ! -f "$app/Contents/Helpers/cua-driver" ]; then
  echo "input is missing Contents/Helpers/cua-driver" >&2
  exit 2
fi
if [ -e "$app/Contents/MacOS/cua-driver" ]; then
  echo "input contains a stale Contents/MacOS/cua-driver" >&2
  exit 2
fi

# Signature-aware staging. A Developer ID (or any identity-bearing) signature
# is copied as-is: re-signing with an ad-hoc identity here would strip it and
# the DMG would ship unsigned. An ad-hoc or absent signature means the bundle
# is an acceptance artifact, and the disposable copy is ad-hoc signed so macOS
# can still verify its structure.
#
# Detection: `codesign -dv` prints `Signature=adhoc` ONLY for ad-hoc
# signatures — identity signatures print `Signature size=...` and one or more
# `Authority=...` lines instead, so `Signature=` alone never matches them.
# Authority lines are the identity-bearing signal; `TeamIdentifier=not set`
# covers self-signed identities without a team. verbose=4 is required for
# Authority output.
identity=$(codesign -dv --verbose=4 "$app" 2>&1 | sed -n 's/^Authority=//p' | head -1 || true)
adhoc=$(codesign -dv "$app" 2>&1 | sed -n '/^Signature=adhoc$/p' || true)

staging=$(mktemp -d "${TMPDIR:-/tmp}/avibe-dmg.XXXXXX")
trap 'rm -rf "$staging"' EXIT HUP INT TERM

cp -R "$app" "$staging/Avibe.app"
ln -s /Applications "$staging/Applications"
mkdir -p "$(dirname "$output")"
rm -f "$output"

if [ -n "$adhoc" ] || [ -z "$identity" ]; then
  # A linker-signed executable does not seal the resources copied into the app
  # bundle. Ad-hoc sign the disposable DMG copy so macOS can verify its
  # structure. This is not Developer ID signing and does not bypass
  # Gatekeeper/notarization.
  codesign --force --sign - \
    --preserve-metadata=identifier,entitlements,flags,runtime \
    "$staging/Avibe.app/Contents/Helpers/cua-driver"
  codesign --force --sign - \
    --preserve-metadata=identifier,entitlements,flags,runtime \
    "$staging/Avibe.app"
  codesign --verify --strict "$staging/Avibe.app/Contents/Helpers/cua-driver"
  codesign --verify --deep --strict "$staging/Avibe.app"
else
  # Sealing the copy must not invalidate the identity signature: verify the
  # staging copy still validates against the same team before imaging it.
  codesign --verify --strict "$staging/Avibe.app/Contents/Helpers/cua-driver"
  codesign --verify --deep --strict "$staging/Avibe.app"
fi

# Tauri's decorated DMG helper drives Finder through AppleScript, which is
# brittle on headless CI and hardened developer machines. A plain compressed
# image has the same install semantics and no GUI dependency.
#
# `hdiutil create` intermittently fails with "Resource busy" on CI while the
# identical call succeeds on another runner in the same job matrix: the imaging
# helper contends with whatever still holds the freshly written staging tree.
# Retry a bounded number of times with a pause, and let the last attempt's
# failure through unchanged so a real defect is still a build failure.
attempt=1
while :; do
  if hdiutil create \
    -volname Avibe \
    -srcfolder "$staging" \
    -format UDZO \
    -imagekey zlib-level=9 \
    -ov \
    "$output"; then
    break
  fi
  if [ "$attempt" -ge 3 ]; then
    echo "hdiutil create failed after $attempt attempts" >&2
    exit 1
  fi
  echo "hdiutil create failed (attempt $attempt); retrying" >&2
  attempt=$((attempt + 1))
  sleep 5
done

hdiutil verify "$output"