mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-07 19:32:17 +00:00
Adds a Makefile target plus helper script that removes container-owned generated artefacts (build/install.stamp, tasks/groups/*-roles.yml) which the host user cannot rm directly. The helper auto-starts a stopped infinito compose container before deletion. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
45 lines
1.8 KiB
Bash
Executable File
45 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Remove the container-owned generated artefacts under the working tree.
|
|
#
|
|
# Both `build/` (install-stamp) and `tasks/groups/*-roles.yml` (output
|
|
# of `cli build include` during setup) are produced inside the compose
|
|
# container by the in-container UID (typically `nobody`). The host
|
|
# user cannot rm them directly. This helper starts the infinito
|
|
# compose container if a stopped one exists, then deletes the
|
|
# nobody-owned artefacts from inside it. Safe no-op when the targets
|
|
# do not exist.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)"
|
|
cd "${REPO_ROOT}"
|
|
|
|
# shellcheck source=scripts/meta/env/load.sh
|
|
source scripts/meta/env/load.sh
|
|
|
|
: "${INFINITO_CONTAINER:?INFINITO_CONTAINER not set after sourcing load.sh}"
|
|
: "${INFINITO_SRC_DIR:?INFINITO_SRC_DIR not set after sourcing load.sh}"
|
|
|
|
if ! docker ps --filter "name=${INFINITO_CONTAINER}" --format '{{.Names}}' | grep -q .; then
|
|
if docker ps -a --filter "name=${INFINITO_CONTAINER}" --format '{{.Names}}' | grep -q .; then
|
|
echo "[clean-container-owned] starting stopped container ${INFINITO_CONTAINER}"
|
|
docker start "${INFINITO_CONTAINER}" >/dev/null
|
|
else
|
|
echo "[clean-container-owned] no ${INFINITO_CONTAINER} container exists — nothing to clean" >&2
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
# The tasks/groups/*.yml files are regenerated by `make setup`; the
|
|
# build/install.stamp is regenerated by `make install`. Both are safe
|
|
# to delete unconditionally — the next make run will produce them
|
|
# fresh with whatever UID is then current.
|
|
echo "[clean-container-owned] removing container-owned generated artefacts inside ${INFINITO_CONTAINER}"
|
|
docker exec -i "${INFINITO_CONTAINER}" sh -lc "
|
|
set -eu
|
|
cd '${INFINITO_SRC_DIR}'
|
|
rm -rf build
|
|
find tasks/groups -mindepth 1 -name '*-roles.yml' -delete
|
|
"
|
|
echo "[clean-container-owned] done"
|