Implements the check announced in ADR 0018. The installer may define the names once between '# --- names (ADR 0018) ---' and '# --- end names ---'; missing files are skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
2.2 KiB
Bash
Executable File
67 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Fails if systemd unit templates, nfpm package files or the installer
|
|
# contain hard-coded product or binary names (ADR 0018). Names belong in the
|
|
# variables of the Makefile and the scripts; templates use placeholders.
|
|
#
|
|
# Usage: scripts/check-brand.sh [FILE...]
|
|
# Without FILE the default set is checked: deploy/systemd/*.in,
|
|
# deploy/nfpm/*, scripts/install.sh. Missing files are skipped.
|
|
#
|
|
# The installer may define the names once, in a block between the lines
|
|
# # --- names (ADR 0018) ---
|
|
# # --- end names ---
|
|
# Each marker must appear exactly once, in this order; everything outside the
|
|
# block is checked. The same applies to any checked file containing a marker.
|
|
|
|
set -euo pipefail
|
|
|
|
readonly BEGIN_MARKER="# --- names (ADR 0018) ---"
|
|
readonly END_MARKER="# --- end names ---"
|
|
# Literal names that must not appear (case-insensitive).
|
|
readonly PATTERN='ddi-suite|ddi-server|ddi-agent-dns|ddi-agent-dhcp'
|
|
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
|
|
files=("$@")
|
|
if ((${#files[@]} == 0)); then
|
|
shopt -s nullglob
|
|
files=(deploy/systemd/*.in deploy/nfpm/* scripts/install.sh)
|
|
shopt -u nullglob
|
|
fi
|
|
|
|
failed=0
|
|
checked=0
|
|
for f in "${files[@]}"; do
|
|
[[ -f "$f" ]] || continue
|
|
checked=$((checked + 1))
|
|
begins="$(grep -cxF -- "$BEGIN_MARKER" "$f" || true)"
|
|
ends="$(grep -cxF -- "$END_MARKER" "$f" || true)"
|
|
if [[ "$f" == scripts/install.sh ]] || ((begins + ends > 0)); then
|
|
if ((begins != 1 || ends != 1)); then
|
|
echo "$f: expected exactly one '${BEGIN_MARKER}' and one '${END_MARKER}' line" >&2
|
|
failed=1
|
|
continue
|
|
fi
|
|
fi
|
|
# "line:text" for every offending line outside the names block.
|
|
hits="$(awk -v b="$BEGIN_MARKER" -v e="$END_MARKER" -v pat="$PATTERN" '
|
|
$0 == b { inside = 1; next }
|
|
$0 == e { if (!inside) print NR ":end marker before begin marker"; inside = 0; next }
|
|
!inside && tolower($0) ~ pat { print NR ":" $0 }
|
|
' "$f")"
|
|
if [[ -n "$hits" ]]; then
|
|
while IFS= read -r line; do
|
|
echo "${f}:${line}" >&2
|
|
done <<<"$hits"
|
|
failed=1
|
|
fi
|
|
done
|
|
|
|
if ((failed)); then
|
|
echo "hard-coded product or binary names found (ADR 0018): use the variables or placeholders" >&2
|
|
exit 1
|
|
fi
|
|
echo "brand check passed (${checked} files)"
|