#!/bin/sh set -eu cd "$(dirname "$0")/.." root="$PWD" # A stable Apple signing identity keeps the app's Keychain requirement stable # across updates. An explicit identity can also be a Developer ID certificate. signing_identity="${MESHPORT_SIGNING_IDENTITY:-}" if [ -z "$signing_identity" ]; then signing_identity=$(security find-identity -v -p codesigning | python3 -c 'import re,sys; ids=re.findall(r"([0-9A-F]{40}) \"Apple Development:", sys.stdin.read()); print(ids[0] if len(ids)==1 else "-")') fi config="$root/apps/meshport_lab/assets/config/default.toml" saved=$(mktemp) had_config=0 if [ -f "$config" ]; then cp -p "$config" "$saved" had_config=1 fi restore_config() { if [ "$had_config" = 1 ]; then cp -p "$saved" "$config"; else rm -f "$config"; fi rm -f "$saved" } trap restore_config EXIT HUP INT TERM # Distribution bundles use only the public template, never local credentials. cp "$root/apps/meshport_lab/assets/config/default.example.toml" "$config" scripts/cargo-local.sh build -p meshport-ffi -p meshport-vpn-helper --release --locked sh scripts/build-singbox-library.sh macos build_number=$(date +%s) build_arch=$(uname -m) cd "$root/apps/meshport_lab" # Rust and Go libraries above target this host architecture as well. FLUTTER_XCODE_ARCHS="$build_arch" flutter build macos --release --build-number="$build_number" app="$PWD/build/macos/Build/Products/Release/MeshPort.app" cp "$root/target/release/libmeshport_ffi.dylib" "$app/Contents/Frameworks/" cp "$root/target/debug/libmeshport_proxy.dylib" "$app/Contents/Frameworks/" cp "$root/target/release/meshport-vpn-helper" "$app/Contents/MacOS/" codesign --force --sign "$signing_identity" "$app/Contents/MacOS/meshport-vpn-helper" codesign --force --sign "$signing_identity" "$app/Contents/Frameworks/libmeshport_ffi.dylib" codesign --force --sign "$signing_identity" "$app/Contents/Frameworks/libmeshport_proxy.dylib" codesign --force --deep --sign "$signing_identity" --entitlements macos/Runner/Release.entitlements "$app" codesign --verify --deep --strict "$app" out="$root/outputs/macos/MeshPort-0.1.0-$build_number-$build_arch-release" mkdir -p "$root/outputs/macos" ditto "$app" "$out.app" # Keep the installed filename stable so dragging it replaces the old APP. ditto -c -k --sequesterRsrc --keepParent "$app" "$out.zip" shasum -a 256 "$out.zip" > "$out.zip.sha256" printf '%s\n' "$out.app" "$out.zip"