PrintToVeraeTimeStamp/platform/macos/pkg/build-pkg.sh

177 lines
7.1 KiB
Shell
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Build a Developer ID–signed, notarized macOS .pkg for Verae Print Stamp.
# Uses the same signing.env as Verae Timestamping.app (FlightLookup Inc.).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../../.." && pwd)"
PKG_DIR="$(cd "$(dirname "$0")" && pwd)"
SIGNING_ENV="${SIGNING_ENV:-$HOME/fie/installers/macos/signing.env}"
# shellcheck source=/dev/null
source "$SIGNING_ENV"
VERSION="${VERSION:-0.1.0}"
BUILD_ROOT="$ROOT/build/macos-pkg"
STAGE="$BUILD_ROOT/stage"
SCRIPTS="$BUILD_ROOT/scripts"
DIST="$BUILD_ROOT/dist"
ID_APP="${APPLE_APP_SIGN_ID:-Developer ID Application: FlightLookup Inc. (G8CKY7VMZC)}"
ID_PKG="${APPLE_INSTALLER_SIGN_ID:-Developer ID Installer: FlightLookup Inc. (G8CKY7VMZC)}"
ENTITLEMENTS="$PKG_DIR/entitlements.plist"
BUNDLE_ID="ai.verae.print-stamp"
PKG_ID="ai.verae.print-stamp.pkg"
echo "→ Cleaning $BUILD_ROOT"
rm -rf "$BUILD_ROOT"
mkdir -p "$STAGE" "$SCRIPTS" "$DIST" \
"$STAGE/Library/Application Support/Verae/PrintStamp/bin" \
"$STAGE/Library/Application Support/Verae/PrintStamp/ipp" \
"$STAGE/Library/Application Support/Verae/PrintStamp/registration-pdf" \
"$STAGE/Applications"
echo "→ Building universal verae-print $VERSION"
cd "$ROOT"
mkdir -p "$BUILD_ROOT/bin"
GOOS=darwin GOARCH=arm64 go build -o "$BUILD_ROOT/bin/verae-print-arm64" ./cmd/verae-print
GOOS=darwin GOARCH=amd64 go build -o "$BUILD_ROOT/bin/verae-print-amd64" ./cmd/verae-print
# Embed version string into HelperVersion via env for postinstall display
echo "$VERSION" > "$STAGE/Library/Application Support/Verae/PrintStamp/VERSION"
lipo -create -output "$STAGE/Library/Application Support/Verae/PrintStamp/bin/verae-print" \
"$BUILD_ROOT/bin/verae-print-arm64" "$BUILD_ROOT/bin/verae-print-amd64"
chmod 755 "$STAGE/Library/Application Support/Verae/PrintStamp/bin/verae-print"
echo "→ Signing verae-print"
codesign --force --sign "$ID_APP" --options runtime --timestamp \
--entitlements "$ENTITLEMENTS" \
"$STAGE/Library/Application Support/Verae/PrintStamp/bin/verae-print"
echo "→ Bundling registration-pdf (jsPDF) + assets"
cp -R "$ROOT/platform/registration-pdf/." "$STAGE/Library/Application Support/Verae/PrintStamp/registration-pdf/"
rm -rf "$STAGE/Library/Application Support/Verae/PrintStamp/registration-pdf/node_modules"
(
cd "$STAGE/Library/Application Support/Verae/PrintStamp/registration-pdf"
npm ci --omit=dev 2>/dev/null || npm install --omit=dev
)
mkdir -p "$STAGE/Library/Application Support/Verae/PrintStamp/assets"
cp -f "$ROOT/assets/VeraeFullLogo.png" "$STAGE/Library/Application Support/Verae/PrintStamp/assets/" 2>/dev/null || true
cp -f "$ROOT/internal/pdfcert/logo.png" "$STAGE/Library/Application Support/Verae/PrintStamp/registration-pdf/VeraeFullLogo.png" 2>/dev/null || true
echo "→ IPP helper files"
cp -f "$ROOT/platform/macos/ipp/verae-print-command.sh" "$STAGE/Library/Application Support/Verae/PrintStamp/ipp/"
cp -f "$ROOT/platform/macos/ipp/com.verae.timestamping.ipp.plist" "$STAGE/Library/Application Support/Verae/PrintStamp/ipp/"
chmod 755 "$STAGE/Library/Application Support/Verae/PrintStamp/ipp/verae-print-command.sh"
# Point LaunchAgent template -c path will be rewritten in postinstall to user support;
# also bake library binary path into a system copy of the command for reference.
sed -i '' "s|VERAE_PRINT_BIN:-\$HOME/bin/verae-print|VERAE_PRINT_BIN:-/Library/Application Support/Verae/PrintStamp/bin/verae-print|" \
"$STAGE/Library/Application Support/Verae/PrintStamp/ipp/verae-print-command.sh" 2>/dev/null || true
echo "→ Building Verae Print Stamp.app"
APP="$STAGE/Applications/Verae Print Stamp.app"
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"
cat > "$APP/Contents/Info.plist" <<PLIST
<?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>
<key>CFBundleExecutable</key><string>Verae Print Stamp</string>
<key>CFBundleIdentifier</key><string>$BUNDLE_ID</string>
<key>CFBundleName</key><string>Verae Print Stamp</string>
<key>CFBundleDisplayName</key><string>Verae Print Stamp</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleShortVersionString</key><string>$VERSION</string>
<key>CFBundleVersion</key><string>$VERSION</string>
<key>LSMinimumSystemVersion</key><string>14.0</string>
<key>NSHighResolutionCapable</key><true/>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key><string>PDF</string>
<key>CFBundleTypeRole</key><string>Viewer</string>
<key>LSHandlerRank</key><string>Alternate</string>
<key>LSItemContentTypes</key>
<array><string>com.adobe.pdf</string></array>
</dict>
</array>
<key>NSHumanReadableCopyright</key>
<string>Copyright © FlightLookup Inc. / Verae</string>
</dict></plist>
PLIST
cat > "$APP/Contents/MacOS/Verae Print Stamp" <<'RUN'
#!/bin/bash
BIN="/Library/Application Support/Verae/PrintStamp/bin/verae-print"
CHANNEL="${VERAE_PRINT_CHANNEL:-verae}"
if [[ $# -eq 0 ]]; then
osascript <<'OSA'
display dialog "Drop a PDF on this app, use Open With, or Print → Destination → Verae Timestamping." buttons {"OK"} default button 1 with title "Verae Print Stamp"
OSA
open -R "/Library/Application Support/Verae/PrintStamp" 2>/dev/null || true
exit 0
fi
for f in "$@"; do
case "$f" in
*.pdf|*.PDF|*.html|*.HTML|*.htm|*.HTM)
"$BIN" stamp -channel "$CHANNEL" -open "$f" \
|| osascript -e "display notification \"Stamp failed for $(basename "$f")\" with title \"Verae Print Stamp\""
;;
*)
osascript -e "display notification \"Unsupported file: $(basename "$f")\" with title \"Verae Print Stamp\""
;;
esac
done
RUN
chmod 755 "$APP/Contents/MacOS/Verae Print Stamp"
echo "→ Signing app bundle"
codesign --force --deep --sign "$ID_APP" --options runtime --timestamp \
--entitlements "$ENTITLEMENTS" \
"$APP"
echo "→ Preparing pkg scripts"
cp -f "$PKG_DIR/scripts/postinstall" "$SCRIPTS/postinstall"
chmod 755 "$SCRIPTS/postinstall"
COMPONENT_PKG="$DIST/VeraePrintStamp-component.pkg"
PRODUCT_PKG="$DIST/VeraePrintStamp-${VERSION}.pkg"
echo "→ pkgbuild component"
pkgbuild \
--root "$STAGE" \
--scripts "$SCRIPTS" \
--identifier "$PKG_ID" \
--version "$VERSION" \
--install-location "/" \
"$COMPONENT_PKG"
echo "→ productbuild + Developer ID Installer sign"
productbuild \
--package "$COMPONENT_PKG" \
--sign "$ID_PKG" \
--timestamp \
"$PRODUCT_PKG"
echo "→ Notarizing $PRODUCT_PKG"
xcrun notarytool submit "$PRODUCT_PKG" --wait \
--key "$APPLE_API_KEY_PATH" \
--key-id "$APPLE_API_KEY_ID" \
--issuer "$APPLE_API_ISSUER_ID"
echo "→ Stapling"
xcrun stapler staple "$PRODUCT_PKG"
echo "→ Verifying"
spctl -a -vv -t install "$PRODUCT_PKG" || true
pkgutil --check-signature "$PRODUCT_PKG" || true
# Stable latest name + checksums
cp -f "$PRODUCT_PKG" "$DIST/VeraePrintStamp-macos.pkg"
(
cd "$DIST"
shasum -a 256 "VeraePrintStamp-${VERSION}.pkg" VeraePrintStamp-macos.pkg > SHA256SUMS
)
echo
echo "Signed installable ready:"
echo " $PRODUCT_PKG"
echo " $DIST/VeraePrintStamp-macos.pkg"
echo
echo "Install: double-click the .pkg (or: sudo installer -pkg … -target /)"
echo "Then: Print → Destination → Verae Timestamping"