#!/usr/bin/env bash
# install.sh: Install dependencies and stow all packages.
# Run this after cloning on a new machine.

set -euo pipefail

DOTFILES_DIR="$(cd "$(dirname "$0")" && pwd)"

# ---------------------------------------------------------------------------
# Dependencies (Fedora)
# ---------------------------------------------------------------------------

DNF_PACKAGES=(
  stow
  # sway ecosystem
  swayidle
  # bar & notifications
  mako
  libnotify        # notify-send
  # terminal & launcher
  fuzzel
  # audio & display
  wireplumber      # wpctl
  pipewire-utils   # pactl
  brightnessctl
  alsa-utils       # speaker-test
  # screen recording
  wf-recorder
  slurp
  zenity
  ffmpeg           # needs RPM Fusion: https://rpmfusion.org
  # misc
  jq
  firefox
)

echo "Installing dnf packages..."
sudo dnf install -y "${DNF_PACKAGES[@]}"

# ---------------------------------------------------------------------------
# Packages not in Fedora repos — install manually if missing
# ---------------------------------------------------------------------------

warn_missing() {
  local cmd="$1" msg="$2"
  if ! command -v "$cmd" &>/dev/null; then
    echo "WARNING: '$cmd' not found — $msg"
  fi
}

warn_missing autotiling  "install via pip: pip install --user autotiling"
warn_missing eww         "install from https://github.com/elkowar/eww/releases"
warn_missing wezterm     "install from https://wezfurlong.org/wezterm/install/linux.html"

# ---------------------------------------------------------------------------
# Stow all packages
# ---------------------------------------------------------------------------

echo ""
echo "Stowing dotfiles..."
for PACKAGE in "$DOTFILES_DIR"/*/; do
  PACKAGE="$(basename "$PACKAGE")"
  echo "  $PACKAGE"
  stow --dir="$DOTFILES_DIR" --target="$HOME" --restow "$PACKAGE"
done

echo "Done."
