#!/bin/sh
# shellcheck shell=bash disable=SC1112  # (SC1112: the data below has typographic quotes in plain text)
# boots-installer: dev-tools-installer v1.1.4 (commit b568a08fffea648c680b1e593407547d8739558f)
#   curl -fsSL https://magnus167.github.io/dev-tools-installer/v1.1.4/install.sh | bash -s -- <combo | pm tool-id...>    (--help for more)
# Page: https://magnus167.github.io/dev-tools-installer/v1.1.4/   Source: https://github.com/Magnus167/dev-tools-installer
# Generated from that version's index.html by scripts/build-installer.mjs: it builds the same script
# the page shows for the same selection (--print prints it), saves it to a temp file and runs it.
#
# This first part is POSIX sh. Under any shell but bash (Alpine has no bash) it installs bash if
# needed (apk) and runs this installer again under bash. Everything after it is bash.

boots_usage() {
  cat <<'BOOTS_HELP'
dev-tools-installer v1.1.4 (commit b568a08): developer tools for Linux, installed with
your distro's package manager plus official upstream releases where needed.
Page:   https://magnus167.github.io/dev-tools-installer/v1.1.4/
Source: https://github.com/Magnus167/dev-tools-installer

Usage:  curl -fsSL https://magnus167.github.io/dev-tools-installer/v1.1.4/install.sh | bash -s -- ARGS
        (on Alpine, which has no bash, pipe into sh instead: it installs bash first)

ARGS
  <combo>                          install a selection made on the page, e.g. apt-hra0le
                                   (the page link for it is https://magnus167.github.io/dev-tools-installer/v1.1.4/#apt-hra0le)
  <pm> <tool-id>... [--no-shell]   install these tools with this package manager
  --print <combo | pm tool-id...>  print the generated script and exit; nothing is installed
  --list [pm]                      list the tool ids; with a pm, how each one installs there
  --help                           show this help

  --no-shell   leave PATH and tool hooks out of ~/.bashrc or ~/.zshrc (nvm and SDKMAN setup
               and shell functions such as mkcd still go in)
  <pm>         apt     Debian, Ubuntu, Mint
               dnf     Fedora, RHEL 8+, Rocky, Alma
               apk     Alpine
               pacman  Arch, Manjaro, EndeavourOS
               zypper  openSUSE, SLES
               yum     CentOS/RHEL 7, Amazon Linux 2 — end of life

Examples
  curl -fsSL https://magnus167.github.io/dev-tools-installer/v1.1.4/install.sh | bash -s -- apt git docker node
  curl -fsSL https://magnus167.github.io/dev-tools-installer/v1.1.4/install.sh | bash -s -- --print dnf ripgrep fd bat
  curl -fsSL https://magnus167.github.io/dev-tools-installer/v1.1.4/install.sh | sh -s -- apk git jq

It builds the same script the page shows for that selection, saves it to a temp file and runs it.
Read it first (--print). Run it as your normal user, not with sudo: it calls sudo (or doas) itself
for system packages, and under sudo it stops unless BOOTS_ALLOW_ROOT=1. Everything else goes under
$HOME (mostly ~/.local/bin), Go in /usr/local/go. Re-running is safe: installed tools are skipped.
A combo whose digits spell a tool id (apt-jq) is taken for a typo of "apt jq"; write apt-0jq.

Exit status: 0 done; 1 something did not install (the script's summary says what);
2 bad arguments, or a combo made by a newer version (nothing was changed).
BOOTS_INSTALL_URL overrides where "| sh" fetches this installer again under bash (https:// only,
or http://localhost for tests; default https://magnus167.github.io/dev-tools-installer/v1.1.4/install.sh).
BOOTS_HELP
}

# Under sudo (or doas) the tools and shell setup would go to root's home: stop, unless asked not to.
boots_root_guard() {
  boots_by="${SUDO_USER:-${DOAS_USER:-}}"
  if [ "$(id -u)" -eq 0 ] && [ -n "$boots_by" ] && [ "$boots_by" != root ] && [ "${BOOTS_ALLOW_ROOT:-}" != 1 ]; then
    echo "install.sh: run this as your normal user, not with sudo: it calls sudo itself when it needs to." >&2
    echo "install.sh: (under sudo it would install into root's home; nothing was changed. To do that anyway:" >&2
    echo "install.sh:  ... | sudo env BOOTS_ALLOW_ROOT=1 bash -s -- ...)" >&2
    exit 2
  fi
}

if [ -z "${BASH_VERSION:-}" ]; then
  boots_file=""
  if [ -f "$0" ] && grep -q '^# boots-installer: ' "$0" 2>/dev/null; then boots_file=$0
  # piped (curl ... | sh): read the rest of the script, which sh never runs, so the download finishes
  # cleanly instead of failing on a closed pipe; the bash part is fetched again below
  elif [ ! -t 0 ]; then cat >/dev/null 2>&1
  fi
  boots_mode=run; boots_sel=""
  for boots_a in "$@"; do
    case $boots_a in
      -h|--help) boots_usage; exit 0 ;;
      --print|--list) boots_mode=$boots_a ;;
      -*) ;;
      *) boots_sel="$boots_sel $boots_a" ;;
    esac
  done
  boots_sel=${boots_sel# }
  if [ "$#" -eq 0 ]; then boots_usage >&2; exit 2; fi
  if [ "$boots_mode" = run ]; then boots_root_guard; fi
  if ! command -v bash >/dev/null 2>&1; then
    if [ "$boots_mode" != run ]; then
      echo "install.sh: $boots_mode needs bash, which is not installed here; nothing was changed." >&2
      case $boots_mode:$boots_sel in
        --print:*-*) echo "install.sh: read the script in the page instead: https://magnus167.github.io/dev-tools-installer/v1.1.4/#${boots_sel%% *}" >&2 ;;
        --print:?*) echo "install.sh: read the script in the page instead: https://magnus167.github.io/dev-tools-installer/v1.1.4/ (pick ${boots_sel%% *} and: ${boots_sel#* })" >&2 ;;
      esac
      echo "install.sh: or run it on any machine with bash: curl -fsSL https://magnus167.github.io/dev-tools-installer/v1.1.4/install.sh | bash -s -- $*" >&2
      exit 1
    fi
    if command -v apk >/dev/null 2>&1; then
      echo "==> installing bash, which this installer needs"
      if [ "$(id -u)" -eq 0 ]; then apk add bash
      elif command -v doas >/dev/null 2>&1; then doas apk add bash
      elif command -v sudo >/dev/null 2>&1; then sudo apk add bash
      else echo "install.sh: installing bash needs root, doas or sudo" >&2; false
      fi || exit 1
    else
      echo "install.sh: this installer needs bash; install it and run this again" >&2
      exit 1
    fi
  fi
  # run from a file (sh install.sh ...): hand the same file to bash
  if [ -n "$boots_file" ]; then exec bash "$boots_file" "$@"; fi
  # piped (curl ... | sh -s -- ...): fetch this same version again and run it under bash.
  # BOOTS_INSTALL_URL may point elsewhere, but only over https (or http on this machine, for tests).
  boots_url="https://magnus167.github.io/dev-tools-installer/v1.1.4/install.sh"
  case ${BOOTS_INSTALL_URL:-} in
    '') ;;
    *@*|*[[:space:]]*) boots_urlok=no ;;
    https://*|http://localhost/*|http://localhost:*|http://127.0.0.1/*|http://127.0.0.1:*) boots_url=$BOOTS_INSTALL_URL ;;
    *) boots_urlok=no ;;
  esac
  if [ "${boots_urlok:-}" = no ]; then
    echo "install.sh: ignoring BOOTS_INSTALL_URL=$BOOTS_INSTALL_URL (only https://, or http://localhost for tests); using $boots_url" >&2
  fi
  boots_tmp="$(mktemp "${TMPDIR:-/tmp}/boots-installer.XXXXXX")" || exit 1
  if command -v curl >/dev/null 2>&1; then curl -fsSL "$boots_url" -o "$boots_tmp"
  elif command -v wget >/dev/null 2>&1; then wget -qO "$boots_tmp" "$boots_url"
  else echo "install.sh: curl or wget is needed to fetch $boots_url" >&2; false
  fi || { echo "install.sh: could not fetch $boots_url" >&2; rm -f "$boots_tmp"; exit 1; }
  bash "$boots_tmp" "$@"
  boots_rc=$?
  rm -f "$boots_tmp"
  exit "$boots_rc"
fi

# ==================================================================== bash from here on (3.2 or newer)
# bash started as sh runs in POSIX mode; the code below wants normal bash
set +o posix 2>/dev/null

# ---------------------------------------------------------------- data (generated from index.html)
BOOTS_VERSION=v1.1.4
BOOTS_COMMIT_SHORT=b568a08
BOOTS_SITE='https://magnus167.github.io/dev-tools-installer/'
BOOTS_SITE_HERE='https://magnus167.github.io/dev-tools-installer/v1.1.4/'
BOOTS_REPO='https://github.com/Magnus167/dev-tools-installer'

# package managers: the combo prefixes
PM_IDS=(apt dnf yum apk pacman zypper)
# the same, in display order
PM_LIST=(apt dnf apk pacman zypper yum)
# distros per package manager, in PM_IDS order
PM_DISTROS=('Debian, Ubuntu, Mint' 'Fedora, RHEL 8+, Rocky, Alma'
  'CentOS/RHEL 7, Amazon Linux 2 — end of life' Alpine 'Arch, Manjaro, EndeavourOS' 'openSUSE, SLES')

# tools, in TOOLS order: index i is combo bit i+1
T_ID=(git python docker gh ripgrep fzf jq uv rust go zoxide lazygit lazydocker bottom glow yq gron jnv
  harlequin visidata clipcat act podman apptainer kubectl k9s helm kind dive fd bat eza delta dust duf
  tealdeer sd hyperfine btop ncdu starship direnv atuin just mise shellcheck precommit xh neovim tmux zellij
  yazi node bun deno mkcd extract serve opentofu terraform awscli ansible kubectx gitlfs sqlite3 duckdb ffmpeg
  pandoc java mkcert htop tree rsync wget lsof strace iotop sysstat 7zip watch entr nmap mtr traceroute dig
  whois tcpdump netcat socat iperf3 checkip)
T_NAME=(git 'python3 + pip' docker gh ripgrep fzf jq uv 'rust + cargo' go zoxide lazygit lazydocker bottom
  glow yq gron jnv harlequin visidata clipcat act podman apptainer kubectl k9s helm kind dive fd bat eza delta
  dust duf tealdeer sd hyperfine btop ncdu starship direnv atuin just mise shellcheck pre-commit xh neovim
  tmux zellij yazi 'node (via nvm)' bun deno mkcd extract serve opentofu terraform 'aws cli' ansible
  'kubectx + kubens' git-lfs sqlite3 duckdb ffmpeg pandoc 'java (via SDKMAN)' mkcert htop tree rsync wget lsof
  strace iotop sysstat 7zip watch entr nmap mtr traceroute dig whois tcpdump netcat socat iperf3 checkip)
T_BIN=(git python3 docker gh rg fzf jq uv cargo go zoxide lazygit lazydocker btm glow yq gron jnv harlequin vd
  '' '' podman apptainer kubectl k9s helm kind dive fd bat eza delta dust duf tldr sd hyperfine btop ncdu
  starship direnv atuin just mise shellcheck pre-commit xh nvim tmux zellij yazi node bun deno '' '' '' tofu
  terraform aws ansible kubectx git-lfs sqlite3 duckdb ffmpeg pandoc java mkcert htop tree rsync wget lsof
  strace iotop iostat 7zz watch entr nmap mtr traceroute dig whois tcpdump nc socat iperf3 '')
T_GROUP=(Essentials Essentials Essentials Essentials 'Search and data' 'Search and data' 'Search and data'
  Languages Languages Languages Shell 'Terminal apps' 'Terminal apps' 'Terminal apps' 'Terminal apps'
  'Search and data' 'Search and data' 'Search and data' 'Terminal apps' 'Terminal apps' Shell Shell Containers
  Containers Containers Containers Containers Containers Containers 'Files and text' 'Files and text'
  'Files and text' 'Files and text' 'Files and text' 'Files and text' 'Files and text' 'Files and text'
  'Dev workflow' 'Terminal apps' 'Terminal apps' Shell 'Dev workflow' Shell 'Dev workflow' 'Dev workflow'
  'Dev workflow' 'Dev workflow' 'Dev workflow' 'Terminal apps' 'Terminal apps' 'Terminal apps' 'Terminal apps'
  Languages Languages Languages Shell Shell Shell 'Infra and cloud' 'Infra and cloud' 'Infra and cloud'
  'Infra and cloud' Containers Essentials Data Data Data Data Languages 'Dev workflow' System System System
  System System System System System System System System Network Network Network Network Network Network
  Network Network Network Shell)
T_DESC=('Version control.' 'Python 3 with pip and venv.' 'Containers, with the compose plugin.'
  'GitHub CLI, from GitHub’s own repo where needed.' 'grep, but absurdly fast.'
  'Fuzzy finder that pipes into everything.' 'JSON Swiss Army knife.'
  'Fast Python package and project manager.' 'The Rust toolchain, via rustup.' 'The Go toolchain.'
  'cd that learns your habits: z proj jumps there.' 'Terminal UI for git.' 'Terminal UI for docker.'
  'System and process monitor.' 'Render markdown in the terminal.' 'jq, but for YAML.'
  'Flattens JSON so you can grep it.' 'Interactive jq REPL.'
  'SQL IDE in the terminal (DuckDB, Postgres and more).' 'Spreadsheet TUI for any tabular file.'
  'Copy a file or piped text to your local clipboard, even over SSH.'
  'Activate the nearest .venv from anywhere in a project.' 'Daemonless, rootless containers.'
  'Containers for HPC and shared machines (formerly Singularity).' 'Command line for Kubernetes clusters.'
  'Terminal UI for Kubernetes.' 'Package manager for Kubernetes.'
  'Local Kubernetes clusters in docker containers.' 'Explore the layers of a container image.'
  'find, but friendlier and faster.' 'cat with syntax highlighting and git marks.'
  'ls with colours, icons and git status.' 'Readable syntax-highlighted git diffs.'
  'du, but as a tree you can read.' 'df, but as a tidy table.' 'tldr: short examples instead of man pages.'
  'sed, but with sane regex syntax.' 'Benchmark any command, with stats.'
  'Pretty CPU, memory, disk and network monitor.' 'Browse disk usage and delete what is eating it.'
  'Fast, minimal prompt for any shell.' 'Loads and unloads env vars per directory.'
  'Searchable, syncable shell history (takes over Ctrl-R).' 'A simpler make for project commands.'
  'One tool for language versions, env vars and tasks.' 'Linter for shell scripts.'
  'Run linters and formatters on every git commit.' 'Friendly, fast HTTP client (httpie-style).'
  'Modern Vim, current release.' 'Terminal multiplexer: sessions that survive a dropped SSH link.'
  'Friendlier terminal multiplexer with built-in layouts.' 'Fast terminal file manager with previews.'
  'Node.js LTS, managed with nvm.' 'Fast JavaScript runtime, bundler and package manager.'
  'Secure JavaScript and TypeScript runtime.' 'mkdir -p and cd in one go.'
  'Unpack any archive with one command.' 'Serve the current directory over HTTP (needs python3).'
  'Open-source Terraform fork: infrastructure as code.'
  'Infrastructure as code, from HashiCorp’s own release.' 'AWS command line, v2.'
  'Agentless automation and config management.' 'Switch Kubernetes contexts and namespaces fast.'
  'Git extension for large files.' 'SQLite shell.' 'Fast analytical SQL on files, in one binary.'
  'Convert, trim and inspect audio and video.' 'Convert documents between markup formats.'
  'Current Temurin JDK, managed with SDKMAN (Alpine: openjdk21).'
  'Locally trusted HTTPS certs for development.' 'Interactive process viewer.' 'Directory listing as a tree.'
  'Fast, resumable file sync and copy.' 'Download files from the command line.'
  'Who’s holding that file or port.' 'Watch the system calls a program makes.'
  'Which process is hammering the disk.' 'iostat, mpstat and sar for CPU and disk stats.'
  '7z, rar and many other archive formats (as 7zz).' 'Re-run a command every few seconds.'
  'Run a command whenever files change.' 'Scan hosts and open ports.' 'traceroute and ping in one live view.'
  'Show the hops to a host.' 'Query DNS servers.' 'Look up who owns a domain or IP.'
  'Capture and read network packets.' 'Read and write raw TCP and UDP connections.'
  'netcat with more plumbing: sockets, files, TLS.' 'Measure network throughput between two hosts.'
  'Print your public IP address (curl, or wget).')
# lowercase id, name and binary, for suggestions
T_HAY=('git git git' 'python python3 + pip python3' 'docker docker docker' 'gh gh gh' 'ripgrep ripgrep rg'
  'fzf fzf fzf' 'jq jq jq' 'uv uv uv' 'rust rust + cargo cargo' 'go go go' 'zoxide zoxide zoxide'
  'lazygit lazygit lazygit' 'lazydocker lazydocker lazydocker' 'bottom bottom btm' 'glow glow glow' 'yq yq yq'
  'gron gron gron' 'jnv jnv jnv' 'harlequin harlequin harlequin' 'visidata visidata vd' 'clipcat clipcat '
  'act act ' 'podman podman podman' 'apptainer apptainer apptainer' 'kubectl kubectl kubectl' 'k9s k9s k9s'
  'helm helm helm' 'kind kind kind' 'dive dive dive' 'fd fd fd' 'bat bat bat' 'eza eza eza'
  'delta delta delta' 'dust dust dust' 'duf duf duf' 'tealdeer tealdeer tldr' 'sd sd sd'
  'hyperfine hyperfine hyperfine' 'btop btop btop' 'ncdu ncdu ncdu' 'starship starship starship'
  'direnv direnv direnv' 'atuin atuin atuin' 'just just just' 'mise mise mise'
  'shellcheck shellcheck shellcheck' 'precommit pre-commit pre-commit' 'xh xh xh' 'neovim neovim nvim'
  'tmux tmux tmux' 'zellij zellij zellij' 'yazi yazi yazi' 'node node (via nvm) node' 'bun bun bun'
  'deno deno deno' 'mkcd mkcd ' 'extract extract ' 'serve serve ' 'opentofu opentofu tofu'
  'terraform terraform terraform' 'awscli aws cli aws' 'ansible ansible ansible'
  'kubectx kubectx + kubens kubectx' 'gitlfs git-lfs git-lfs' 'sqlite3 sqlite3 sqlite3' 'duckdb duckdb duckdb'
  'ffmpeg ffmpeg ffmpeg' 'pandoc pandoc pandoc' 'java java (via sdkman) java' 'mkcert mkcert mkcert'
  'htop htop htop' 'tree tree tree' 'rsync rsync rsync' 'wget wget wget' 'lsof lsof lsof'
  'strace strace strace' 'iotop iotop iotop' 'sysstat sysstat iostat' '7zip 7zip 7zz' 'watch watch watch'
  'entr entr entr' 'nmap nmap nmap' 'mtr mtr mtr' 'traceroute traceroute traceroute' 'dig dig dig'
  'whois whois whois' 'tcpdump tcpdump tcpdump' 'netcat netcat nc' 'socat socat socat' 'iperf3 iperf3 iperf3'
  'checkip checkip ')
# indices of the tools each one requires
T_REQ=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 8 7 7 '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
  '' '' '' '' '' '' '' '' '' '' '' 7 '' '' '' '' '' '' '' '' '' '' '' '' '' '' 7 '' '' '' '' '' '' '' '' '' ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
# 1: needs the compiler toolchain
T_BUILD=('' '' '' '' '' '' '' '' 1 '' '' '' '' '' '' '' '' 1 '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
# shell hook snippet and its flags (initAlways, initUpstreamOnly, initLast)
T_INIT=('' '' '' '' '' rc-fzf '' '' '' '' rc-zoxide '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
  '' '' '' '' '' '' '' '' '' '' rc-starship rc-direnv rc-atuin '' rc-mise '' '' '' '' '' '' '' rc-node '' ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' rc-java '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
  '' '')
T_INITALWAYS=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 1 '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 1
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
T_INITUP=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 1 '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' 1 ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
T_INITLAST=('' '' '' '' '' '' '' '' '' '' 1 '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
# shell function snippet, for shell-only tools
T_RC=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' rc-clipcat rc-act '' '' '' '' '' '' '' '' ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' rc-mkcd rc-extract rc-serve '' '' ''
  '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' rc-checkip)
T_DOCKER=2
# tool ids and names that a combo's digits could spell (see safeCombo() in the page)
T_WORDS=(git python docker gh ripgrep fzf jq uv rust go zoxide lazygit lazydocker bottom glow yq gron jnv
  harlequin visidata clipcat act podman apptainer kubectl k9s helm kind dive fd bat eza delta dust duf
  tealdeer sd hyperfine btop ncdu starship direnv atuin just mise shellcheck precommit xh neovim tmux zellij
  yazi node bun deno mkcd extract serve opentofu terraform awscli ansible kubectx gitlfs sqlite3 duckdb ffmpeg
  pandoc java mkcert htop tree rsync wget lsof strace iotop sysstat 7zip watch entr nmap mtr traceroute dig
  whois tcpdump netcat socat iperf3 checkip)

# page order of groups, with the tool indices in each
G_NAME=(Essentials Languages Containers 'Infra and cloud' 'Files and text' 'Search and data' Data
  'Dev workflow' 'Terminal apps' Shell System Network)
G_TOOLS=('0 1 2 3 63' '7 8 9 52 53 54 68' '22 23 24 25 26 27 28 62' '58 59 60 61' '29 30 31 32 33 34 36 35'
  '4 5 6 15 16 17' '64 65 66 67' '37 41 43 44 45 46 47 69' '11 12 13 14 18 19 38 39 48 49 50 51'
  '10 40 42 20 21 55 56 57 90' '70 71 72 73 74 75 76 77 78 79 80' '81 82 83 84 85 86 87 88 89')

# pm_load <pm>: the package manager's commands, and how() of every tool with it (H_*, TOOLS order)
pm_load() {
  case $1 in
    apt)
      P_ID=apt
      P_DISTROS='Debian, Ubuntu, Mint'
      P_REFRESH='$SUDO apt-get update -y'
      P_INSTALL='$SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y "$@"'
      P_BASE='curl ca-certificates tar gzip unzip xz-utils'
      P_BUILD='build-essential pkg-config libssl-dev'
      H_TYPE=(pkg pkg fn pkg pkg pkg pkg fn fn fn fn fn fn fn fn fn fn fn fn fn rc rc pkg fn fn fn fn fn fn fn fn fn
        fn fn pkg pkg pkg pkg pkg pkg fn pkg fn fn fn pkg fn fn fn pkg fn fn fn fn fn rc rc rc fn fn fn fn fn pkg
        pkg fn pkg fn fn pkg pkg pkg pkg pkg pkg pkg pkg pkg fn pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg rc)
      H_VIA=(apt apt get.docker.com apt apt apt apt installer rustup go.dev installer binary binary .deb binary
        binary binary cargo 'uv tool' 'uv tool' 'shell function' 'shell function' apt .deb binary binary binary
        binary binary binary binary binary binary binary apt apt apt apt apt apt binary apt binary binary binary apt
        'uv tool' binary binary apt binary binary nvm binary binary 'shell function' 'shell function'
        'shell function' binary binary installer 'uv tool' binary apt apt binary apt binary SDKMAN apt apt apt apt
        apt apt apt apt apt binary apt apt apt apt apt apt apt apt apt apt apt 'shell function')
      H_PKGS=(git 'python3 python3-pip python3-venv' '' gh ripgrep fzf jq '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' podman '' '' '' '' '' '' '' '' '' '' '' duf tealdeer sd hyperfine btop ncdu '' direnv '' '' '' shellcheck
        '' '' '' tmux '' '' '' '' '' '' '' '' '' '' '' '' '' git-lfs sqlite3 '' ffmpeg '' '' mkcert htop tree rsync
        wget lsof strace iotop sysstat '' procps entr nmap mtr-tiny traceroute dnsutils whois tcpdump netcat-openbsd
        socat iperf3 '')
      H_FB=('' '' '' '' ripgrep-bin fzf-bin jq-bin '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' duf-bin tealdeer-bin sd-bin hyperfine-bin btop-bin ncdu-bin '' direnv-bin '' '' ''
        shellcheck-bin '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' gitlfs-bin '' '' '' '' '' mkcert-bin '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_FBVIA=('' '' '' '' binary binary binary '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' binary binary binary binary binary binary '' binary '' '' '' binary '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' binary '' '' '' '' '' binary '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '')
      H_FN=('' '' docker-get '' '' '' '' uv-script rust-script go-tarball zoxide-script lazygit-bin lazydocker-bin
        bottom-deb glow-bin yq-bin gron-bin jnv-cargo harlequin-uv visidata-uv '' '' '' apptainer-deb kubectl-bin
        k9s-bin helm-bin kind-bin dive-bin fd-bin bat-bin eza-bin delta-bin dust-bin '' '' '' '' '' '' starship-bin
        '' atuin-bin just-bin mise-bin '' precommit-uv xh-bin neovim-tarball '' zellij-bin yazi-bin node-nvm bun-zip
        deno-zip '' '' '' opentofu-bin terraform-bin awscli-zip ansible-uv kubectx-bin '' '' duckdb-bin ''
        pandoc-bin java-sdkman '' '' '' '' '' '' '' '' '' 7zip-bin '' '' '' '' '' '' '' '' '' '' '' '')
      H_PRE=('' '' '' gh-repo-apt '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_POST=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_WHY=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      ;;
    dnf)
      P_ID=dnf
      P_DISTROS='Fedora, RHEL 8+, Rocky, Alma'
      P_REFRESH=':'
      P_INSTALL='$SUDO dnf install -y --setopt=strict=0 "$@"'
      P_BASE='curl ca-certificates tar gzip unzip xz'
      P_BUILD='gcc gcc-c++ make pkgconf-pkg-config openssl-devel'
      H_TYPE=(pkg pkg fn pkg fn fn pkg fn fn fn fn fn fn fn fn fn fn fn fn fn rc rc pkg fn fn fn fn fn fn fn fn fn
        fn fn fn fn fn fn fn fn fn fn fn fn fn fn fn fn fn pkg fn fn fn fn fn rc rc rc fn fn pkg fn fn pkg pkg fn
        pkg fn fn fn pkg pkg pkg pkg pkg pkg pkg pkg fn pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg rc)
      H_VIA=(dnf dnf get.docker.com dnf binary binary dnf installer rustup go.dev installer binary binary binary
        binary binary binary cargo 'uv tool' 'uv tool' 'shell function' 'shell function' dnf EPEL binary binary
        binary binary binary binary binary binary binary binary binary binary binary binary binary binary binary
        binary binary binary binary binary 'uv tool' binary binary dnf binary binary nvm binary binary
        'shell function' 'shell function' 'shell function' binary binary dnf 'uv tool' binary dnf dnf binary dnf
        binary SDKMAN binary dnf dnf dnf dnf dnf dnf dnf dnf binary dnf dnf dnf dnf dnf dnf dnf dnf dnf dnf dnf
        'shell function')
      H_PKGS=(git 'python3 python3-pip' '' gh '' '' jq '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' podman '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' tmux '' '' '' '' '' '' '' '' '' ''
        awscli2 '' '' git-lfs sqlite '' ffmpeg-free '' '' '' htop tree rsync wget lsof strace iotop sysstat ''
        procps-ng entr nmap mtr traceroute bind-utils whois tcpdump nmap-ncat socat iperf3 '')
      H_FB=('' '' '' '' '' '' jq-bin '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' awscli-zip '' '' gitlfs-bin
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_FBVIA=('' '' '' '' '' '' binary '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' installer '' '' binary
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_FN=('' '' docker-dnf '' ripgrep-bin fzf-bin '' uv-script rust-script go-tarball zoxide-script lazygit-bin
        lazydocker-bin bottom-bin glow-bin yq-bin gron-bin jnv-cargo harlequin-uv visidata-uv '' '' '' apptainer-dnf
        kubectl-bin k9s-bin helm-bin kind-bin dive-bin fd-bin bat-bin eza-bin delta-bin dust-bin duf-bin
        tealdeer-bin sd-bin hyperfine-bin btop-bin ncdu-bin starship-bin direnv-bin atuin-bin just-bin mise-bin
        shellcheck-bin precommit-uv xh-bin neovim-tarball '' zellij-bin yazi-bin node-nvm bun-zip deno-zip '' '' ''
        opentofu-bin terraform-bin '' ansible-uv kubectx-bin '' '' duckdb-bin '' pandoc-bin java-sdkman mkcert-bin
        '' '' '' '' '' '' '' '' 7zip-bin '' '' '' '' '' '' '' '' '' '' '' '')
      H_PRE=('' '' '' gh-repo-dnf '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_POST=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_WHY=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      ;;
    yum)
      P_ID=yum
      P_DISTROS='CentOS/RHEL 7, Amazon Linux 2 — end of life'
      P_REFRESH=':'
      P_INSTALL='$SUDO yum install -y "$@"'
      P_BASE='curl ca-certificates tar gzip unzip xz'
      P_BUILD='gcc gcc-c++ make pkgconfig openssl-devel'
      H_TYPE=(pkg pkg fn pkg fn fn fn fn fn fn fn fn fn fn fn fn fn fn skip fn rc rc skip skip fn fn fn fn fn fn fn
        fn fn fn fn fn fn fn fn fn fn fn fn fn fn fn fn fn fn pkg fn fn skip fn skip rc rc rc fn fn fn fn fn fn pkg
        fn skip fn fn fn pkg pkg pkg pkg pkg pkg pkg pkg fn pkg skip pkg pkg pkg pkg pkg pkg pkg pkg pkg rc)
      H_VIA=(yum yum installer yum binary binary binary installer rustup go.dev installer binary binary binary
        binary binary binary cargo unavailable 'uv tool' 'shell function' 'shell function' unavailable unavailable
        binary binary binary binary binary binary binary binary binary binary binary binary binary binary binary
        binary binary binary binary binary binary binary 'uv tool' binary binary yum binary binary unavailable
        binary unavailable 'shell function' 'shell function' 'shell function' binary binary installer 'uv tool'
        binary binary yum binary unavailable binary SDKMAN binary yum yum yum yum yum yum yum yum binary yum
        unavailable yum yum yum yum yum yum yum yum yum 'shell function')
      H_PKGS=(git 'python3 python3-pip' '' gh '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' tmux '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' sqlite '' '' '' '' '' htop tree rsync wget lsof strace iotop sysstat '' procps-ng '' nmap mtr
        traceroute bind-utils whois tcpdump nmap-ncat socat iperf3 '')
      H_FB=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_FBVIA=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_FN=('' '' docker-yum '' ripgrep-bin fzf-bin jq-bin uv-script rust-script go-tarball zoxide-script
        lazygit-bin lazydocker-bin bottom-bin glow-bin yq-bin gron-bin jnv-cargo '' visidata-uv '' '' '' ''
        kubectl-bin k9s-bin helm-bin kind-bin dive-bin fd-bin bat-bin eza-bin delta-bin dust-bin duf-bin
        tealdeer-bin sd-bin hyperfine-bin btop-bin ncdu-bin starship-bin direnv-bin atuin-bin just-bin mise-bin
        shellcheck-bin precommit-uv xh-bin neovim-tarball '' zellij-bin yazi-bin '' bun-zip '' '' '' '' opentofu-bin
        terraform-bin awscli-zip ansible-uv kubectx-bin gitlfs-bin '' duckdb-bin '' pandoc-bin java-sdkman
        mkcert-bin '' '' '' '' '' '' '' '' 7zip-bin '' '' '' '' '' '' '' '' '' '' '' '')
      H_PRE=('' '' '' gh-repo-yum '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_POST=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_WHY=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        'its pyarrow dependency needs a newer glibc than CentOS 7 or Amazon Linux 2 have' '' '' ''
        'not packaged for CentOS 7 or Amazon Linux 2'
        'no package or compatible build for CentOS 7 or Amazon Linux 2' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' ''
        'current Node.js needs a newer glibc than CentOS 7 or Amazon Linux 2 have' ''
        'deno needs a newer glibc than CentOS 7 or Amazon Linux 2 have' '' '' '' '' '' '' '' '' '' '' ''
        'no ffmpeg in the Amazon Linux 2 or CentOS 7 repos' '' '' '' '' '' '' '' '' '' '' '' '' ''
        'not in the Amazon Linux 2 or CentOS 7 repos' '' '' '' '' '' '' '' '' '' '')
      ;;
    apk)
      P_ID=apk
      P_DISTROS=Alpine
      P_REFRESH='$SUDO apk update'
      P_INSTALL='$SUDO apk add "$@"'
      P_BASE='bash curl ca-certificates tar gzip unzip xz'
      P_BUILD='build-base pkgconf openssl-dev'
      H_TYPE=(pkg pkg pkg pkg pkg pkg pkg fn fn pkg pkg pkg fn pkg fn fn fn fn skip fn rc rc pkg pkg fn pkg pkg fn
        fn pkg pkg pkg pkg pkg fn fn pkg pkg pkg pkg fn pkg fn fn fn pkg fn pkg pkg pkg fn fn pkg fn pkg rc rc rc fn
        fn pkg fn fn pkg pkg fn pkg fn pkg fn pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg
        pkg pkg pkg rc)
      H_VIA=(apk apk apk apk apk apk apk installer rustup apk apk apk binary apk binary binary binary cargo
        unavailable 'uv tool' 'shell function' 'shell function' apk apk binary apk apk binary binary apk apk apk apk
        apk binary binary apk apk apk apk binary apk binary binary binary apk 'uv tool' apk apk apk binary binary
        apk binary apk 'shell function' 'shell function' 'shell function' binary binary apk 'uv tool' binary apk apk
        binary apk binary apk binary apk apk apk apk apk apk apk apk apk apk apk apk apk apk apk apk apk apk apk apk
        'shell function')
      H_PKGS=(git 'python3 py3-pip' 'docker docker-cli-compose' github-cli ripgrep fzf jq '' '' go zoxide lazygit ''
        bottom '' '' '' '' '' '' '' '' podman apptainer '' k9s helm '' '' fd bat eza delta dust '' '' sd hyperfine
        btop ncdu '' direnv '' '' '' shellcheck '' xh neovim tmux '' '' 'nodejs npm' '' deno '' '' '' '' '' aws-cli
        '' '' git-lfs sqlite '' ffmpeg '' openjdk21 '' htop tree rsync wget lsof strace iotop sysstat 7zip procps-ng
        entr nmap mtr traceroute bind-tools whois tcpdump netcat-openbsd socat iperf3 '')
      H_FB=('' '' '' '' ripgrep-bin fzf-bin jq-bin '' '' go-tarball zoxide-script lazygit-bin '' '' '' '' '' '' ''
        '' '' '' '' '' '' k9s-bin helm-bin '' '' fd-bin bat-bin eza-bin delta-bin dust-bin '' '' sd-bin
        hyperfine-bin btop-bin ncdu-bin '' direnv-bin '' '' '' shellcheck-bin '' xh-bin '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' gitlfs-bin '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '')
      H_FBVIA=('' '' '' '' binary binary binary '' '' go.dev installer binary '' '' '' '' '' '' '' '' '' '' '' '' ''
        binary binary '' '' binary binary binary binary binary '' '' binary binary binary binary '' binary '' '' ''
        binary '' binary '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' binary '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_FN=('' '' '' '' '' '' '' uv-script rust-script '' '' '' lazydocker-bin '' glow-bin yq-bin gron-bin jnv-cargo
        '' visidata-uv '' '' '' '' kubectl-bin '' '' kind-bin dive-bin '' '' '' '' '' duf-bin tealdeer-bin '' '' ''
        '' starship-bin '' atuin-bin just-bin mise-bin '' precommit-uv '' '' '' zellij-bin yazi-bin '' bun-zip '' ''
        '' '' opentofu-bin terraform-bin '' ansible-uv kubectx-bin '' '' duckdb-bin '' pandoc-bin '' mkcert-bin ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_PRE=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_POST=('' '' docker-post-openrc '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_WHY=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        'its DuckDB dependency has no Alpine (musl) build' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      ;;
    pacman)
      P_ID=pacman
      P_DISTROS='Arch, Manjaro, EndeavourOS'
      P_REFRESH='$SUDO pacman -Syu --noconfirm'
      P_INSTALL='$SUDO pacman -S --noconfirm --needed "$@"'
      P_BASE='curl ca-certificates tar gzip unzip xz'
      P_BUILD='base-devel pkgconf openssl'
      H_TYPE=(pkg pkg pkg pkg pkg pkg pkg fn fn pkg pkg pkg fn pkg pkg fn fn fn fn fn rc rc pkg pkg fn pkg pkg pkg
        pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg fn pkg pkg pkg pkg pkg fn fn fn rc
        rc rc pkg fn pkg fn pkg pkg pkg fn pkg fn fn pkg pkg pkg pkg pkg pkg pkg pkg pkg fn pkg pkg pkg pkg pkg pkg
        pkg pkg pkg pkg pkg rc)
      H_VIA=(pacman pacman pacman pacman pacman pacman pacman installer rustup pacman pacman pacman binary pacman
        pacman binary binary cargo 'uv tool' 'uv tool' 'shell function' 'shell function' pacman pacman binary pacman
        pacman pacman pacman pacman pacman pacman pacman pacman pacman pacman pacman pacman pacman pacman pacman
        pacman pacman pacman pacman pacman 'uv tool' pacman pacman pacman pacman pacman nvm binary binary
        'shell function' 'shell function' 'shell function' pacman binary pacman 'uv tool' pacman pacman pacman
        binary pacman binary SDKMAN pacman pacman pacman pacman pacman pacman pacman pacman pacman binary pacman
        pacman pacman pacman pacman pacman pacman pacman pacman pacman pacman 'shell function')
      H_PKGS=(git 'python python-pip' 'docker docker-compose' github-cli ripgrep fzf jq '' '' go zoxide lazygit ''
        bottom glow '' '' '' '' '' '' '' podman apptainer '' k9s helm kind dive fd bat eza git-delta dust duf
        tealdeer sd hyperfine btop ncdu starship direnv atuin just mise shellcheck '' xh neovim tmux zellij yazi ''
        '' '' '' '' '' opentofu '' aws-cli-v2 '' kubectx git-lfs sqlite '' ffmpeg '' '' mkcert htop tree rsync wget
        lsof strace iotop sysstat '' procps-ng entr nmap mtr traceroute bind whois tcpdump openbsd-netcat socat
        iperf3 '')
      H_FB=('' '' docker-get '' ripgrep-bin fzf-bin jq-bin '' '' go-tarball zoxide-script lazygit-bin '' bottom-bin
        glow-bin '' '' '' '' '' '' '' '' '' '' k9s-bin helm-bin kind-bin dive-bin fd-bin bat-bin eza-bin delta-bin
        dust-bin duf-bin tealdeer-bin sd-bin hyperfine-bin btop-bin ncdu-bin starship-bin direnv-bin atuin-bin
        just-bin mise-bin shellcheck-bin '' xh-bin neovim-tarball '' zellij-bin yazi-bin '' '' '' '' '' ''
        opentofu-bin '' awscli-zip '' kubectx-bin gitlfs-bin '' '' '' '' '' mkcert-bin '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '')
      H_FBVIA=('' '' get.docker.com '' binary binary binary '' '' go.dev installer binary '' binary binary '' '' ''
        '' '' '' '' '' '' '' binary binary binary binary binary binary binary binary binary binary binary binary
        binary binary binary binary binary binary binary binary binary '' binary binary '' binary binary '' '' '' ''
        '' '' binary '' installer '' binary binary '' '' '' '' '' binary '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '')
      H_FN=('' '' '' '' '' '' '' uv-script rust-script '' '' '' lazydocker-bin '' '' yq-bin gron-bin jnv-cargo
        harlequin-uv visidata-uv '' '' '' '' kubectl-bin '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' precommit-uv '' '' '' '' '' node-nvm bun-zip deno-zip '' '' '' '' terraform-bin '' ansible-uv '' '' ''
        duckdb-bin '' pandoc-bin java-sdkman '' '' '' '' '' '' '' '' '' 7zip-bin '' '' '' '' '' '' '' '' '' '' '' '')
      H_PRE=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_POST=('' '' docker-post-systemd '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_WHY=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      ;;
    zypper)
      P_ID=zypper
      P_DISTROS='openSUSE, SLES'
      P_REFRESH='$SUDO zypper --non-interactive --gpg-auto-import-keys refresh'
      P_INSTALL='$SUDO zypper --non-interactive install "$@"'
      P_BASE='curl ca-certificates tar gzip unzip xz'
      P_BUILD='gcc gcc-c++ make pkg-config libopenssl-devel'
      H_TYPE=(pkg pkg pkg pkg pkg pkg pkg fn fn fn fn fn fn fn fn fn fn fn fn fn rc rc pkg pkg fn fn pkg fn fn pkg
        pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg fn pkg fn fn fn fn fn fn fn pkg fn fn fn fn fn rc rc rc fn fn fn fn
        fn pkg pkg fn skip fn fn fn pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg pkg
        rc)
      H_VIA=(zypper zypper zypper zypper zypper zypper zypper installer rustup go.dev installer binary binary binary
        binary binary binary cargo 'uv tool' 'uv tool' 'shell function' 'shell function' zypper zypper binary binary
        zypper binary binary zypper zypper zypper zypper zypper zypper zypper zypper zypper zypper zypper binary
        zypper binary binary binary binary 'uv tool' binary binary zypper binary binary nvm binary binary
        'shell function' 'shell function' 'shell function' binary binary installer 'uv tool' binary zypper zypper
        binary unavailable binary SDKMAN binary zypper zypper zypper zypper zypper zypper zypper zypper zypper
        zypper zypper zypper zypper zypper zypper zypper zypper zypper zypper zypper 'shell function')
      H_PKGS=(git 'python3 python3-pip' 'docker docker-compose' gh ripgrep fzf jq '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' podman apptainer '' '' helm '' '' fd bat eza git-delta dust duf tealdeer sd hyperfine btop ncdu
        '' direnv '' '' '' '' '' '' '' tmux '' '' '' '' '' '' '' '' '' '' '' '' '' git-lfs sqlite3 '' '' '' '' ''
        htop tree rsync wget lsof strace iotop sysstat 7zip procps entr nmap mtr traceroute bind-utils whois tcpdump
        netcat-openbsd socat iperf '')
      H_FB=('' '' docker-get '' ripgrep-bin fzf-bin jq-bin '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        helm-bin '' '' fd-bin bat-bin eza-bin delta-bin dust-bin duf-bin tealdeer-bin sd-bin hyperfine-bin btop-bin
        ncdu-bin '' direnv-bin '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' gitlfs-bin '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' 7zip-bin '' '' '' '' '' '' '' '' '' '' '' '')
      H_FBVIA=('' '' get.docker.com '' binary binary binary '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        binary '' '' binary binary binary binary binary binary binary binary binary binary binary '' binary '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' binary '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        binary '' '' '' '' '' '' '' '' '' '' '' '')
      H_FN=('' '' '' '' '' '' '' uv-script rust-script go-tarball zoxide-script lazygit-bin lazydocker-bin
        bottom-bin glow-bin yq-bin gron-bin jnv-cargo harlequin-uv visidata-uv '' '' '' '' kubectl-bin k9s-bin ''
        kind-bin dive-bin '' '' '' '' '' '' '' '' '' '' '' starship-bin '' atuin-bin just-bin mise-bin
        shellcheck-bin precommit-uv xh-bin neovim-tarball '' zellij-bin yazi-bin node-nvm bun-zip deno-zip '' '' ''
        opentofu-bin terraform-bin awscli-zip ansible-uv kubectx-bin '' '' duckdb-bin '' pandoc-bin java-sdkman
        mkcert-bin '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_PRE=('' '' '' gh-repo-zypper '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_POST=('' '' docker-post-systemd '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '')
      H_WHY=('' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        'Leap ships a stripped ffmpeg 3.4 (a full build needs Packman)' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''
        '' '' '' '' '' '' '' '' '')
      ;;
    *) return 1 ;;
  esac
}

snip() { # snip <name>: the snippet's text, exactly as the page uses it, in REPLY
  case $1 in
    preamble) REPLY='# Run as your normal user: under sudo, ~/.local/bin and the shell setup would land in root'\''s home.
if [ "$(id -u)" -eq 0 ] && [ -n "${SUDO_USER:-${DOAS_USER:-}}" ] && [ "${SUDO_USER:-${DOAS_USER:-}}" != root ] \
  && [ "${BOOTS_ALLOW_ROOT:-}" != 1 ]; then
  echo "run this as your normal user, not with sudo: it calls sudo itself when it needs to." >&2
  echo "(under sudo it would install into root'\''s home; set BOOTS_ALLOW_ROOT=1 to do that anyway)" >&2
  exit 2
fi
BIN_DIR="${BIN_DIR:-$HOME/.local/bin}"
mkdir -p "$BIN_DIR"
export PATH="$BIN_DIR:$HOME/.cargo/bin:/usr/local/go/bin:$PATH"
USER="${USER:-$(id -un)}"
FAILED=()

case "$(uname -m)" in
  x86_64)        DEB_ARCH=amd64; GO_ARCH=amd64; UNAME_ARCH=x86_64 ;;
  aarch64|arm64) DEB_ARCH=arm64; GO_ARCH=arm64; UNAME_ARCH=aarch64 ;;
  *) echo "unsupported architecture: $(uname -m)" >&2; exit 1 ;;
esac
export DEB_ARCH GO_ARCH UNAME_ARCH

SUDO=""
if [ "$(id -u)" -ne 0 ]; then
  if command -v sudo >/dev/null 2>&1; then SUDO="sudo"
  elif command -v doas >/dev/null 2>&1; then SUDO="doas"
  else echo "this script needs root, sudo or doas" >&2; exit 1
  fi
fi

have() { command -v "$1" >/dev/null 2>&1; }

# step <label> <function>: run one install, record failures, keep going
step() {
  echo "--> $1"
  if "$2"; then echo "    ok"; else echo "    FAILED: $1" >&2; FAILED+=("$1"); fi
}' ;;
    helpers) REPLY='# Latest release tag of a GitHub repo, without a leading "v".
# Follows the /releases/latest redirect, so there is no API rate limit.
gh_latest_tag() {
  local url
  url="$(curl -fsSLI -o /dev/null -w '\''%{url_effective}'\'' "https://github.com/$1/releases/latest")" || return 1
  case "$url" in
    */tag/*) echo "${url##*/tag/}" | sed '\''s/^v//'\'' ;;
    *) echo "could not resolve the latest release of $1" >&2; return 1 ;;
  esac
}

# install_from_tarball <url> <binary>: download, unpack, copy <binary> into $BIN_DIR
install_from_tarball() {
  local tmp bin rc=1
  tmp="$(mktemp -d)"
  if curl -fsSL "$1" -o "$tmp/pkg.tgz" && tar -xzf "$tmp/pkg.tgz" -C "$tmp"; then
    bin="$(find "$tmp" -type f -name "$2" | head -n1)"
    if [ -n "$bin" ]; then
      install -m 0755 "$bin" "$BIN_DIR/$2" && rc=0
    else
      echo "$2 not found in archive" >&2
    fi
  fi
  rm -rf "$tmp"
  return $rc
}' ;;
    pm-install) REPLY='# pm_install <pkg>...: all at once; if that fails, one at a time, so a single unavailable
# package doesn'\''t stop the rest. Whatever still fails is left in PKG_FAILED.
pm_install() {
  PKG_FAILED=()
  pm_try "$@" && return 0
  if [ "$#" -gt 1 ]; then
    echo "    the batch failed; installing the packages one at a time"
    local p
    for p in "$@"; do pm_try "$p" >/dev/null || PKG_FAILED+=("$p"); done
  else
    PKG_FAILED=("$1")
  fi
  [ "${#PKG_FAILED[@]}" -eq 0 ] && return 0
  echo "    could not install: ${PKG_FAILED[*]}" >&2
  return 1
}' ;;
    fallback) REPLY='# fallback <label> <function> <bin>: the upstream install, run only when the distro
# package did not provide <bin> (not packaged on this release, or it failed to install)
fallback() {
  have "$3" && return 0
  echo "--> $1: native package unavailable, using upstream"
  if "$2"; then echo "    ok"; else echo "    FAILED: $1" >&2; FAILED+=("$1"); fi
}' ;;
    gh-repo-apt) REPLY='if [ ! -f /etc/apt/sources.list.d/github-cli.list ]; then
  $SUDO mkdir -p -m 755 /etc/apt/keyrings
  curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
    | $SUDO tee /etc/apt/keyrings/githubcli-archive-keyring.gpg >/dev/null
  $SUDO chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
  echo "deb [arch=$DEB_ARCH signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
    | $SUDO tee /etc/apt/sources.list.d/github-cli.list >/dev/null
fi' ;;
    gh-repo-dnf) REPLY='if ! dnf repolist 2>/dev/null | grep -q gh-cli; then
  if dnf --version 2>/dev/null | grep -q dnf5; then
    $SUDO dnf config-manager addrepo --from-repofile=https://cli.github.com/packages/rpm/gh-cli.repo
  else
    $SUDO dnf install -y '\''dnf-command(config-manager)'\''
    $SUDO dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
  fi
fi' ;;
    gh-repo-yum) REPLY='if [ ! -f /etc/yum.repos.d/gh-cli.repo ]; then
  $SUDO yum install -y yum-utils
  $SUDO yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
fi' ;;
    gh-repo-zypper) REPLY='zypper lr 2>/dev/null | grep -q gh-cli \
  || $SUDO zypper --non-interactive addrepo https://cli.github.com/packages/rpm/gh-cli.repo' ;;
    docker-post-openrc) REPLY='$SUDO rc-update add docker default || true
$SUDO service docker start || true' ;;
    docker-post-systemd) REPLY='$SUDO systemctl enable --now docker || true' ;;
    docker-get) REPLY='install_docker() {
  have docker && { echo "    already installed"; return 0; }
  curl -fsSL https://get.docker.com | $SUDO sh
}' ;;
    docker-yum) REPLY='install_docker() {
  have docker && { echo "    already installed"; return 0; }
  # Amazon Linux 2 ships Docker in Amazon'\''s own extras repo (get.docker.com does not support it)
  if have amazon-linux-extras; then
    $SUDO amazon-linux-extras install -y docker || return 1
    $SUDO systemctl enable --now docker >/dev/null 2>&1 || true
    return 0
  fi
  curl -fsSL https://get.docker.com | $SUDO sh
}' ;;
    docker-dnf) REPLY='install_docker() {
  have docker && { echo "    already installed"; return 0; }
  curl -fsSL https://get.docker.com | $SUDO sh && have docker && return 0
  # get.docker.com sends some RHEL rebuilds (Rocky 9 today) to an empty repo;
  # Docker'\''s CentOS repo carries the same packages for them
  [ "$(. /etc/os-release 2>/dev/null; echo "${ID:-}")" != fedora ] || return 1
  echo "    retrying from Docker'\''s CentOS repo"
  curl -fsSL https://download.docker.com/linux/centos/docker-ce.repo | $SUDO tee /etc/yum.repos.d/docker-ce.repo >/dev/null \
    && $SUDO dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin || return 1
  # start it now and at boot, as get.docker.com does (fails harmlessly without systemd, e.g. in a container)
  $SUDO systemctl enable --now docker >/dev/null 2>&1 || true
}' ;;
    ripgrep-bin) REPLY='install_ripgrep() {
  have rg && { echo "    already installed"; return 0; }
  # upstream has no aarch64 musl build: never leave a glibc binary on a musl system
  if [ "$UNAME_ARCH" = aarch64 ] && ls /lib/ld-musl-* >/dev/null 2>&1; then echo "no aarch64 musl build of ripgrep upstream" >&2; return 1; fi
  local ver target
  ver="$(gh_latest_tag BurntSushi/ripgrep)" || return 1
  case "$UNAME_ARCH" in
    x86_64)  target=x86_64-unknown-linux-musl ;;
    aarch64) target=aarch64-unknown-linux-gnu ;;
  esac
  install_from_tarball "https://github.com/BurntSushi/ripgrep/releases/download/${ver}/ripgrep-${ver}-${target}.tar.gz" rg
}' ;;
    fzf-bin) REPLY='install_fzf() {
  have fzf && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag junegunn/fzf)" || return 1
  install_from_tarball "https://github.com/junegunn/fzf/releases/download/v${ver}/fzf-${ver}-linux_${GO_ARCH}.tar.gz" fzf
}' ;;
    jq-bin) REPLY='install_jq() {
  have jq && { echo "    already installed"; return 0; }
  curl -fsSL "https://github.com/jqlang/jq/releases/latest/download/jq-linux-${GO_ARCH}" -o "$BIN_DIR/jq" \
    && chmod +x "$BIN_DIR/jq"
}' ;;
    uv-script) REPLY='install_uv() {
  have uv && { echo "    already installed"; return 0; }
  curl -LsSf https://astral.sh/uv/install.sh | env UV_NO_MODIFY_PATH=1 sh
}' ;;
    rust-script) REPLY='install_rust() {
  have cargo && { echo "    already installed"; return 0; }
  curl --proto '\''=https'\'' --tlsv1.2 -sSf https://sh.rustup.rs \
    | sh -s -- -y --no-modify-path --default-toolchain stable
}' ;;
    go-tarball) REPLY='install_go() {
  have go && { echo "    already installed"; return 0; }
  local ver tmp rc
  ver="$(curl -fsSL '\''https://go.dev/VERSION?m=text'\'' | head -n1)"
  [ -n "$ver" ] || { echo "could not resolve the latest Go version" >&2; return 1; }
  tmp="$(mktemp -d)"
  curl -fsSL "https://go.dev/dl/${ver}.linux-${GO_ARCH}.tar.gz" -o "$tmp/go.tgz" || { rm -rf "$tmp"; return 1; }
  $SUDO rm -rf /usr/local/go
  $SUDO tar -C /usr/local -xzf "$tmp/go.tgz"; rc=$?
  rm -rf "$tmp"
  return $rc
}' ;;
    zoxide-script) REPLY='install_zoxide() {
  have zoxide && { echo "    already installed"; return 0; }
  curl -sSfL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh
}' ;;
    lazygit-bin) REPLY='install_lazygit() {
  have lazygit && { echo "    already installed"; return 0; }
  local ver arch
  ver="$(gh_latest_tag jesseduffield/lazygit)" || return 1
  case "$UNAME_ARCH" in x86_64) arch=x86_64 ;; aarch64) arch=arm64 ;; esac
  install_from_tarball "https://github.com/jesseduffield/lazygit/releases/download/v${ver}/lazygit_${ver}_linux_${arch}.tar.gz" lazygit
}' ;;
    lazydocker-bin) REPLY='install_lazydocker() {
  have lazydocker && { echo "    already installed"; return 0; }
  local ver arch
  ver="$(gh_latest_tag jesseduffield/lazydocker)" || return 1
  case "$UNAME_ARCH" in x86_64) arch=x86_64 ;; aarch64) arch=arm64 ;; esac
  install_from_tarball "https://github.com/jesseduffield/lazydocker/releases/download/v${ver}/lazydocker_${ver}_Linux_${arch}.tar.gz" lazydocker
}' ;;
    bottom-deb) REPLY='install_bottom() {
  have btm && { echo "    already installed"; return 0; }
  local ver tmp rc
  ver="$(gh_latest_tag ClementTsang/bottom)" || return 1
  tmp="$(mktemp -d)"
  curl -fsSL "https://github.com/ClementTsang/bottom/releases/download/${ver}/bottom_${ver}-1_${DEB_ARCH}.deb" -o "$tmp/bottom.deb" \
    || { rm -rf "$tmp"; return 1; }
  $SUDO dpkg -i "$tmp/bottom.deb"; rc=$?
  rm -rf "$tmp"
  return $rc
}' ;;
    bottom-bin) REPLY='install_bottom() {
  have btm && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag ClementTsang/bottom)" || return 1
  install_from_tarball "https://github.com/ClementTsang/bottom/releases/download/${ver}/bottom_${UNAME_ARCH}-unknown-linux-gnu.tar.gz" btm
}' ;;
    glow-bin) REPLY='install_glow() {
  have glow && { echo "    already installed"; return 0; }
  local ver arch
  ver="$(gh_latest_tag charmbracelet/glow)" || return 1
  case "$UNAME_ARCH" in x86_64) arch=x86_64 ;; aarch64) arch=arm64 ;; esac
  install_from_tarball "https://github.com/charmbracelet/glow/releases/download/v${ver}/glow_${ver}_Linux_${arch}.tar.gz" glow
}' ;;
    yq-bin) REPLY='install_yq() {
  have yq && { echo "    already installed"; return 0; }
  curl -fsSL "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_${GO_ARCH}" -o "$BIN_DIR/yq" \
    && chmod +x "$BIN_DIR/yq"
}' ;;
    gron-bin) REPLY='install_gron() {
  have gron && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag tomnomnom/gron)" || return 1
  install_from_tarball "https://github.com/tomnomnom/gron/releases/download/v${ver}/gron-linux-${GO_ARCH}-${ver}.tgz" gron
}' ;;
    jnv-cargo) REPLY='install_jnv() {
  have jnv && { echo "    already installed"; return 0; }
  have cargo || { echo "cargo not found, so jnv can'\''t be built" >&2; return 1; }
  cargo install --locked jnv
}' ;;
    harlequin-uv) REPLY='install_harlequin() {
  have harlequin && { echo "    already installed"; return 0; }
  have uv || { echo "uv not found" >&2; return 1; }
  # pin a Python its compiled dependencies ship wheels for (a distro'\''s newest python3 may not have them yet)
  uv tool install --python 3.13 harlequin
}' ;;
    visidata-uv) REPLY='install_visidata() {
  have vd && { echo "    already installed"; return 0; }
  have uv || { echo "uv not found" >&2; return 1; }
  uv tool install visidata
}' ;;
    apptainer-deb) REPLY='install_apptainer() {
  have apptainer && { echo "    already installed"; return 0; }
  local ver suffix="" tmp ubuntu rc ppa=https://ppa.launchpadcontent.net/apptainer/ppa/ubuntu
  # Ubuntu and its derivatives (Mint, Pop!_OS, ...) name their Ubuntu base here
  ubuntu="$(. /etc/os-release 2>/dev/null; echo "${UBUNTU_CODENAME:-}")"
  # Apptainer'\''s release .debs are amd64 only, in two builds: one for libfuse3-3 systems (Debian 12,
  # Ubuntu 24.04) and a "-trixie+" one for libfuse3-4 systems (Debian 13+, Ubuntu 26.04).
  # Use it only if apt says it can actually be installed here.
  if [ "$DEB_ARCH" = amd64 ]; then
    ver="$(gh_latest_tag apptainer/apptainer)" || return 1
    apt-cache show libfuse3-4 >/dev/null 2>&1 && suffix="-trixie+"
    tmp="$(mktemp -d)"
    chmod 755 "$tmp"
    if curl -fsSL "https://github.com/apptainer/apptainer/releases/download/v${ver}/apptainer_${ver}${suffix}_${DEB_ARCH}.deb" -o "$tmp/apptainer.deb" \
       && apt-get install -s -y "$tmp/apptainer.deb" >/dev/null 2>&1; then
      $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y "$tmp/apptainer.deb"; rc=$?
      rm -rf "$tmp"
      return $rc
    fi
    rm -rf "$tmp"
  fi
  # No release .deb fits (Ubuntu 22.04, or arm64). Ubuntu and derivatives: Apptainer'\''s official PPA,
  # if it builds for this release; key pinned by fingerprint; undone again if the install fails.
  if [ -n "$ubuntu" ] && curl -fsSI "$ppa/dists/$ubuntu/InRelease" >/dev/null 2>&1; then
    echo "    no release .deb fits this system; using the official Apptainer PPA (ppa:apptainer/ppa)"
    $SUDO mkdir -p -m 755 /etc/apt/keyrings
    if curl -fsSL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xF6B0F5193D4F3301EF491FF0AFE36534FC6218AE" \
         | $SUDO tee /etc/apt/keyrings/apptainer-ppa.asc >/dev/null \
       && echo "deb [signed-by=/etc/apt/keyrings/apptainer-ppa.asc] $ppa $ubuntu main" \
         | $SUDO tee /etc/apt/sources.list.d/apptainer-ppa.list >/dev/null \
       && $SUDO apt-get update -y >/dev/null \
       && $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y apptainer; then
      return 0
    fi
    echo "    the PPA install failed; removing the PPA again" >&2
    $SUDO rm -f /etc/apt/sources.list.d/apptainer-ppa.list /etc/apt/keyrings/apptainer-ppa.asc
    return 1
  fi
  echo "no apptainer package fits this system (see apptainer.org/docs/admin/main/installation.html)" >&2
  return 1
}' ;;
    apptainer-dnf) REPLY='install_apptainer() {
  have apptainer && { echo "    already installed"; return 0; }
  # Fedora has it in the main repos; RHEL, Rocky and Alma get it from EPEL
  $SUDO dnf install -y apptainer && return 0
  $SUDO dnf install -y epel-release && $SUDO dnf install -y apptainer
}' ;;
    kubectl-bin) REPLY='install_kubectl() {
  have kubectl && { echo "    already installed"; return 0; }
  local ver base tmp rc=1
  ver="$(curl -fsSL https://dl.k8s.io/release/stable.txt)" || return 1
  base="https://dl.k8s.io/release/${ver}/bin/linux/${GO_ARCH}/kubectl"
  tmp="$(mktemp -d)"
  if curl -fsSL "$base" -o "$tmp/kubectl" && curl -fsSL "$base.sha256" -o "$tmp/kubectl.sha256" \
     && (cd "$tmp" && echo "$(cat kubectl.sha256)  kubectl" | sha256sum -c - >/dev/null); then
    install -m 0755 "$tmp/kubectl" "$BIN_DIR/kubectl" && rc=0
  else
    echo "kubectl download or checksum check failed" >&2
  fi
  rm -rf "$tmp"
  return $rc
}' ;;
    k9s-bin) REPLY='install_k9s() {
  have k9s && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag derailed/k9s)" || return 1
  install_from_tarball "https://github.com/derailed/k9s/releases/download/v${ver}/k9s_Linux_${GO_ARCH}.tar.gz" k9s
}' ;;
    helm-bin) REPLY='install_helm() {
  have helm && { echo "    already installed"; return 0; }
  local ver
  ver="$(curl -fsSL https://get.helm.sh/helm-latest-version)" || return 1
  install_from_tarball "https://get.helm.sh/helm-${ver}-linux-${GO_ARCH}.tar.gz" helm
}' ;;
    kind-bin) REPLY='install_kind() {
  have kind && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag kubernetes-sigs/kind)" || return 1
  curl -fsSL "https://github.com/kubernetes-sigs/kind/releases/download/v${ver}/kind-linux-${GO_ARCH}" -o "$BIN_DIR/kind" \
    && chmod +x "$BIN_DIR/kind"
}' ;;
    dive-bin) REPLY='install_dive() {
  have dive && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag wagoodman/dive)" || return 1
  install_from_tarball "https://github.com/wagoodman/dive/releases/download/v${ver}/dive_${ver}_linux_${GO_ARCH}.tar.gz" dive
}' ;;
    fd-bin) REPLY='install_fd() {
  have fd && { echo "    already installed"; return 0; }
  local ver target
  ver="$(gh_latest_tag sharkdp/fd)" || return 1
  target=${UNAME_ARCH}-unknown-linux-musl
  install_from_tarball "https://github.com/sharkdp/fd/releases/download/v${ver}/fd-v${ver}-${target}.tar.gz" fd
}' ;;
    bat-bin) REPLY='install_bat() {
  have bat && { echo "    already installed"; return 0; }
  local ver target
  ver="$(gh_latest_tag sharkdp/bat)" || return 1
  target=${UNAME_ARCH}-unknown-linux-musl
  install_from_tarball "https://github.com/sharkdp/bat/releases/download/v${ver}/bat-v${ver}-${target}.tar.gz" bat
}' ;;
    eza-bin) REPLY='install_eza() {
  have eza && { echo "    already installed"; return 0; }
  # upstream has no aarch64 musl build: never leave a glibc binary on a musl system
  if [ "$UNAME_ARCH" = aarch64 ] && ls /lib/ld-musl-* >/dev/null 2>&1; then echo "no aarch64 musl build of eza upstream" >&2; return 1; fi
  local ver target
  ver="$(gh_latest_tag eza-community/eza)" || return 1
  # no aarch64 musl build upstream; the gnu one is used there
  case "$UNAME_ARCH" in
    x86_64)  target=x86_64-unknown-linux-musl ;;
    aarch64) target=aarch64-unknown-linux-gnu ;;
  esac
  install_from_tarball "https://github.com/eza-community/eza/releases/download/v${ver}/eza_${target}.tar.gz" eza
}' ;;
    delta-bin) REPLY='install_delta() {
  have delta && { echo "    already installed"; return 0; }
  # upstream has no aarch64 musl build: never leave a glibc binary on a musl system
  if [ "$UNAME_ARCH" = aarch64 ] && ls /lib/ld-musl-* >/dev/null 2>&1; then echo "no aarch64 musl build of delta upstream" >&2; return 1; fi
  local ver target
  ver="$(gh_latest_tag dandavison/delta)" || return 1
  # no aarch64 musl build upstream; the gnu one is used there
  case "$UNAME_ARCH" in
    x86_64)  target=x86_64-unknown-linux-musl ;;
    aarch64) target=aarch64-unknown-linux-gnu ;;
  esac
  install_from_tarball "https://github.com/dandavison/delta/releases/download/${ver}/delta-${ver}-${target}.tar.gz" delta
}' ;;
    dust-bin) REPLY='install_dust() {
  have dust && { echo "    already installed"; return 0; }
  local ver target
  ver="$(gh_latest_tag bootandy/dust)" || return 1
  target=${UNAME_ARCH}-unknown-linux-musl
  install_from_tarball "https://github.com/bootandy/dust/releases/download/v${ver}/dust-v${ver}-${target}.tar.gz" dust
}' ;;
    duf-bin) REPLY='install_duf() {
  have duf && { echo "    already installed"; return 0; }
  local ver arch
  ver="$(gh_latest_tag muesli/duf)" || return 1
  case "$UNAME_ARCH" in x86_64) arch=x86_64 ;; aarch64) arch=arm64 ;; esac
  install_from_tarball "https://github.com/muesli/duf/releases/download/v${ver}/duf_${ver}_linux_${arch}.tar.gz" duf
}' ;;
    sd-bin) REPLY='install_sd() {
  have sd && { echo "    already installed"; return 0; }
  local ver target
  ver="$(gh_latest_tag chmln/sd)" || return 1
  target=${UNAME_ARCH}-unknown-linux-musl
  install_from_tarball "https://github.com/chmln/sd/releases/download/v${ver}/sd-v${ver}-${target}.tar.gz" sd
}' ;;
    hyperfine-bin) REPLY='install_hyperfine() {
  have hyperfine && { echo "    already installed"; return 0; }
  local ver target
  ver="$(gh_latest_tag sharkdp/hyperfine)" || return 1
  target=${UNAME_ARCH}-unknown-linux-musl
  install_from_tarball "https://github.com/sharkdp/hyperfine/releases/download/v${ver}/hyperfine-v${ver}-${target}.tar.gz" hyperfine
}' ;;
    btop-bin) REPLY='install_btop() {
  have btop && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag aristocratos/btop)" || return 1
  install_from_tarball "https://github.com/aristocratos/btop/releases/download/v${ver}/btop-${UNAME_ARCH}-unknown-linux-musl.tar.gz" btop
}' ;;
    tealdeer-bin) REPLY='install_tealdeer() {
  have tldr && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag tealdeer-rs/tealdeer)" || return 1
  curl -fsSL "https://github.com/tealdeer-rs/tealdeer/releases/download/v${ver}/tealdeer-linux-${UNAME_ARCH}-musl" -o "$BIN_DIR/tldr" \
    && chmod +x "$BIN_DIR/tldr"
}' ;;
    ncdu-bin) REPLY='install_ncdu() {
  have ncdu && { echo "    already installed"; return 0; }
  local ver
  # ncdu is not released on GitHub: read the newest version from the author'\''s download page
  ver="$(curl -fsSL https://dev.yorhel.nl/ncdu | grep -o "ncdu-[0-9][0-9.]*-linux-${UNAME_ARCH}\.tar\.gz" | sed '\''s/^ncdu-//; s/-linux.*//'\'' | sort -V | tail -n1)"
  [ -n "$ver" ] || { echo "could not resolve the latest ncdu version" >&2; return 1; }
  install_from_tarball "https://dev.yorhel.nl/download/ncdu-${ver}-linux-${UNAME_ARCH}.tar.gz" ncdu
}' ;;
    starship-bin) REPLY='install_starship() {
  have starship && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag starship/starship)" || return 1
  install_from_tarball "https://github.com/starship/starship/releases/download/v${ver}/starship-${UNAME_ARCH}-unknown-linux-musl.tar.gz" starship
}' ;;
    direnv-bin) REPLY='install_direnv() {
  have direnv && { echo "    already installed"; return 0; }
  curl -fsSL "https://github.com/direnv/direnv/releases/latest/download/direnv.linux-${GO_ARCH}" -o "$BIN_DIR/direnv" \
    && chmod +x "$BIN_DIR/direnv"
}' ;;
    atuin-bin) REPLY='install_atuin() {
  have atuin && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag atuinsh/atuin)" || return 1
  install_from_tarball "https://github.com/atuinsh/atuin/releases/download/v${ver}/atuin-${UNAME_ARCH}-unknown-linux-musl.tar.gz" atuin
}' ;;
    just-bin) REPLY='install_just() {
  have just && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag casey/just)" || return 1
  install_from_tarball "https://github.com/casey/just/releases/download/${ver}/just-${ver}-${UNAME_ARCH}-unknown-linux-musl.tar.gz" just
}' ;;
    mise-bin) REPLY='install_mise() {
  have mise && { echo "    already installed"; return 0; }
  local ver arch
  ver="$(gh_latest_tag jdx/mise)" || return 1
  case "$UNAME_ARCH" in x86_64) arch=x64 ;; aarch64) arch=arm64 ;; esac
  curl -fsSL "https://github.com/jdx/mise/releases/download/v${ver}/mise-v${ver}-linux-${arch}-musl" -o "$BIN_DIR/mise" \
    && chmod +x "$BIN_DIR/mise"
}' ;;
    shellcheck-bin) REPLY='install_shellcheck() {
  have shellcheck && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag koalaman/shellcheck)" || return 1
  install_from_tarball "https://github.com/koalaman/shellcheck/releases/download/v${ver}/shellcheck-v${ver}.linux.${UNAME_ARCH}.tar.gz" shellcheck
}' ;;
    precommit-uv) REPLY='install_precommit() {
  have pre-commit && { echo "    already installed"; return 0; }
  have uv || { echo "uv not found" >&2; return 1; }
  uv tool install pre-commit
}' ;;
    xh-bin) REPLY='install_xh() {
  have xh && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag ducaale/xh)" || return 1
  install_from_tarball "https://github.com/ducaale/xh/releases/download/v${ver}/xh-v${ver}-${UNAME_ARCH}-unknown-linux-musl.tar.gz" xh
}' ;;
    neovim-tarball) REPLY='install_neovim() {
  have nvim && { echo "    already installed"; return 0; }
  local arch tmp rc=1 opt="$HOME/.local/opt"
  case "$UNAME_ARCH" in x86_64) arch=x86_64 ;; aarch64) arch=arm64 ;; esac
  # neovim/neovim-releases = same release, built against an older glibc (works on Amazon Linux 2);
  # still glibc only, so Alpine installs the distro package instead
  tmp="$(mktemp -d)"
  if curl -fsSL "https://github.com/neovim/neovim-releases/releases/latest/download/nvim-linux-${arch}.tar.gz" -o "$tmp/nvim.tgz" \
     && tar -xzf "$tmp/nvim.tgz" -C "$tmp"; then
    mkdir -p "$opt" && rm -rf "$opt/nvim" \
      && mv "$tmp/nvim-linux-${arch}" "$opt/nvim" \
      && ln -sf "$opt/nvim/bin/nvim" "$BIN_DIR/nvim" && rc=0
  fi
  rm -rf "$tmp"
  if [ $rc -eq 0 ] && ! "$BIN_DIR/nvim" --version >/dev/null 2>&1; then
    echo "nvim does not run on this system (glibc too old?)" >&2
    rm -rf "$opt/nvim" "$BIN_DIR/nvim"; rc=1
  fi
  return $rc
}' ;;
    zellij-bin) REPLY='install_zellij() {
  have zellij && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag zellij-org/zellij)" || return 1
  install_from_tarball "https://github.com/zellij-org/zellij/releases/download/v${ver}/zellij-${UNAME_ARCH}-unknown-linux-musl.tar.gz" zellij
}' ;;
    yazi-bin) REPLY='install_yazi() {
  have yazi && { echo "    already installed"; return 0; }
  local tmp rc=1 dir
  have unzip || { echo "unzip not found" >&2; return 1; }
  dir="yazi-${UNAME_ARCH}-unknown-linux-musl"
  tmp="$(mktemp -d)"
  if curl -fsSL "https://github.com/sxyazi/yazi/releases/latest/download/${dir}.zip" -o "$tmp/yazi.zip" \
     && unzip -q "$tmp/yazi.zip" -d "$tmp"; then
    install -m 0755 "$tmp/$dir/yazi" "$BIN_DIR/yazi" \
      && install -m 0755 "$tmp/$dir/ya" "$BIN_DIR/ya" && rc=0
  fi
  rm -rf "$tmp"
  return $rc
}' ;;
    node-nvm) REPLY='install_node() {
  export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
  local ver nvm_rc node_bin
  # an existing nvm: load it first, so its default node counts and nothing is installed over it
  # (nvm.sh is not safe under `set -u`)
  if [ -s "$NVM_DIR/nvm.sh" ]; then
    set +u
    # shellcheck source=/dev/null
    . "$NVM_DIR/nvm.sh"
    set -u
  fi
  have node && { echo "    already installed"; return 0; }
  ver="$(gh_latest_tag nvm-sh/nvm)" || return 1
  # current Node builds link against libatomic, which minimal images lack
  if ! ldconfig -p 2>/dev/null | grep -q '\''libatomic\.so\.1'\''; then
    if have apt-get || have zypper; then pm_install libatomic1
    elif have dnf || have yum; then pm_install libatomic
    fi
  fi
  # PROFILE=/dev/null: the installer must not edit rc files (the shell setup step does that)
  curl -fsSL "https://raw.githubusercontent.com/nvm-sh/nvm/v${ver}/install.sh" | PROFILE=/dev/null bash || return 1
  set +u
  # shellcheck source=/dev/null
  . "$NVM_DIR/nvm.sh" && nvm install --lts; nvm_rc=$?
  # make it the default only if there is no default yet
  if [ "$nvm_rc" -eq 0 ] && [ ! -e "$NVM_DIR/alias/default" ]; then nvm alias default '\''lts/*'\'' >/dev/null; fi
  # the version just installed (`nvm which current` needs the `which` command, missing on Fedora/Rocky images)
  node_bin="$(nvm which '\''lts/*'\'' 2>/dev/null)"
  set -u
  [ "$nvm_rc" -eq 0 ] && [ -x "$node_bin" ] || return 1
  # put node on PATH for the rest of this script (the final check needs it)
  PATH="$(dirname "$node_bin"):$PATH"; export PATH
  node --version >/dev/null || { echo "node was installed but does not run on this system (glibc too old?)" >&2; return 1; }
}' ;;
    bun-zip) REPLY='install_bun() {
  have bun && { echo "    already installed"; return 0; }
  have unzip || { echo "unzip not found" >&2; return 1; }
  local arch musl="" tmp rc=1
  case "$UNAME_ARCH" in x86_64) arch=x64 ;; aarch64) arch=aarch64 ;; esac
  if ls /lib/ld-musl-* >/dev/null 2>&1; then
    musl="-musl"
    # bun'\''s musl build links against the C++ runtime, which Alpine does not ship by default
    $SUDO apk add --no-cache libgcc libstdc++ || return 1
  fi
  tmp="$(mktemp -d)"
  if curl -fsSL "https://github.com/oven-sh/bun/releases/latest/download/bun-linux-${arch}${musl}.zip" -o "$tmp/bun.zip" \
     && unzip -q "$tmp/bun.zip" -d "$tmp"; then
    install -m 0755 "$tmp/bun-linux-${arch}${musl}/bun" "$BIN_DIR/bun" && rc=0
  fi
  rm -rf "$tmp"
  return $rc
}' ;;
    deno-zip) REPLY='install_deno() {
  have deno && { echo "    already installed"; return 0; }
  have unzip || { echo "unzip not found" >&2; return 1; }
  local tmp rc=1
  tmp="$(mktemp -d)"
  if curl -fsSL "https://github.com/denoland/deno/releases/latest/download/deno-${UNAME_ARCH}-unknown-linux-gnu.zip" -o "$tmp/deno.zip" \
     && unzip -q "$tmp/deno.zip" -d "$tmp"; then
    install -m 0755 "$tmp/deno" "$BIN_DIR/deno" && rc=0
  fi
  rm -rf "$tmp"
  # the glibc build will not start on very old systems (e.g. Amazon Linux 2)
  [ "$rc" -eq 0 ] && { "$BIN_DIR/deno" --version >/dev/null 2>&1 || { echo "deno does not run on this system (glibc too old?)" >&2; rm -f "$BIN_DIR/deno"; rc=1; }; }
  return $rc
}' ;;
    opentofu-bin) REPLY='install_opentofu() {
  have tofu && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag opentofu/opentofu)" || return 1
  install_from_tarball "https://github.com/opentofu/opentofu/releases/download/v${ver}/tofu_${ver}_linux_${GO_ARCH}.tar.gz" tofu
}' ;;
    terraform-bin) REPLY='install_terraform() {
  have terraform && { echo "    already installed"; return 0; }
  local ver tmp rc=1
  ver="$(curl -fsSL https://checkpoint-api.hashicorp.com/v1/check/terraform \
    | sed -n '\''s/.*"current_version" *: *"\([^"]*\)".*/\1/p'\'')"
  [ -n "$ver" ] || { echo "could not resolve the latest Terraform version" >&2; return 1; }
  tmp="$(mktemp -d)"
  if curl -fsSL "https://releases.hashicorp.com/terraform/${ver}/terraform_${ver}_linux_${GO_ARCH}.zip" -o "$tmp/tf.zip" \
     && unzip -q -o "$tmp/tf.zip" terraform -d "$tmp"; then
    install -m 0755 "$tmp/terraform" "$BIN_DIR/terraform" && rc=0
  fi
  rm -rf "$tmp"
  return $rc
}' ;;
    awscli-zip) REPLY='install_awscli() {
  local tmp cur="" rc=1
  if have aws; then
    cur="$(aws --version 2>&1)"
    case "$cur" in aws-cli/2*) echo "    already installed"; return 0 ;; esac
    echo "    found ${cur%% *} at $(command -v aws); installing AWS CLI v2 as $BIN_DIR/aws"
  fi
  tmp="$(mktemp -d)"
  if curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-${UNAME_ARCH}.zip" -o "$tmp/awscliv2.zip" \
     && unzip -q "$tmp/awscliv2.zip" -d "$tmp"; then
    "$tmp/aws/install" --update -i "$HOME/.local/aws-cli" -b "$BIN_DIR" && rc=0
  fi
  rm -rf "$tmp"
  hash -r
  [ "$rc" -eq 0 ] || return 1
  case "$("$BIN_DIR/aws" --version 2>&1)" in aws-cli/2*) ;; *) echo "$BIN_DIR/aws is not AWS CLI v2" >&2; return 1 ;; esac
  if [ -n "$cur" ]; then
    # v1 stays where it was (unless it was $BIN_DIR/aws itself, which the v2 link replaces)
    echo "    NOTE: v1 is still installed; v2 wins only while $BIN_DIR comes first on your PATH"
    echo "          (the '\''Wire up my shell'\'' PATH line puts it first)"
  fi
}' ;;
    ansible-uv) REPLY='install_ansible() {
  have ansible && { echo "    already installed"; return 0; }
  have uv || { echo "uv not found" >&2; return 1; }
  # ansible-core needs Python 3.13+; pin it so uv doesn'\''t pick a pre-release interpreter
  uv tool install --python 3.13 --with-executables-from ansible-core ansible
}' ;;
    kubectx-bin) REPLY='install_kubectx() {
  have kubectx && have kubens && { echo "    already installed"; return 0; }
  local ver arch
  ver="$(gh_latest_tag ahmetb/kubectx)" || return 1
  case "$UNAME_ARCH" in x86_64) arch=x86_64 ;; aarch64) arch=arm64 ;; esac
  install_from_tarball "https://github.com/ahmetb/kubectx/releases/download/v${ver}/kubectx_v${ver}_linux_${arch}.tar.gz" kubectx \
    && install_from_tarball "https://github.com/ahmetb/kubectx/releases/download/v${ver}/kubens_v${ver}_linux_${arch}.tar.gz" kubens
}' ;;
    gitlfs-bin) REPLY='install_gitlfs() {
  have git-lfs && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag git-lfs/git-lfs)" || return 1
  install_from_tarball "https://github.com/git-lfs/git-lfs/releases/download/v${ver}/git-lfs-linux-${GO_ARCH}-v${ver}.tar.gz" git-lfs
}' ;;
    duckdb-bin) REPLY='install_duckdb() {
  have duckdb && { echo "    already installed"; return 0; }
  local ver libc=""
  ver="$(gh_latest_tag duckdb/duckdb)" || return 1
  # the musl build still links libstdc++ dynamically
  if ls /lib/ld-musl-* >/dev/null 2>&1; then libc="-musl"; pm_install libstdc++ || return 1; fi
  install_from_tarball "https://github.com/duckdb/duckdb/releases/download/v${ver}/duckdb-cli-linux-${GO_ARCH}${libc}.tar.gz" duckdb
}' ;;
    pandoc-bin) REPLY='install_pandoc() {
  have pandoc && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag jgm/pandoc)" || return 1
  install_from_tarball "https://github.com/jgm/pandoc/releases/download/${ver}/pandoc-${ver}-linux-${GO_ARCH}.tar.gz" pandoc
}' ;;
    mkcert-bin) REPLY='install_mkcert() {
  have mkcert && { echo "    already installed"; return 0; }
  local ver
  ver="$(gh_latest_tag FiloSottile/mkcert)" || return 1
  curl -fsSL "https://github.com/FiloSottile/mkcert/releases/download/v${ver}/mkcert-v${ver}-linux-${GO_ARCH}" -o "$BIN_DIR/mkcert" \
    && chmod +x "$BIN_DIR/mkcert"
}' ;;
    java-sdkman) REPLY='install_java() {
  local init="$HOME/.sdkman/bin/sdkman-init.sh" rc
  # an existing SDKMAN: load it first, so its java counts and nothing is installed over it
  # (sdkman-init.sh is not safe under `set -u`)
  if [ -s "$init" ]; then
    set +u
    # shellcheck source=/dev/null
    . "$init"
    set -u
  fi
  have java && { echo "    already installed"; return 0; }
  # SDKMAN needs zip as well as unzip, curl and bash
  have zip || pm_install zip || return 1
  if [ ! -s "$init" ]; then
    curl -fsSL "https://get.sdkman.io?rcupdate=false" | bash || return 1
  fi
  set +u
  # shellcheck source=/dev/null
  . "$init"
  # no prompts, for this run only: your SDKMAN config is left as it is (sdk re-reads it on every
  # call, so stdin from /dev/null is what really answers "set as default?" with its default, yes)
  sdkman_auto_answer=true sdkman_auto_selfupdate=false sdk install java </dev/null; rc=$?
  set -u
  return $rc
}' ;;
    7zip-bin) REPLY='# Official 7-Zip release (ip7z/7zip): a static `7zz`. Distros disagree on 7z/7za/7zz, so we always use this one.
install_7zip() {
  have 7zz && { echo "    already installed"; return 0; }
  local ver arch tmp rc=1
  ver="$(gh_latest_tag ip7z/7zip)" || return 1
  case "$UNAME_ARCH" in x86_64) arch=x64 ;; aarch64) arch=arm64 ;; esac
  tmp="$(mktemp -d)"
  if curl -fsSL "https://github.com/ip7z/7zip/releases/download/${ver}/7z${ver//./}-linux-${arch}.tar.xz" -o "$tmp/pkg.txz" \
     && tar -xJf "$tmp/pkg.txz" -C "$tmp" 7zz; then
    install -m 0755 "$tmp/7zz" "$BIN_DIR/7zz" && rc=0
  else
    echo "could not download or unpack 7-Zip (is xz installed?)" >&2
  fi
  rm -rf "$tmp"
  return $rc
}' ;;
    rc-head) REPLY='case "$(basename "${SHELL:-/bin/bash}")" in
  zsh) RC="$HOME/.zshrc" ;;
  *)   RC="$HOME/.bashrc" ;;
esac
touch "$RC"
echo "    rc file: $RC"' ;;
    rc-path) REPLY='export PATH="$HOME/.local/bin:$HOME/.cargo/bin:/usr/local/go/bin:$PATH"' ;;
    rc-zoxide) REPLY='if command -v zoxide >/dev/null 2>&1; then
  if [ -n "${ZSH_VERSION:-}" ]; then eval "$(zoxide init zsh)"; else eval "$(zoxide init bash)"; fi
fi' ;;
    rc-fzf) REPLY='if command -v fzf >/dev/null 2>&1; then
  if [ -n "${ZSH_VERSION:-}" ]; then _fzf_sh=zsh; else _fzf_sh=bash; fi
  if fzf --"$_fzf_sh" >/dev/null 2>&1; then
    eval "$(fzf --"$_fzf_sh")"
  elif [ -f "/usr/share/doc/fzf/examples/key-bindings.$_fzf_sh" ]; then
    . "/usr/share/doc/fzf/examples/key-bindings.$_fzf_sh"
  fi
  unset _fzf_sh
fi' ;;
    rc-clipcat) REPLY='# clipcat [file]: copy a file, or piped text, to your local clipboard, even over SSH (OSC 52)
#   clipcat notes.md      or      cat notes.md | clipcat
# Needs a terminal that supports OSC 52; inside tmux, set -g set-clipboard on.
clipcat() {
  local data
  if [ "$#" -gt 0 ] && [ "$1" != "-" ]; then
    [ -f "$1" ] || { echo "clipcat: '\''$1'\'' is not a file" >&2; return 1; }
    data=$(base64 < "$1" | tr -d '\''\n'\'')
  elif [ -t 0 ]; then
    echo "usage: clipcat <file>   or   <command> | clipcat" >&2; return 2
  else
    data=$(base64 | tr -d '\''\n'\'')
  fi
  printf '\''\033]52;c;%s\a'\'' "$data" > /dev/tty
}' ;;
    rc-act) REPLY='# act: activate the nearest .venv, walking up from $PWD
act() {
  local dir="$PWD"
  while [ "$dir" != "/" ]; do
    if [ -f "$dir/.venv/bin/activate" ]; then
      . "$dir/.venv/bin/activate"
      return
    fi
    dir="$(dirname "$dir")"
  done
  echo "No .venv found in $PWD or any parent directory." >&2
  return 1
}' ;;
    rc-starship) REPLY='if command -v starship >/dev/null 2>&1; then
  if [ -n "${ZSH_VERSION:-}" ]; then eval "$(starship init zsh)"; else eval "$(starship init bash)"; fi
fi' ;;
    rc-direnv) REPLY='if command -v direnv >/dev/null 2>&1; then
  if [ -n "${ZSH_VERSION:-}" ]; then eval "$(direnv hook zsh)"; else eval "$(direnv hook bash)"; fi
fi' ;;
    rc-atuin) REPLY='# atuin takes over Ctrl-R and the Up arrow (it loads after fzf, so it wins Ctrl-R)
if command -v atuin >/dev/null 2>&1; then
  if [ -n "${ZSH_VERSION:-}" ]; then eval "$(atuin init zsh)"; else eval "$(atuin init bash)"; fi
fi' ;;
    rc-mise) REPLY='if command -v mise >/dev/null 2>&1; then
  if [ -n "${ZSH_VERSION:-}" ]; then eval "$(mise activate zsh)"; else eval "$(mise activate bash)"; fi
fi' ;;
    rc-node) REPLY='export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && [ -n "${BASH_VERSION:-}" ] && . "$NVM_DIR/bash_completion"' ;;
    rc-mkcd) REPLY='# mkcd <dir>: make a directory (and parents) and cd into it
mkcd() { mkdir -p -- "$1" && cd -- "$1"; }' ;;
    rc-extract) REPLY='# extract <file>...: unpack almost any archive by its extension
extract() {
  [ "$#" -gt 0 ] || { echo "usage: extract <archive>..." >&2; return 2; }
  local f need c rc=0
  for f in "$@"; do
    [ -f "$f" ] || { echo "extract: '\''$f'\'' is not a file" >&2; rc=1; continue; }
    case "$f" in
      *.tar.gz|*.tgz)    need=tar ;;
      *.tar.bz2|*.tbz2)  need=tar ;;
      *.tar.xz|*.txz)    need=tar ;;
      *.tar.zst)         need=zstd ;;
      *.tar)             need=tar ;;
      *.gz)              need=gunzip ;;
      *.bz2)             need=bunzip2 ;;
      *.xz)              need=unxz ;;
      *.zst)             need=unzstd ;;
      *.zip)             need=unzip ;;
      *.7z)              need=7zz; for c in 7zz 7z 7za; do command -v "$c" >/dev/null 2>&1 && { need=$c; break; }; done ;;
      *.rar)             need=7zz; for c in 7zz 7z unrar; do command -v "$c" >/dev/null 2>&1 && { need=$c; break; }; done ;;
      *) echo "extract: don'\''t know how to unpack '\''$f'\''" >&2; rc=1; continue ;;
    esac
    command -v "$need" >/dev/null 2>&1 || { echo "extract: '\''$need'\'' is needed for '\''$f'\'' but is not installed" >&2; rc=1; continue; }
    case "$f" in
      *.tar.gz|*.tgz)   tar -xzf "$f" ;;
      *.tar.bz2|*.tbz2) tar -xjf "$f" ;;
      *.tar.xz|*.txz)   tar -xJf "$f" ;;
      *.tar.zst)        zstd -dc -- "$f" | tar -xf - ;;
      *.tar)            tar -xf "$f" ;;
      *.gz)             gunzip -k -- "$f" ;;
      *.bz2)            bunzip2 -k -- "$f" ;;
      *.xz)             unxz -k -- "$f" ;;
      *.zst)            unzstd -q -- "$f" ;;
      *.zip)            unzip -q "$f" ;;
      *.7z|*.rar)       "$need" x "$f" ;;
    esac || rc=1
  done
  return $rc
}' ;;
    rc-serve) REPLY='# serve [port]: serve the current directory over HTTP (needs python3)
serve() { python3 -m http.server "${1:-8000}"; }' ;;
    rc-checkip) REPLY='# checkip: print your public IP address (tries a few services, with curl or else wget)
checkip() {
  local u ip
  for u in https://checkip.amazonaws.com https://api.ipify.org https://icanhazip.com; do
    if command -v curl >/dev/null 2>&1; then
      ip=$(curl -fsS --max-time 5 "$u" 2>/dev/null)
    elif command -v wget >/dev/null 2>&1; then
      ip=$(wget -qO- -T 5 -t 1 "$u" 2>/dev/null)
    else
      echo "checkip: needs curl or wget" >&2; return 1
    fi
    ip=$(printf '\''%s'\'' "$ip" | tr -d '\''[:space:]'\'')
    case "$ip" in '\'''\''|*[!0-9A-Fa-f.:]*) continue ;; esac
    printf '\''%s\n'\'' "$ip"; return 0
  done
  echo "checkip: could not reach an IP lookup service" >&2; return 1
}' ;;
    rc-java) REPLY='export SDKMAN_DIR="$HOME/.sdkman"
if [ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]; then
  . "$SDKMAN_DIR/bin/sdkman-init.sh"
fi' ;;
    docker-group) REPLY='if have docker && [ "$(id -u)" -ne 0 ] && ! id -nG "$USER" | tr '\'' '\'' '\''\n'\'' | grep -qx docker; then
  if have usermod; then $SUDO usermod -aG docker "$USER"; else $SUDO addgroup "$USER" docker; fi \
    && echo "    added $USER to the docker group (log out and back in to use docker without sudo)"
fi' ;;
    *) echo "install.sh: internal error: no snippet $1" >&2; exit 3 ;;
  esac
}

# ---------------------------------------------------------------- helpers
NT=${#T_ID[@]}
B36=0123456789abcdefghijklmnopqrstuvwxyz
# The combo bitmask is wider than bash's 64-bit integers, so it is kept as little-endian 24-bit limbs.
LIMB=24
LIMB_MASK=16777215

boots_die() { echo "install.sh: $*" >&2; exit 2; }

is_pm() { local p; for p in "${PM_IDS[@]}"; do [ "$p" = "$1" ] && return 0; done; return 1; }

tool_word() { # tool_word <word>: is it a tool id or (lowercase) name?
  local w
  for w in "${T_WORDS[@]}"; do [ "$w" = "$1" ] && return 0; done
  return 1
}

safe_combo() { # safe_combo <combo>: as safeCombo() in the page: a 0 after the dash if the digits spell a tool
  if tool_word "${1#*-}"; then REPLY="${1%%-*}-0${1#*-}"; else REPLY=$1; fi
}

tool_index() { # tool_index <id>: its index in TOOLS, in REPLY
  local i
  for ((i = 0; i < NT; i++)); do
    if [ "${T_ID[i]}" = "$1" ]; then REPLY=$i; return 0; fi
  done
  return 1
}

big_from_b36() { # big_from_b36 <digits>: BIG = that base-36 number
  local s=$1 i j d v carry
  BIG=(0)
  for ((i = 0; i < ${#s}; i++)); do
    d=${B36%%"${s:i:1}"*}; carry=${#d}
    for ((j = 0; j < ${#BIG[@]}; j++)); do
      v=$(( BIG[j] * 36 + carry ))
      BIG[j]=$(( v & LIMB_MASK )); carry=$(( v >> LIMB ))
    done
    while (( carry > 0 )); do BIG+=( $(( carry & LIMB_MASK )) ); carry=$(( carry >> LIMB )); done
  done
}

big_to_b36() { # BIG in base 36, in REPLY
  local -a n=("${BIG[@]}")
  local out="" i r v nz
  while :; do
    nz=0
    for v in "${n[@]}"; do if (( v )); then nz=1; break; fi; done
    (( nz )) || break
    r=0
    for ((i = ${#n[@]} - 1; i >= 0; i--)); do
      v=$(( (r << LIMB) + n[i] )); n[i]=$(( v / 36 )); r=$(( v % 36 ))
    done
    out=${B36:r:1}$out
  done
  REPLY=${out:-0}
}

big_bit() { (( (BIG[$1 / LIMB] >> ($1 % LIMB)) & 1 )); }

big_top() { # highest set bit of BIG (-1 for zero), in REPLY
  local j=$(( ${#BIG[@]} - 1 )) b
  while (( j >= 0 )) && (( BIG[j] == 0 )); do j=$(( j - 1 )); done
  if (( j < 0 )); then REPLY=-1; return; fi
  b=$(( LIMB - 1 ))
  while (( ((BIG[j] >> b) & 1) == 0 )); do b=$(( b - 1 )); done
  REPLY=$(( j * LIMB + b ))
}

combo_of() { # combo_of <pm> <rc_on>: the combo ID of SEL, as encode() in the page, in REPLY
  local i b
  BIG=()
  for ((i = 0; i <= (NT + 1) / LIMB; i++)); do BIG[i]=0; done
  if [ "$2" != 1 ]; then BIG[0]=1; fi
  for ((i = 0; i < NT; i++)); do
    if [ -n "${SEL[i]}" ]; then b=$(( i + 1 )); BIG[b / LIMB]=$(( BIG[b / LIMB] | (1 << (b % LIMB)) )); fi
  done
  big_to_b36
  REPLY="$1-$REPLY"
}

lev() { # lev <a> <b>: edit distance, in REPLY
  local a=$1 b=$2 i j c best
  local -a prev row
  for ((j = 0; j <= ${#b}; j++)); do prev[j]=$j; done
  for ((i = 1; i <= ${#a}; i++)); do
    row=("$i")
    for ((j = 1; j <= ${#b}; j++)); do
      if [ "${a:i-1:1}" = "${b:j-1:1}" ]; then c=0; else c=1; fi
      best=$(( prev[j - 1] + c ))
      (( prev[j] + 1 < best )) && best=$(( prev[j] + 1 ))
      (( row[j - 1] + 1 < best )) && best=$(( row[j - 1] + 1 ))
      row[j]=$best
    done
    prev=("${row[@]}")
  done
  REPLY=${prev[${#b}]}
}

suggest() { # suggest <word>: tool ids that look like it, in REPLY
  local q i out="" max
  q=$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')
  for ((i = 0; i < NT; i++)); do
    if [ "${T_BIN[i]}" = "$q" ] || [[ "$q" == *"${T_ID[i]}"* ]] || { (( ${#q} >= 3 )) && [[ "${T_HAY[i]}" == *"$q"* ]]; }; then
      out+=", ${T_ID[i]}"; continue
    fi
    max=1; (( ${#T_ID[i]} > 5 )) && max=2
    lev "$q" "${T_ID[i]}"
    (( REPLY <= max )) && out+=", ${T_ID[i]}"
  done
  REPLY=${out#, }
}

how_text() { # how_text <i>: how tool i installs with the loaded pm, in REPLY
  local i=$1 r names=""
  case ${H_TYPE[i]} in
    pkg)  REPLY="$P_ID: ${H_PKGS[i]}"; [ -n "${H_FB[i]}" ] && REPLY+=" (else upstream: ${H_FBVIA[i]})" ;;
    fn)   REPLY="upstream: ${H_VIA[i]}" ;;
    rc)   REPLY="shell function" ;;
    skip) REPLY="unavailable: ${H_WHY[i]}"; return ;;
  esac
  for r in ${T_REQ[i]}; do names+=", ${T_ID[r]}"; done
  [ -n "$names" ] && REPLY+=" (needs ${names#, })"
}

list_tools() { # list_tools [pm]: the tool table
  local pm=$1 g i w1=2 w2=4 w3=5
  if [ -n "$pm" ]; then pm_load "$pm"; fi
  for ((i = 0; i < NT; i++)); do
    (( ${#T_ID[i]} > w1 )) && w1=${#T_ID[i]}
    (( ${#T_NAME[i]} > w2 )) && w2=${#T_NAME[i]}
    (( ${#T_GROUP[i]} > w3 )) && w3=${#T_GROUP[i]}
  done
  if [ -n "$pm" ]; then
    printf "%-${w1}s  %-${w2}s  %-${w3}s  %s\n" ID NAME GROUP "WITH $pm"
  else
    printf "%-${w1}s  %-${w2}s  %-${w3}s  %s\n" ID NAME GROUP DESCRIPTION
  fi
  for ((g = 0; g < ${#G_NAME[@]}; g++)); do
    for i in ${G_TOOLS[g]}; do
      if [ -n "$pm" ]; then how_text "$i"; else REPLY=${T_DESC[i]}; fi
      printf "%-${w1}s  %-${w2}s  %-${w3}s  %s\n" "${T_ID[i]}" "${T_NAME[i]}" "${T_GROUP[i]}" "$REPLY"
    done
  done
}

# ---------------------------------------------------------------- the generator
# How each tool installs with a pm comes precomputed from the page's how() (pm_load). Below is a
# line-for-line port of resolve() and generate() in index.html; tests/parity.mjs checks that the
# two give byte-identical scripts.

resolve_sel() { # SEL (picked) -> ALL (picked + their requirements) and ACT (what gets installed)
  local i r
  ALL=(); ACT=()
  for ((i = 0; i < NT; i++)); do
    [ -n "${SEL[i]}" ] || continue
    ALL[i]=1
    [ "${H_TYPE[i]}" = skip ] && continue
    for r in ${T_REQ[i]}; do ALL[r]=1; done
  done
  for ((i = 0; i < NT; i++)); do
    if [ -n "${ALL[i]}" ] && [ "${H_TYPE[i]}" != skip ]; then ACT[i]=1; fi
  done
}

emit() { local x; for x in "$@"; do S+=$x$'\n'; done; }

rc_block() { # rc_block <name> <body>: as rcBlock() in the page, in REPLY
  local nl=$'\n'
  REPLY="if grep -qF '# boots-on-the-ground: $1' \"\$RC\"; then${nl}  echo \"    $1: already in \$RC\"${nl}else${nl}cat >> \"\$RC\" <<'RC_EOF'${nl}${nl}# boots-on-the-ground: $1${nl}$2${nl}RC_EOF${nl}  echo \"    $1: added\"${nl}fi"
}

gen_script() { # gen_script <pm> <rc_on> <combo>: the install script for ACT/ALL, in REPLY
  local pm=$1 rc_on=$2 combo=$3 nl=$'\n' IFS=$' \t\n' S="" i k pass need_build="" cur="" next base joined
  local -a tools=() left=() pkgs=() soft=() pres=() posts=() fns=() fbs=() bodies=() rcs=() names=() lines=() blocks=() bins=()
  for ((i = 0; i < NT; i++)); do
    if [ -n "${ACT[i]}" ]; then tools+=("$i")
    elif [ -n "${ALL[i]}" ]; then left+=("$i"); fi
  done
  for i in "${tools[@]}"; do
    [ -n "${T_BUILD[i]}" ] && need_build=1
    case ${H_TYPE[i]} in
      pkg)
        pkgs+=("${H_PKGS[i]}")
        if [ -n "${H_PRE[i]}" ]; then snip "${H_PRE[i]}"; pres+=("$REPLY"); fi
        if [ -n "${H_POST[i]}" ]; then snip "${H_POST[i]}"; posts+=("$REPLY"); fi
        # only the first package (the one that provides the binary) is covered by the fallback
        if [ -n "${H_FB[i]}" ]; then fbs+=("$i"); soft+=("${H_PKGS[i]%% *}"); snip "${H_FB[i]}"; bodies+=("$REPLY"); fi ;;
      fn) fns+=("$i"); snip "${H_FN[i]}"; bodies+=("$REPLY") ;;
      rc) rcs+=("$i") ;;
    esac
  done

  for i in "${tools[@]}"; do names+=("${T_NAME[i]%% *}"); done
  emit "#!/usr/bin/env bash" "# Boots on the ground: generated install script" \
    "# generated by dev-tools-installer $BOOTS_VERSION (commit $BOOTS_COMMIT_SHORT)" \
    "# $BOOTS_SITE_HERE#$combo" "# source: $BOOTS_REPO" "# combo:  $combo" \
    "# system: $pm ($P_DISTROS), x86_64 or aarch64"
  for k in "${names[@]}"; do # wrapList(names, 70)
    if [ -n "$cur" ]; then next="$cur, $k"; else next=$k; fi
    if (( ${#next} > 70 )) && [ -n "$cur" ]; then lines+=("$cur,"); cur=$k; else cur=$next; fi
  done
  [ -n "$cur" ] && lines+=("$cur")
  for ((k = 0; k < ${#lines[@]}; k++)); do
    if (( k )); then emit "#         ${lines[k]}"; else emit "# tools:  ${lines[k]}"; fi
  done
  if (( ${#left[@]} )); then
    emit "# left out, not available with $pm:"
    for i in "${left[@]}"; do emit "#   ${T_NAME[i]}: ${H_WHY[i]}"; done
  fi
  emit "#" "# Read it before you run it. System packages need sudo or doas;" \
    '# everything else lands under $HOME (mostly ~/.local/bin) or in /usr/local/go.' \
    "set -uo pipefail" ""
  snip preamble; emit "$REPLY" ""
  if (( ${#bodies[@]} )); then snip helpers; emit "$REPLY" ""; fi

  emit "# ---------------------------------------------------------------- system packages" \
    "pm_refresh() { $P_REFRESH; }" "pm_try() { $P_INSTALL; }"
  snip pm-install; emit "$REPLY"
  emit "" 'echo "==> system packages"' 'pm_refresh || FAILED+=("package index refresh")'
  base=$P_BASE; [ -n "$need_build" ] && base+=" $P_BUILD"
  emit "pm_install $base"' || FAILED+=("base packages: ${PKG_FAILED[*]}")'
  if (( ${#pres[@]} )); then
    emit "" "# extra package repos" "${pres[@]}" 'pm_refresh || FAILED+=("package index refresh")'
  fi
  if (( ${#pkgs[@]} )); then
    emit ""
    if (( ${#soft[@]} )); then
      emit "# packages with an upstream fallback below, used if the distro lacks them" "PKG_SOFT=\" ${soft[*]} \""
    fi
    emit "if ! pm_install ${pkgs[*]}; then" '  for p in "${PKG_FAILED[@]}"; do'
    if (( ${#soft[@]} )); then emit '    case "$PKG_SOFT" in *" $p "*) continue ;; esac'; fi
    emit '    FAILED+=("$p package")' "  done" "fi"
  fi
  if (( ${#posts[@]} )); then emit "" "${posts[@]}"; fi

  if (( ${#bodies[@]} )); then
    emit "" "# ---------------------------------------------------------------- upstream installs"
    for k in "${bodies[@]}"; do emit "$k" ""; done
    if (( ${#fbs[@]} )); then snip fallback; emit "$REPLY" ""; fi
    emit "echo" 'echo "==> upstream installs"'
    for i in "${fns[@]}"; do emit "step ${T_ID[i]} install_${T_ID[i]}"; done
    for i in "${fbs[@]}"; do emit "fallback ${T_ID[i]} install_${T_ID[i]} ${T_BIN[i]}"; done
  fi

  # shell setup: PATH and `init` hooks follow rc_on, except initAlways ones; initUpstreamOnly hooks
  # only with the upstream method; initLast hooks after all others; `rc` functions always
  if [ "$rc_on" = 1 ]; then snip rc-path; rc_block path "$REPLY"; blocks+=("$REPLY"); fi
  for pass in "" 1; do
    for i in "${tools[@]}"; do
      [ -n "${T_INIT[i]}" ] && [ "${T_INITLAST[i]}" = "$pass" ] || continue
      [ "$rc_on" = 1 ] || [ -n "${T_INITALWAYS[i]}" ] || continue
      [ -n "${T_INITUP[i]}" ] && [ "${H_TYPE[i]}" != fn ] && continue
      snip "${T_INIT[i]}"; rc_block "${T_ID[i]}" "$REPLY"; blocks+=("$REPLY")
    done
  done
  for i in "${rcs[@]}"; do snip "${T_RC[i]}"; rc_block "${T_ID[i]}" "$REPLY"; blocks+=("$REPLY"); done
  if (( ${#blocks[@]} )); then
    joined=${blocks[0]}
    for ((k = 1; k < ${#blocks[@]}; k++)); do joined+=$nl$nl${blocks[k]}; done
    snip rc-head
    emit "" "# ---------------------------------------------------------------- shell setup"
    emit "echo" 'echo "==> shell setup"' "$REPLY" "" "$joined"
  fi
  if [ -n "$T_DOCKER" ] && [ -n "${ACT[T_DOCKER]}" ]; then
    snip docker-group; emit "" "echo" 'echo "==> docker group"' "$REPLY"
  fi

  for i in "${tools[@]}"; do [ -n "${T_BIN[i]}" ] && bins+=("${T_BIN[i]}"); done
  emit "" "# ---------------------------------------------------------------- check" "echo" 'echo "==> check"'
  if (( ${#bins[@]} )); then
    emit "for t in ${bins[*]}; do" \
      "  if have \"\$t\"; then printf '    ok       %s\\n' \"\$t\"; else printf '    missing  %s\\n' \"\$t\"; FAILED+=(\"\$t missing\"); fi" \
      "done"
  fi
  if (( ${#rcs[@]} )); then
    k=""; for i in "${rcs[@]}"; do k+=" ${T_ID[i]}"; done
    emit "for f in ${k# }; do" \
      "  if grep -qF \"# boots-on-the-ground: \$f\" \"\$RC\"; then printf '    ok       %s (in %s)\\n' \"\$f\" \"\$RC\"; else printf '    missing  %s\\n' \"\$f\"; fi" \
      "done"
  fi
  emit "" "echo" 'if [ "${#FAILED[@]}" -eq 0 ]; then' \
    '  echo "==> done. Open a new shell to pick up PATH and rc changes."' "else" \
    '  echo "==> finished with problems: ${FAILED[*]}" >&2' "  exit 1" "fi"
  REPLY=$S
}

# ---------------------------------------------------------------- main
boots_main() {
  local mode=run rc_on=1 a pm digits combo i bad="" f picked="" ok
  local -a pos=()
  SEL=()
  for a in "$@"; do
    case $a in
      -h|--help) boots_usage; return 0 ;;
      --print) [ "$mode" = list ] && boots_die "--print and --list don't go together"; mode=print ;;
      --list) [ "$mode" = print ] && boots_die "--print and --list don't go together"; mode=list ;;
      --no-shell) rc_on=0 ;;
      --) ;;
      -*) boots_die "unknown option $a (see --help)" ;;
      *) pos+=("$a") ;;
    esac
  done

  if [ "$mode" = list ]; then
    (( ${#pos[@]} <= 1 )) || boots_die "--list takes at most one package manager"
    if (( ${#pos[@]} )) && ! is_pm "${pos[0]}"; then boots_die "unknown package manager '${pos[0]}' (one of: ${PM_LIST[*]})"; fi
    list_tools "${pos[0]}"
    return 0
  fi
  if (( ${#pos[@]} == 0 )); then boots_usage >&2; exit 2; fi

  a=${pos[0]}
  case $a in
    *-*) # a combo ID: <pm>-<base 36 bitmask>
      pm=${a%%-*}; digits=${a#*-}
      if is_pm "$pm" && tool_word "$digits"; then
        echo "install.sh: '$a' is not a combo ID; did you mean: ... | bash -s -- $pm $digits" >&2
        boots_die "(a combo ID from a page link that happens to spell a tool id is written $pm-0$digits)"
      fi
      is_pm "$pm" || boots_die "'$a' is not a combo ID: '$pm' is not a package manager (one of: ${PM_LIST[*]})"
      case $digits in ''|*[!0-9a-z]*) boots_die "'$a' is not a combo ID (expected $pm- and then digits and lowercase letters)" ;; esac
      (( ${#digits} <= 64 )) || boots_die "'$a' is too long to be a combo ID"
      (( ${#pos[@]} == 1 )) || boots_die "a combo ID takes no tool ids (got: ${pos[*]:1})"
      big_from_b36 "$digits"; big_top
      if (( REPLY > NT )); then
        boots_die "this combo needs a newer version: ${BOOTS_SITE}install.sh (this is $BOOTS_VERSION, which knows $NT tools)"
      fi
      big_bit 0 && rc_on=0
      for ((i = 0; i < NT; i++)); do big_bit $(( i + 1 )) && SEL[i]=1; done
      (( ${#SEL[@]} )) || boots_die "the combo $a picks no tools"
      ;;
    *)
      if ! is_pm "$a"; then
        tool_index "$a" && boots_die "start with the package manager, e.g. apt $a (one of: ${PM_LIST[*]})"
        ok=""
        if (( ${#a} >= 3 )); then # a distro name: say which package manager it uses
          f=$(printf '%s' "$a" | tr '[:upper:]' '[:lower:]')
          for i in "${!PM_IDS[@]}"; do
            case "$(printf '%s' "${PM_DISTROS[i]}" | tr '[:upper:]' '[:lower:]')" in *"$f"*) ok+=" ${PM_IDS[i]}" ;; esac
          done
        fi
        [ -n "$ok" ] && boots_die "'$a' is not a package manager; for $a use:${ok}"
        boots_die "'$a' is not a package manager or a combo ID (package managers: ${PM_LIST[*]})"
      fi
      pm=$a
      (( ${#pos[@]} > 1 )) || boots_die "no tools given; e.g. $pm git jq (see --list $pm)"
      for a in "${pos[@]:1}"; do
        if tool_index "$a"; then SEL[REPLY]=1; continue; fi
        suggest "$a"
        if [ -n "$REPLY" ]; then echo "install.sh: unknown tool id '$a'; did you mean: $REPLY" >&2
        else echo "install.sh: unknown tool id '$a'" >&2; fi
        bad=1
      done
      [ -z "$bad" ] || boots_die "see all tool ids with --list"
      ;;
  esac

  pm_load "$pm"
  resolve_sel
  if (( ${#ACT[@]} == 0 )); then
    for i in "${!ALL[@]}"; do echo "install.sh:   ${T_NAME[i]}: ${H_WHY[i]}" >&2; done
    boots_die "nothing to install: none of these tools is available with $pm"
  fi
  combo_of "$pm" "$rc_on"; combo=$REPLY
  gen_script "$pm" "$rc_on" "$combo"
  if [ "$mode" = print ]; then printf '%s' "$REPLY"; return 0; fi

  # ---- install: check the system, save the script, run it
  boots_root_guard
  a=$pm; [ "$pm" = apt ] && a=apt-get
  if ! command -v "$a" >/dev/null 2>&1; then
    boots_die "$combo is for $pm ($P_DISTROS), but there is no $a here; nothing was changed (see --help for package managers)"
  fi
  f=$(mktemp "${TMPDIR:-/tmp}/boots-install.XXXXXX") || { echo "install.sh: could not create a temp file" >&2; exit 1; }
  printf '%s' "$REPLY" > "$f" || { echo "install.sh: could not write $f" >&2; exit 1; }
  for i in "${!ACT[@]}"; do picked+=", ${T_NAME[i]%% *}"; done
  echo "==> dev-tools-installer $BOOTS_VERSION (commit $BOOTS_COMMIT_SHORT), $pm: ${picked#, }"
  for i in "${!ALL[@]}"; do
    [ -n "${ACT[i]}" ] || echo "    left out, not available with $pm: ${T_NAME[i]} (${H_WHY[i]})"
  done
  echo "==> running the generated script, saved as $f"
  safe_combo "$combo"
  echo "    (to read it without running anything: ... | bash -s -- --print $REPLY)"
  echo
  if { : </dev/tty; } 2>/dev/null; then bash "$f" </dev/tty; else bash "$f" </dev/null; fi
}

boots_main "$@"; exit $?
