#!/usr/bin/env bash
# packs/tmux/install-010-core.sh -- install tmux and check the version floor.
#
# Mutates: installs the 'tmux' apt package if absent (via sudo when non-root).
# Floor rationale: tmux >= 3.2 for popup -e / current plugin compatibility;
# Ubuntu 22.04 ships 3.2a, 24.04 ships 3.4 (floor, not pin).
#
# Usage: bash install-010-core.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"
TMUX_MIN="3.2"
if ! command -v tmux >/dev/null 2>&1; then
info "tmux not found; installing via apt"
apt_install tmux
fi
if command -v tmux >/dev/null 2>&1; then
# Capture whole output, then extract (never pipe-and-hope).
TMUX_V_RAW=$(tmux -V 2>&1 || true)
TMUX_V=$(printf '%s' "$TMUX_V_RAW" | awk '{print $2}')
require_version tmux "$TMUX_V" "$TMUX_MIN"
else
if [ "${TOOLKIT_DRY_RUN:-0}" = "1" ]; then
warn "dry-run: tmux not installed yet, version floor not checked"
else
fail "tmux still not on PATH after install attempt"
exit 2
fi
fi