#!/usr/bin/env bash # ───────────────────────────────────────────────────────────────────────────── # Arcline OS — overlay application # # scripts/apply-overlays.sh # # overlays/ is organised as layered filesystem trees: # overlays/base/ → every edition # overlays// → that edition only # # Files are copied preserving structure and permissions. Later layers win. # overlays/base is applied first, then the edition overlay. # ───────────────────────────────────────────────────────────────────────────── set -euo pipefail source "$(dirname "${BASH_SOURCE[0]}")/common.sh" TARGET="${1:?usage: apply-overlays.sh }" EDITION="${2:?usage: apply-overlays.sh }" validate_edition "$EDITION" [[ -d "$TARGET" ]] || die "rootfs '$TARGET' does not exist" apply_layer() { local layer="$1" local src="$ROOT/overlays/$layer" [[ -d "$src" ]] || { warn "overlay layer '$layer' not present, skipping"; return 0; } log "applying overlay layer: $layer" # Copy the *contents* of the layer dir into the rootfs, keeping dotfiles, # symlinks, and permissions. Never clobber across layers silently — but # cp -a with overwrite is the desired "later layer wins" behaviour here. cp -a "$src/." "$TARGET/" } apply_layer base apply_layer "$EDITION" log "overlays applied ✓"