Harden install.sh: prune only directories, gate before mkdir

This commit is contained in:
Your Name
2026-08-24 15:47:02 -04:00
parent 0ef44264fa
commit 53571e9cd0
+3 -2
View File
@@ -15,8 +15,6 @@ echo "==> dev_agent_team installer"
echo "==> Source: $ROOT/agents"
echo "==> Destination: $TARGET"
mkdir -p "$TARGET"
# Resolve the agent source list into an array up front (nullglob: no match
# means an empty array, not a literal glob string).
shopt -s nullglob
@@ -30,6 +28,8 @@ if (( ${#AGENT_FILES[@]} < EXPECTED_COUNT )); then
exit 1
fi
mkdir -p "$TARGET"
STAMP="$(date +%Y%m%d_%H%M%S)_$$" # PID suffix keeps rapid reruns distinct
BACKUP_DIR="$TARGET/.backup/$STAMP"
@@ -56,6 +56,7 @@ if (( backed_up > 0 )); then
excess=$(( ${#backup_dirs[@]} - KEEP_BACKUPS ))
if (( excess > 0 )); then
for prune_dir in "${backup_dirs[@]:0:excess}"; do
[ -d "$prune_dir" ] || continue
rm -rf "$prune_dir"
echo " pruned old backup: .backup/$(basename "$prune_dir")"
done