#!/usr/bin/env bash
# packs/ops-scripts/install-010-bin.sh -- link team ops scripts into PATH.
#
# Mutates: symlinks this pack's bin/* into ~/.local/bin (created if needed).
# ~/.local/bin is on the default PATH via ~/.profile on Ubuntu; a note is
# printed if it is not currently on PATH. Existing files are backed up.
#
# Usage: bash install-010-bin.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"

BIN_DST="$HOME/.local/bin"
ensure_dir "$BIN_DST"

found=0
for f in "$PACK_DIR"/bin/*; do
    [ -f "$f" ] || continue
    found=1
    backup_then_link "$f" "$BIN_DST/$(basename "$f")"
done
if [ "$found" -eq 0 ]; then
    fail "no scripts found in $PACK_DIR/bin"
    exit 2
fi

case ":$PATH:" in
    *":$BIN_DST:"*) ok "$BIN_DST is on PATH" ;;
    *) warn "$BIN_DST is not on PATH in this shell; log out/in (Ubuntu adds it via ~/.profile)" ;;
esac
