#!/usr/bin/env bash
# packs/shell/install-010-fence.sh -- source team shell files from ~/.bashrc.
#
# Mutates: writes/updates ONE fenced block in ~/.bashrc that sources this
# pack's files/*.sh from wherever the toolkit clone lives. Re-running
# replaces the fence (never append-duplicates). ~/.bashrc is backed up to
# ~/.bashrc.bak.<timestamp> before the first change.
#
# Usage: bash install-010-fence.sh [TOOLKIT_DRY_RUN=1 to preview]
# Exit codes: 0 PROCEED, 1 HOLD, 2 precondition missing. ASCII + LF.
set -euo pipefail
shopt -s inherit_errexit 2>/dev/null || true
IFS=$'\n\t'
PACK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. "$PACK_DIR/../../lib/lib-install.sh"
# The fence references the clone location measured NOW (no hardcoded paths).
FILES_DIR="$PACK_DIR/files"
bashrc_fence "$HOME/.bashrc" <<BLOCK
# Managed by ops-toolkit (packs/shell). Do not edit inside this fence:
# re-installs replace it. Source: $FILES_DIR
if [ -d "$FILES_DIR" ]; then
for _ops_f in "$FILES_DIR"/*.sh; do
[ -r "\$_ops_f" ] && . "\$_ops_f"
done
unset _ops_f
fi
BLOCK
info "open a new shell (or 'source ~/.bashrc') to pick up the helpers"