#!/bin/sh # Builds money with a static pdftotext inside it: one file to copy to a server, # with nothing to install there — not even poppler-utils. # # scripts/build-bundled.sh # linux, this machine's architecture # scripts/build-bundled.sh arm64 # linux/arm64 (podman/docker need qemu) # # pdftotext is built in a container from a checksum-pinned poppler release # (scripts/pdftotext.Containerfile) and cached under internal/parser/bundled/, # so later runs only rebuild money. Delete that file to rebuild it. set -eu cd "$(dirname "$0")/.." arch=${1:-$(go env GOARCH)} case $arch in amd64 | arm64) ;; *) echo "build-bundled: no static pdftotext for linux/$arch; use amd64 or arm64" >&2 exit 1 ;; esac bin=internal/parser/bundled/pdftotext-linux-$arch if [ ! -f "$bin" ] || [ scripts/pdftotext.Containerfile -nt "$bin" ]; then engine=$(command -v podman || command -v docker) || { echo "build-bundled: building pdftotext needs podman or docker" >&2 exit 1 } out=$(mktemp -d) trap 'rm -rf "$out"' EXIT "$engine" build --platform "linux/$arch" -f scripts/pdftotext.Containerfile \ --output "type=local,dest=$out" scripts mkdir -p internal/parser/bundled mv "$out/pdftotext" "$bin" fi mkdir -p dist CGO_ENABLED=0 GOOS=linux GOARCH=$arch \ go build -tags bundled -trimpath -o "dist/money-linux-$arch" ./cmd/money echo "dist/money-linux-$arch"