#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" APP_NAME="ashell" BUNDLE_ID="dev.ashell.app" APP_DIR="$ROOT_DIR/target/release/${APP_NAME}.app" CONTENTS_DIR="$APP_DIR/Contents" MACOS_DIR="$CONTENTS_DIR/MacOS" RESOURCES_DIR="$CONTENTS_DIR/Resources" SIGN_IDENTITY="${SIGN_IDENTITY:--}" cd "$ROOT_DIR" cargo build --release rm -rf "$APP_DIR" mkdir -p "$MACOS_DIR" "$RESOURCES_DIR" cp "$ROOT_DIR/target/release/$APP_NAME" "$MACOS_DIR/$APP_NAME" cat > "$CONTENTS_DIR/Info.plist" < CFBundleDevelopmentRegion en CFBundleExecutable $APP_NAME CFBundleIdentifier $BUNDLE_ID CFBundleInfoDictionaryVersion 6.0 CFBundleName $APP_NAME CFBundlePackageType APPL CFBundleShortVersionString 0.1.0 CFBundleVersion 1 LSMinimumSystemVersion 12.0 NSHighResolutionCapable EOF printf 'APPL????' > "$CONTENTS_DIR/PkgInfo" if command -v codesign >/dev/null 2>&1; then # Important: do not pass an entitlements file here. # A sandboxed macOS app carries the `com.apple.security.app-sandbox` entitlement, # which would prevent the file access behavior this app needs. codesign --force --deep --sign "$SIGN_IDENTITY" "$APP_DIR" >/dev/null ENTITLEMENTS_XML="$(codesign -d --entitlements :- "$APP_DIR" 2>/dev/null || true)" if printf '%s' "$ENTITLEMENTS_XML" | grep -q "com.apple.security.app-sandbox"; then echo "error: app bundle is sandboxed; remove app sandbox entitlements before packaging" >&2 exit 1 fi fi echo "$APP_DIR"