#!/usr/bin/env bash # Shared helpers: logging, sudo, preflight checks, idempotency primitives. if [[ -t 1 ]] || [[ "${FORCE_COLOR:-0}" == "1" ]]; then BOLD=$'\033[1m' DIM=$'\033[2m' RED=$'\033[31m' GREEN=$'\033[32m' YELLOW=$'\033[33m' BLUE=$'\033[34m' RESET=$'\033[0m' else BOLD="" DIM="" RED="" GREEN="" YELLOW="" BLUE="" RESET="" fi step() { printf '\n%s==>%s %s%s%s\n' "$BLUE" "$RESET" "$BOLD" "$*" "$RESET"; } info() { printf ' %s\n' "$*"; } ok() { printf ' %s✓%s %s\n' "$GREEN" "$RESET" "$*"; } warn() { printf ' %s!%s %s\n' "$YELLOW" "$RESET" "$*" >&2; } err() { printf ' %s✗%s %s\n' "$RED" "$RESET" "$*" >&2; } # Run as root via sudo, preserving prompt visibility. as_root() { sudo "$@"; } require_not_root() { if [[ $EUID -eq 0 ]]; then err "Do not run this script as root. It will sudo where needed." exit 1 fi } # Package management (pkg_installed, pkg_install, etc.) and distro detection # live in lib/distro.sh. Source it after this file. # # yay_install is kept as an alias for code paths that explicitly want AUR # packages even on a distro-agnostic call site (rare). On non-Arch distros it # falls back to pkg_install. yay_install() { if [[ "${DISTRO:-}" == "arch" ]] && command -v yay >/dev/null 2>&1; then local missing=() local p for p in "$@"; do pkg_installed "$p" || missing+=("$p") done if [[ ${#missing[@]} -eq 0 ]]; then ok "Already installed: $*" return 0 fi info "Installing (AUR): ${missing[*]}" yay -S --needed --noconfirm "${missing[@]}" else pkg_install "$@" fi }