Files
kevinveenbirkenbachandClaude Opus 5 575a5a87ac refactor(layout): sort shipped scripts by language and split the unit suite
Every script a role ships now lives under `files/<language>/`, and the unit
suite is split the same way: `tests/unit/python/` beside new sibling trees for
the other languages. `tests/lint/filesystem/test_role_files_layout.py` keeps it
that way; directories whose shape is dictated from outside carry a `.nocheck`
naming the constraint (Docker build contexts, WordPress mu-plugins, the Joomla
extension, Odoo addons, Playwright suites, the `files/test/test.sh` harness
that `test-e2e-cli` resolves generically).

This cannot be applied in halves. Moving a file and repointing what names it
are the same change: 14 references resolve only at deploy time, so the tree is
green either before or after, never between.

Those 14 were found by static resolution over every reference class, not by the
test suite -- a full `make quality-high` was green while all of them were
broken:

  * 7 `src:` values built from a role variable holding a bare filename
    (svc-bkp-remote-2-local, decidim, espocrm, friendica, joomla, pixelfed x2).
    The variable doubles as the destination name inside the container, so the
    language segment belongs at the call site, not in the variable.
  * `sys-service/tasks/04_base.yml` resolved every consumer's systemd script
    through `first_found(..., errors='strict')` over `files/script.{sh,py}`.
    18 roles ship exactly that and have no template fallback: the play would
    have died on each.
  * `sys-front-inj-javascript` fell back to `<role>/files/javascript.js`; the
    interface now reads `files/javascript/javascript.js`.
  * `sys-front-inj-logout/templates/head_sub.j2` built the cache-busting mtime
    path through `path_absolute(... 'files', ...)`.
  * 4 `ansible.builtin.script:` invocations naming a bare command
    (pull.py, prune.sh, set_postgres_superuser_password.sh, ganesha-serve.sh).
  * `dev-python/files/shell/install.sh` pointed at a sibling role's script.

Depth-dependent paths inside the moved trees were bumped accordingly: 59
`parents[N]` computations, 12 relative climbs, and the per-role recover CLI,
whose path `cli/administration/recover/recoverers.py` still assembled from the
pre-move location.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 01:31:09 +02:00

75 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
# Stores a hard-linked differential snapshot of the host's generated
# secret material (infinito secrets + tokens, the self-signed CA, the
# Let's Encrypt account + certs, the ACME DNS credentials) and the node
# identity in the local backup directory. None of this lives in a docker
# volume, the NFS export or the operator inventory, so without this
# snapshot a restored host cannot re-serve its running tokens and TLS
# trust. The node subtree keeps ssh host keys + machine-id (universal
# FHS paths, not configurable): a fresh host restore needs them for its
# ssh identity and, via machine-id, a stable backup addressing hash.
#
# Arguments:
# $1 BACKUPS_DIR local backup root
# $2 REPO_NAME repository directory name inside the machine hash dir
# $3.. NAME=DIR named source directories; a missing optional dir is
# skipped (CA absent in letsencrypt mode, ACME absent
# in self-signed mode).
set -euo pipefail
BACKUPS_DIR="${1:?usage: script.sh BACKUPS_DIR REPO_NAME NAME=DIR...}"
REPO_NAME="${2:?usage: script.sh BACKUPS_DIR REPO_NAME NAME=DIR...}"
shift 2
MACHINE_HASH="$(sha256sum /etc/machine-id | cut -c1-64)"
REPO_DIR="${BACKUPS_DIR%/}/${MACHINE_HASH}/${REPO_NAME}"
GENERATION="$(date +%Y%m%d%H%M%S)"
DEST_DIR="${REPO_DIR}/${GENERATION}/files"
PREVIOUS_FILES=""
if [[ -d "${REPO_DIR}" ]]; then
PREVIOUS_GENERATION="$(find "${REPO_DIR}" -mindepth 1 -maxdepth 1 -type d | sort | tail -n1)"
if [[ -n "${PREVIOUS_GENERATION}" && -d "${PREVIOUS_GENERATION}/files" ]]; then
PREVIOUS_FILES="${PREVIOUS_GENERATION}/files"
fi
fi
cleanup_failed_generation() {
rm -rf "${REPO_DIR:?}/${GENERATION:?}"
}
trap cleanup_failed_generation ERR
mkdir -p "${DEST_DIR}"
snapshot_subtree() {
local name="$1" src="$2"
local dest="${DEST_DIR}/${name}"
mkdir -p "${dest}"
local args=(-a)
if [[ -n "${PREVIOUS_FILES}" && -d "${PREVIOUS_FILES}/${name}" ]]; then
args+=(--link-dest "${PREVIOUS_FILES}/${name}/")
fi
rsync "${args[@]}" "${src}" "${dest}/"
}
for spec in "$@"; do
name="${spec%%=*}"
src="${spec#*=}"
if [[ ! -e "${src}" ]]; then
echo "SKIP: ${name} source ${src} absent"
continue
fi
snapshot_subtree "${name}" "${src%/}/"
echo "OK: ${name} snapshot from ${src}"
done
mkdir -p "${DEST_DIR}/node"
cp -a /etc/machine-id "${DEST_DIR}/node/machine-id"
for key in /etc/ssh/ssh_host_*; do
[[ -e "${key}" ]] || continue
cp -a "${key}" "${DEST_DIR}/node/"
done
echo "OK: node identity snapshot (ssh host keys + machine-id)"
echo "OK: differential secrets backup stored in ${DEST_DIR}"