PrintToVeraeTimeStamp/platform/macos/pkg/build-pkg.sh
George Lambert d82d0a59cf fix(macos-pkg): dark-mode contrast, RTF Agree, sidebar brand clip
Screenshots (Desktop 5.25–5.27 AM) showed:
- Light purple/white chips and table headers unreadable on dark Installer WebKit
- License page only Continue (HTML license); no Agree/Disagree
- Left background text truncated ("Verae Print Stam", cut tagline)

Fixes:
- welcome/readme/conclusion/license HTML: color-scheme + prefers-color-scheme dark,
  high-contrast chips/tables/boxes (no white-on-white)
- license.rtf primary in Distribution (Installer Agree/Disagree)
- background.png / background-dark.png: left plum column + logo, short labels only
- smoke-installer-ui.sh checks RTF + dark-mode CSS (19 PASS)

Rebuild: SKIP_SIGN=1 ./platform/macos/pkg/build-pkg.sh
2026-10-14 05:31:07 -04:00

290 lines
12 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.
# Installer GUI includes: product identification, Verae branding, license Agree.
#
# Env:
# VERSION override HelperVersion
# SIGNING_ENV path to Apple signing.env (default ~/fie/installers/macos/signing.env)
# SKIP_SIGN=1 unsigned component + product (local UI smoke; no notary)
# SKIP_NOTARY=1 sign product but skip notarytool/staple
# UNSIGNED_ONLY=1 alias for SKIP_SIGN=1
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../../.." && pwd)"
PKG_DIR="$(cd "$(dirname "$0")" && pwd)"
RES_SRC="$PKG_DIR/resources"
SIGNING_ENV="${SIGNING_ENV:-$HOME/fie/installers/macos/signing.env}"
SKIP_SIGN="${SKIP_SIGN:-${UNSIGNED_ONLY:-0}}"
SKIP_NOTARY="${SKIP_NOTARY:-0}"
if [[ "$SKIP_SIGN" != "1" ]]; then
if [[ ! -f "$SIGNING_ENV" ]]; then
echo "error: signing env not found: $SIGNING_ENV" >&2
echo "hint: SKIP_SIGN=1 ./build-pkg.sh # unsigned product for installer UI smoke" >&2
exit 1
fi
# shellcheck source=/dev/null
source "$SIGNING_ENV"
fi
# Package version = internal/job.HelperVersion (single source of truth).
if [[ -z "${VERSION:-}" ]]; then
VERSION="$(grep -E 'HelperVersion[[:space:]]*=' "$ROOT/internal/job/job.go" | head -1 | sed -E 's/.*"([^"]+)".*/\1/')"
fi
VERSION="${VERSION:-0.3.6}"
BUILD_ROOT="$ROOT/build/macos-pkg"
STAGE="$BUILD_ROOT/stage"
SCRIPTS="$BUILD_ROOT/scripts"
DIST="$BUILD_ROOT/dist"
RES_STAGE="$BUILD_ROOT/resources"
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"
PRODUCT_NAME="Verae Print Stamp"
COMPONENT_NAME="VeraePrintStamp-component.pkg"
echo "→ Cleaning $BUILD_ROOT"
rm -rf "$BUILD_ROOT"
mkdir -p "$STAGE" "$SCRIPTS" "$DIST" "$RES_STAGE" \
"$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
echo "$VERSION" > "$STAGE/Library/Application Support/Verae/PrintStamp/VERSION"
# Product identification sidecar for support/audit
cat > "$STAGE/Library/Application Support/Verae/PrintStamp/PRODUCT.txt" <<PROD
product_name=$PRODUCT_NAME
product_id=$BUNDLE_ID
package_id=$PKG_ID
version=$VERSION
publisher=Verae / FlightLookup Inc.
brand=Verae
downloads=https://printit.verae.ai/
support=https://verae.com
PROD
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"
if [[ "$SKIP_SIGN" != "1" ]]; then
echo "→ Signing verae-print"
codesign --force --sign "$ID_APP" --options runtime --timestamp \
--entitlements "$ENTITLEMENTS" \
"$STAGE/Library/Application Support/Verae/PrintStamp/bin/verae-print"
else
echo "→ SKIP_SIGN=1 — leaving verae-print unsigned"
fi
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
cp -f "$PKG_DIR/LICENSE.txt" "$STAGE/Library/Application Support/Verae/PrintStamp/LICENSE.txt"
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"
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 $PRODUCT_NAME.app (branded + product ID)"
APP="$STAGE/Applications/${PRODUCT_NAME}.app"
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"
if [[ -f "$RES_SRC/AppIcon.icns" ]]; then
cp -f "$RES_SRC/AppIcon.icns" "$APP/Contents/Resources/AppIcon.icns"
fi
cp -f "$ROOT/assets/VeraeFullLogo.png" "$APP/Contents/Resources/VeraeFullLogo.png" 2>/dev/null || true
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>$PRODUCT_NAME</string>
<key>CFBundleDisplayName</key><string>$PRODUCT_NAME</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleShortVersionString</key><string>$VERSION</string>
<key>CFBundleVersion</key><string>$VERSION</string>
<key>CFBundleGetInfoString</key>
<string>$PRODUCT_NAME $VERSION — Verae / FlightLookup Inc. (ai.verae.print-stamp)</string>
<key>CFBundleIconFile</key><string>AppIcon</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 © Verae / FlightLookup Inc. All rights reserved.</string>
<key>VeraeProductID</key><string>$BUNDLE_ID</string>
<key>VeraePackageID</key><string>$PKG_ID</string>
<key>VeraeBrand</key><string>Verae</string>
<key>VeraeProductURL</key><string>https://printit.verae.ai/</string>
</dict></plist>
PLIST
cat > "$APP/Contents/MacOS/Verae Print Stamp" <<'RUN'
#!/bin/bash
BIN="/Library/Application Support/Verae/PrintStamp/bin/verae-print"
if [[ $# -eq 0 ]]; then
# Opened from Applications: key setup (keep / sign in / create account / paste / skip)
# and the "after each print" choice, in native dialogs.
exec "$BIN" mac-key-setup
fi
for f in "$@"; do
case "$f" in
*.pdf|*.PDF|*.html|*.HTML|*.htm|*.HTM)
"$BIN" stamp -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 "APPL????" > "$APP/Contents/PkgInfo" 2>/dev/null || printf 'APPL????' > "$APP/Contents/PkgInfo"
if [[ "$SKIP_SIGN" != "1" ]]; then
echo "→ Signing app bundle"
codesign --force --deep --sign "$ID_APP" --options runtime --timestamp \
--entitlements "$ENTITLEMENTS" \
"$APP"
else
echo "→ SKIP_SIGN=1 — leaving app unsigned"
fi
echo "→ Preparing installer GUI resources (welcome / license RTF Agree / readme / branding)"
cp -f "$RES_SRC/welcome.html" "$RES_STAGE/"
cp -f "$RES_SRC/license.html" "$RES_STAGE/" 2>/dev/null || true
cp -f "$RES_SRC/license.rtf" "$RES_STAGE/"
cp -f "$RES_SRC/conclusion.html" "$RES_STAGE/"
cp -f "$RES_SRC/background.png" "$RES_STAGE/"
cp -f "$RES_SRC/background-dark.png" "$RES_STAGE/"
# readme: inject version
sed "s/{{VERSION}}/$VERSION/g" "$RES_SRC/readme.html" > "$RES_STAGE/readme.html"
# Distribution from template
sed \
-e "s/@VERSION@/$VERSION/g" \
-e "s/@PKG_ID@/$PKG_ID/g" \
-e "s/@BUNDLE_ID@/$BUNDLE_ID/g" \
-e "s/@COMPONENT_NAME@/$COMPONENT_NAME/g" \
"$PKG_DIR/Distribution.xml.in" > "$BUILD_ROOT/Distribution.xml"
echo "→ Preparing pkg scripts"
cp -f "$PKG_DIR/scripts/postinstall" "$SCRIPTS/postinstall"
chmod 755 "$SCRIPTS/postinstall"
COMPONENT_PKG="$DIST/$COMPONENT_NAME"
PRODUCT_PKG="$DIST/VeraePrintStamp-${VERSION}.pkg"
echo "→ pkgbuild component ($PKG_ID $VERSION)"
pkgbuild \
--root "$STAGE" \
--scripts "$SCRIPTS" \
--identifier "$PKG_ID" \
--version "$VERSION" \
--install-location "/" \
"$COMPONENT_PKG"
echo "→ productbuild Distribution (branded + license accept + product ID)"
PB_ARGS=(
--distribution "$BUILD_ROOT/Distribution.xml"
--resources "$RES_STAGE"
--package-path "$DIST"
)
if [[ "$SKIP_SIGN" != "1" ]]; then
PB_ARGS+=(--sign "$ID_PKG" --timestamp)
fi
productbuild "${PB_ARGS[@]}" "$PRODUCT_PKG"
if [[ "$SKIP_SIGN" != "1" && "$SKIP_NOTARY" != "1" ]]; then
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
elif [[ "$SKIP_SIGN" == "1" ]]; then
echo "→ SKIP_SIGN=1 — skipping notary/staple (open $PRODUCT_PKG to review Installer UI)"
elif [[ "$SKIP_NOTARY" == "1" ]]; then
echo "→ SKIP_NOTARY=1 — signed product, not notarized"
pkgutil --check-signature "$PRODUCT_PKG" || true
fi
# Stable latest name + checksums
cp -f "$PRODUCT_PKG" "$DIST/VeraePrintStamp-macos.pkg"
(
cd "$DIST"
shasum -a 256 "VeraePrintStamp-${VERSION}.pkg" VeraePrintStamp-macos.pkg > SHA256SUMS
)
# Expand smoke: ensure Distribution + license resources embedded
EXPAND="$BUILD_ROOT/expand-check"
rm -rf "$EXPAND"
pkgutil --expand "$PRODUCT_PKG" "$EXPAND"
fail=0
has_expand_file() {
local f
f="$(find "$EXPAND" -name "$1" -print -quit 2>/dev/null || true)"
[[ -n "$f" && -s "$f" ]]
}
for need in Distribution welcome.html license.rtf readme.html conclusion.html background.png; do
if ! has_expand_file "$need"; then
echo "error: product pkg missing installer resource: $need" >&2
fail=1
fi
done
DIST_FILE=""
[[ -f "$EXPAND/Distribution" ]] && DIST_FILE="$EXPAND/Distribution"
[[ -z "$DIST_FILE" && -f "$EXPAND/Distribution.xml" ]] && DIST_FILE="$EXPAND/Distribution.xml"
if [[ -z "$DIST_FILE" ]] || ! grep -q 'Verae Print Stamp' "$DIST_FILE"; then
echo "error: Distribution missing product title Verae Print Stamp" >&2
fail=1
fi
if [[ -n "$DIST_FILE" ]] && ! grep -q 'ai.verae.print-stamp' "$DIST_FILE"; then
echo "error: Distribution missing product id ai.verae.print-stamp" >&2
fail=1
fi
if [[ "$fail" -ne 0 ]]; then
echo "Installer resource check failed. Tree:" >&2
find "$EXPAND" -maxdepth 3 -type f >&2 || true
exit 1
fi
echo "→ Installer GUI resources verified inside product pkg"
echo
echo "Signed installable ready:"
echo " $PRODUCT_PKG"
echo " $DIST/VeraePrintStamp-macos.pkg"
echo
echo "Installer pages: Welcome (branded) → License (Agree) → Read Me (product ID) → Install → Conclusion"
echo "Install: double-click the .pkg (or: sudo installer -pkg … -target /)"
echo "Then: Print → Destination → Verae Timestamping"