ci / Web (lint, test, audit, build) (push) Successful in 1m22s
ci / Shell and licence headers (push) Successful in 8s
ci / Integration (real BIND and Kea) (push) Successful in 2m6s
ci / Protobuf (push) Successful in 6s
ci / Go (lint, test, vuln) (push) Successful in 3m43s
ci / Release build (dry run) (push) Successful in 2m27s
ci / Development environment (compose) (push) Successful in 13s
ci / End-to-end (server, agents, BIND, Kea) (push) Successful in 3m8s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.8 KiB
Bash
Executable File
51 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Renders the systemd unit templates deploy/systemd/*.service.in (ADR 0024).
|
|
#
|
|
# Usage: scripts/render-units.sh <bindir> <outdir>
|
|
# writes <outdir>/<BIN_SERVER>.service, <BIN_AGENT_DNS>.service and
|
|
# <BIN_AGENT_DHCP>.service with @BINDIR@ = <bindir>.
|
|
#
|
|
# Names come from the environment (set by the Makefile, ADR 0018): PRODUCT,
|
|
# DISPLAY_NAME, BIN_SERVER, BIN_AGENT_DNS, BIN_AGENT_DHCP, ENV_PREFIX.
|
|
|
|
set -euo pipefail
|
|
|
|
if [[ $# -ne 2 ]]; then
|
|
sed -n '4,11p' "$0" | sed 's/^# \{0,1\}//' >&2
|
|
exit 2
|
|
fi
|
|
bindir="$1"
|
|
outdir="$2"
|
|
|
|
PRODUCT="${PRODUCT:-ddi-suite}"
|
|
DISPLAY_NAME="${DISPLAY_NAME:-DDI-Suite}"
|
|
BIN_SERVER="${BIN_SERVER:-ddi-server}"
|
|
BIN_AGENT_DNS="${BIN_AGENT_DNS:-ddi-agent-dns}"
|
|
BIN_AGENT_DHCP="${BIN_AGENT_DHCP:-ddi-agent-dhcp}"
|
|
ENV_PREFIX="${ENV_PREFIX:-DDI_}"
|
|
|
|
# Values end up in sed replacements: allow only safe characters.
|
|
for v in "$bindir" "$PRODUCT" "$BIN_SERVER" "$BIN_AGENT_DNS" "$BIN_AGENT_DHCP" "$ENV_PREFIX"; do
|
|
[[ "$v" =~ ^[A-Za-z0-9._/+-]+$ ]] || { echo "unsafe value: $v" >&2; exit 2; }
|
|
done
|
|
[[ "$DISPLAY_NAME" =~ ^[A-Za-z0-9\ ._+-]+$ ]] || { echo "unsafe display name: $DISPLAY_NAME" >&2; exit 2; }
|
|
|
|
src="$(cd "$(dirname "$0")/../deploy/systemd" && pwd)"
|
|
mkdir -p "$outdir"
|
|
render() {
|
|
sed -e "s|@PRODUCT@|$PRODUCT|g" -e "s|@DISPLAY_NAME@|$DISPLAY_NAME|g" \
|
|
-e "s|@BIN_SERVER@|$BIN_SERVER|g" -e "s|@BIN_AGENT_DNS@|$BIN_AGENT_DNS|g" \
|
|
-e "s|@BIN_AGENT_DHCP@|$BIN_AGENT_DHCP|g" -e "s|@BINDIR@|$bindir|g" \
|
|
-e "s|@CONFIG_DIR@|/etc/$PRODUCT|g" -e "s|@ENV_PREFIX@|$ENV_PREFIX|g" \
|
|
"$src/$1" >"$outdir/$2"
|
|
if grep -q '@[A-Z_]*@' "$outdir/$2"; then
|
|
echo "unreplaced placeholder in $2" >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
render server.service.in "$BIN_SERVER.service"
|
|
render agent-dns.service.in "$BIN_AGENT_DNS.service"
|
|
render agent-dhcp.service.in "$BIN_AGENT_DHCP.service"
|