#!/bin/bash # SPDX-License-Identifier: Apache-2.0 # Build the ctool Debian package for one architecture. # Usage: build-deb.sh ctool # # The commit hash and build date are baked into the binary at link time # via -ldflags in the Makefile, so `ctool version` is the source of truth # for "which build". The .deb itself carries only the release version. set -euo pipefail PACKAGE="${1:?usage: build-deb.sh ctool }" ARCH="${2:?usage: build-deb.sh ctool }" VERSION="${3:?usage: build-deb.sh ctool }" REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" PKG="${PACKAGE}_${VERSION}_${ARCH}" STAGING="$(mktemp -d)" trap 'rm -rf "$STAGING"' EXIT echo "Building ${PKG}.deb" if [ "$PACKAGE" != "ctool" ]; then echo "error: unknown package '${PACKAGE}' (expected ctool)" >&2 exit 2 fi install -d "$STAGING/DEBIAN" install -d "$STAGING/usr/bin" install -d "$STAGING/usr/share/man/man1" # Binary. ctool is an interactive tool, not a daemon, so it lives in # /usr/bin and is on every login shell's PATH by default. install -m 755 "$REPO_ROOT/build/${ARCH}/ctool" "$STAGING/usr/bin/ctool" # ctfetch and ctail are busybox-style aliases: the binary dispatches on # argv[0], so a symlink is all it takes for `ctfetch ...` to mean # `ctool fetch ...` and `ctail ...` to mean `ctool tail ...`. ln -s ctool "$STAGING/usr/bin/ctfetch" ln -s ctool "$STAGING/usr/bin/ctail" # Manpages — one overview (ctool) plus one detailed page per subcommand. gzip -9 -c "$REPO_ROOT/docs/ctool.1" > "$STAGING/usr/share/man/man1/ctool.1.gz" gzip -9 -c "$REPO_ROOT/docs/ctfetch.1" > "$STAGING/usr/share/man/man1/ctfetch.1.gz" gzip -9 -c "$REPO_ROOT/docs/ctail.1" > "$STAGING/usr/share/man/man1/ctail.1.gz" # DEBIAN metadata. No conffiles and no maintainer scripts — the package # ships a single binary, two symlinks, and three manpages. sed "s/@VERSION@/${VERSION}/;s/@ARCH@/${ARCH}/" \ "$REPO_ROOT/debian/${PACKAGE}.control.in" > "$STAGING/DEBIAN/control" # Emit package into build/ mkdir -p "$REPO_ROOT/build" OUT="$REPO_ROOT/build/${PKG}.deb" dpkg-deb --build --root-owner-group "$STAGING" "$OUT" echo "Built: $OUT"