#!/usr/bin/env bash # Build a minimal .deb for nginx-logtail containing the four static binaries. # Expects `make build-` to have already populated build//. # # Usage: debian/build-deb.sh # arch: amd64 | arm64 # version: e.g. 0.9.1 set -euo pipefail if [ "$#" -ne 2 ]; then echo "usage: $0 " >&2 exit 1 fi ARCH="$1" VERSION="$2" PKG="nginx-logtail" STAGE="$(mktemp -d)" chmod 0755 "$STAGE" # Output into build/ alongside the per-arch binary trees so `make clean` # wipes everything in one rm and .gitignore only needs to ignore build/. OUT_DIR="build" mkdir -p "${OUT_DIR}" OUT="${OUT_DIR}/${PKG}_${VERSION}_${ARCH}.deb" trap 'rm -rf "$STAGE"' EXIT BUILD_DIR="build/${ARCH}" for b in collector aggregator frontend cli; do if [ ! -x "${BUILD_DIR}/${b}" ]; then echo "error: ${BUILD_DIR}/${b} not found — run 'make build-${ARCH}' first" >&2 exit 1 fi done install -d -m 0755 \ "${STAGE}/DEBIAN" \ "${STAGE}/usr/sbin" \ "${STAGE}/usr/bin" \ "${STAGE}/usr/share/doc/${PKG}" \ "${STAGE}/usr/share/man/man8" \ "${STAGE}/usr/share/${PKG}" \ "${STAGE}/lib/systemd/system" install -m 0755 "${BUILD_DIR}/collector" "${STAGE}/usr/sbin/nginx-logtail-collector" install -m 0755 "${BUILD_DIR}/aggregator" "${STAGE}/usr/sbin/nginx-logtail-aggregator" install -m 0755 "${BUILD_DIR}/frontend" "${STAGE}/usr/sbin/nginx-logtail-frontend" install -m 0755 "${BUILD_DIR}/cli" "${STAGE}/usr/bin/nginx-logtail" install -m 0644 LICENSE "${STAGE}/usr/share/doc/${PKG}/copyright" install -m 0644 README.md "${STAGE}/usr/share/doc/${PKG}/README.md" # Manpage: gzip per Debian policy (lintian only checks for .gz). gzip -n -9 -c debian/nginx-logtail.8 > "${STAGE}/usr/share/man/man8/nginx-logtail.8.gz" chmod 0644 "${STAGE}/usr/share/man/man8/nginx-logtail.8.gz" # systemd units. Installed, not enabled or started — operator opts in. install -m 0644 debian/nginx-logtail-collector.service "${STAGE}/lib/systemd/system/" install -m 0644 debian/nginx-logtail-aggregator.service "${STAGE}/lib/systemd/system/" install -m 0644 debian/nginx-logtail-frontend.service "${STAGE}/lib/systemd/system/" # Defaults template. postinst renders this to /etc/default/nginx-logtail on # first install with %HOSTNAME% substituted. Not a dpkg conffile — operator # edits survive upgrades because postinst only writes when the file is absent. install -m 0644 debian/default.template "${STAGE}/usr/share/${PKG}/default.template" # Maintainer scripts: postinst creates _logtail user and renders defaults; # prerm stops running services; postrm reloads systemd and removes the # generated defaults file on purge. install -m 0755 debian/postinst "${STAGE}/DEBIAN/postinst" install -m 0755 debian/postrm "${STAGE}/DEBIAN/postrm" install -m 0755 debian/prerm "${STAGE}/DEBIAN/prerm" cat > "${STAGE}/DEBIAN/control" < Homepage: https://git.ipng.ch/ipng/nginx-logtail Description: Real-time top-K traffic analysis for nginx clusters nginx-logtail is a four-binary Go system that ingests nginx access logs (from files or UDP) and answers ranked top-K queries over configurable time windows. See /usr/share/doc/nginx-logtail/README.md. EOF dpkg-deb --build --root-owner-group "${STAGE}" "${OUT}" echo "built ${OUT}"