#!/bin/bash # ippeveprinter -c handler: PDF (or PS) on stdin → Verae stamp with approved naming. set -euo pipefail LOG="${HOME}/Library/Logs/verae-print-ipp.log" mkdir -p "$(dirname "$LOG")" exec >>"$LOG" 2>&1 echo "$(date -u +%Y-%m-%dT%H:%MZ) IPP job start env=$(env | grep -E '^IPP_|^CONTENT_|^USER=' | tr '\n' ' ')" VERAE_PRINT="${VERAE_PRINT_BIN:-$HOME/bin/verae-print}" OUT_DIR="${HOME}/Documents/Verae Timestamps" mkdir -p "$OUT_DIR" # First-run: require customer xVerae- signing key (opens portal dialogs) if ! "$VERAE_PRINT" setup; then echo "ERROR: signing key setup required" >&2 osascript -e 'display notification "Create a Verae customer account to get your signing key" with title "Verae Timestamping"' || true open "https://customer.verae.ai/portal/" 2>/dev/null || true exit 1 fi TITLE="${IPP_JOB_NAME:-${IPP_DOCUMENT_NAME:-document}}" # Strip path / extension for stem BASE="$(basename "$TITLE")" STEM="${BASE%.*}" STEM="$(echo "$STEM" | tr -cd 'A-Za-z0-9._ -' | head -c 80)" STEM="${STEM:-document}" TMPDIR="${TMPDIR:-/tmp}" WORK="$(mktemp -d "${TMPDIR}/verae-ipp.XXXXXX")" RAW="$WORK/job.bin" PDF="$WORK/${STEM}.pdf" # ippeveprinter may pass a spool file as argv[1], or feed bytes on stdin if [[ $# -ge 1 && -f "${1:-}" ]]; then echo "input file arg: $1" cp "$1" "$RAW" elif [[ ! -t 0 ]]; then cat >"$RAW" else echo "ERROR: no document on stdin or argv" >&2 exit 1 fi if [[ ! -s "$RAW" ]]; then echo "ERROR: empty document" >&2 exit 1 fi if [[ "$(head -c 4 "$RAW")" == "%PDF" ]]; then cp "$RAW" "$PDF" elif command -v /usr/bin/pstopdf >/dev/null 2>&1; then /usr/bin/pstopdf "$RAW" -o "$PDF" || cp "$RAW" "$PDF" else cp "$RAW" "$PDF" fi echo "stamping stem=$STEM pdf=$PDF" "$VERAE_PRINT" stamp -out-dir "$OUT_DIR" -name "$STEM" -open "$PDF" echo "ATTR: job-impressions-completed=1" >&2 rm -rf "$WORK" exit 0