#!/usr/bin/env bash # render-config.sh — turn *.tmpl files into real configs via envsubst. # Substitutes ONLY ${BASE_DOMAIN} and ${HOST_LAN_IP} so literal $-syntax that # belongs to the target file (dnsmasq, caddy, toml) is left untouched. # Halts on any unset var or missing template (cautious: no half-rendered output). set -euo pipefail cd "$(dirname "$0")/.." # repo root [ -f .env ] && { set -a; . ./.env; set +a; } : "${BASE_DOMAIN:?BASE_DOMAIN unset (set in .env)}" : "${HOST_LAN_IP:?HOST_LAN_IP unset (set in .env)}" render() { # $1=template $2=output [ -f "$1" ] || { echo "missing template: $1" >&2; exit 1; } envsubst '${BASE_DOMAIN} ${HOST_LAN_IP}' < "$1" > "$2" echo "rendered $2" } render drasl/config/config.toml.tmpl drasl/config/config.toml render dnsmasq/dnsmasq.conf.tmpl dnsmasq/dnsmasq.conf # packwiz external-file metadata: render every pack/mods/*.pw.toml.tmpl into its # .pw.toml (injects ${BASE_DOMAIN} into the download URL), then rebuild the # packwiz index. .packwizignore keeps the .tmpl out of the index. shopt -s nullglob tmpls=(pack/mods/*.pw.toml.tmpl) shopt -u nullglob if [ "${#tmpls[@]}" -gt 0 ]; then for t in "${tmpls[@]}"; do render "$t" "${t%.tmpl}"; done command -v packwiz >/dev/null 2>&1 || { echo "packwiz not found — cannot refresh index" >&2; exit 1; } # index.toml is gitignored build output; seed a minimal one so packwiz refresh # (which won't bootstrap a missing index) has something to populate. [ -f pack/index.toml ] || printf 'hash-format = "sha256"\n' > pack/index.toml ( cd pack && packwiz refresh ) echo "refreshed packwiz index (${#tmpls[@]} external metafiles)" fi