homelab-codex-ws/scripts/ha/lib/apply_gitignore.sh
oskar ee48319a86 feat(ha): skeleton for Home Assistant configs-as-code subproject
Structure only, no deploy path: DESIGN.md decision registry (phasing,
per-instance adapter, bidirectional sync with drift-abort on deploy,
reload-vs-restart gating, token handling), instances.yaml (ken/piha via
docker-exec, chelsty-ha via api), config/storage-export/fixtures dirs,
and a read-only scripts/ha/import.sh (docker-exec adapter only) with a
canonical YAML normalize+split library and an offline determinism test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-21 15:29:39 +02:00

34 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
# Delete files from an extracted /config tree that match
# services/home-assistant/.gitignore patterns.
#
# Intentionally NOT a full gitignore engine — the exclusion list is small
# and fixed (see DESIGN.md, "Scope"), so each line is applied as either a
# directory-name prune (trailing "/") or a path/basename glob.
set -euo pipefail
apply_gitignore_filter() {
local root_dir="$1"
local gitignore_file="$2"
if [[ ! -f "$gitignore_file" ]]; then
echo "apply_gitignore_filter: gitignore file not found: $gitignore_file" >&2
return 1
fi
local pattern
while IFS= read -r pattern; do
[[ -z "$pattern" || "$pattern" == \#* ]] && continue
if [[ "$pattern" == */ ]]; then
local dirname="${pattern%/}"
find "$root_dir" -type d -name "$dirname" -prune -exec rm -rf {} +
elif [[ "$pattern" == */* ]]; then
# path-relative pattern, e.g. ".storage/auth*"
find "$root_dir" -type f -path "*/${pattern}" -delete
else
find "$root_dir" -type f -name "$pattern" -delete
fi
done < "$gitignore_file"
}