bootstrap/linux.sh

#!/usr/bin/env bash
# bootstrap/linux.sh — first-run setup on a Debian/Ubuntu or Fedora box.

set -euo pipefail

here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
repo_root="$(cd "$here/.." && pwd)"

# Detect package manager.
if command -v apt-get >/dev/null 2>&1; then
  PM=apt
elif command -v dnf >/dev/null 2>&1; then
  PM=dnf
else
  printf 'linux.sh: no supported package manager (apt/dnf) found\n' >&2
  exit 1
fi

# Install packages listed in packages.txt (# comments ignored, blank lines skipped).
mapfile -t pkgs < <(grep -Ev '^\s*(#|$)' "$here/packages.txt")

printf '== installing %d packages via %s\n' "${#pkgs[@]}" "$PM"
case "$PM" in
  apt)
    sudo apt-get update
    sudo DEBIAN_FRONTEND=noninteractive apt-get install -y "${pkgs[@]}"
    ;;
  dnf)
    sudo dnf install -y "${pkgs[@]}"
    ;;
esac

# stow packages
if ! command -v stow >/dev/null 2>&1; then
  printf 'linux.sh: stow not installed; add it to packages.txt\n' >&2
  exit 1
fi

printf '== stow packages\n'
for pkg in zsh nvim tmux git bin; do
  if [[ -d "$repo_root/$pkg" ]]; then
    (cd "$repo_root" && stow --no-folding --target="$HOME" --restow "$pkg")
  fi
done

# Default shell (best-effort).
if [[ "$SHELL" != *"zsh"* ]] && command -v zsh >/dev/null 2>&1; then
  printf '== setting login shell to zsh\n'
  chsh -s "$(command -v zsh)" "$USER" || true
fi

printf '\nDone. Open a new shell to pick up the zsh config.\n'