Introduces a static-binary build and Debian package (amd64/arm64) with version/commit/date stamped via -ldflags. Ships section-1 manpages for ctool, ctfetch, and ctail. Adds a `version` subcommand reachable as `ctool version`, `ctool -version`, `ctool --version`, `ctool fetch version`, `ctool tail version`, and via the ctfetch/ctail symlinks. Adds tests covering the dispatcher, fetch/tail argument parsing, and the formatter/helper functions. Adds a retrofit design document modelled on the vpp-maglev one, with FRs and NFRs for each tool and the dispatcher. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
56 lines
2.1 KiB
Bash
Executable File
56 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
# Build the ctool Debian package for one architecture.
|
|
# Usage: build-deb.sh ctool <amd64|arm64> <version>
|
|
#
|
|
# 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 <amd64|arm64> <version>}"
|
|
ARCH="${2:?usage: build-deb.sh ctool <amd64|arm64> <version>}"
|
|
VERSION="${3:?usage: build-deb.sh ctool <amd64|arm64> <version>}"
|
|
|
|
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"
|