#!/bin/bash
# ly.sh — ly TUI display manager (cyberqueer-themed)
#
# ly is a minimal, animated TUI login manager that takes over tty1 from getty.
# Its cyberqueer theming (colormix / doom animation colours) lives in the repo's
# etc-ly-config.ini, which is also an apply-theme.sh SYS_FILES target so the
# palette stays in sync.
#
# This module was extracted from the Desktop-Environment scripts so ly can be
# installed independently of any particular DE. It is mutually exclusive with
# the lightdm greeter module (see modules.conf). Enabling ly here disables the
# other greeters (greetd, lightdm) and the tty1 getty so exactly one display
# manager owns tty1.

set -euo pipefail
source "$(dirname "${BASH_SOURCE[0]}")/../../lib/logging.sh"

# apps/ → optional-Modules → modules → setup → repo root (four levels up).
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../../.." && pwd)"

log "Installing ly display manager..."
sudo pacman -S --noconfirm --needed ly

# ── Deploy the cyberqueer ly configuration ────────────────────────────────────
LY_CONF_SRC="$DOTFILES_DIR/etc-ly-config.ini"
if [[ -f "$LY_CONF_SRC" ]]; then
    log "Deploying ly config to /etc/ly/config.ini..."
    sudo mkdir -p /etc/ly
    sudo cp -f "$LY_CONF_SRC" /etc/ly/config.ini
else
    warn "ly config not found at $LY_CONF_SRC — leaving ly defaults in place."
fi

# ── Make ly the sole greeter on tty1 ──────────────────────────────────────────
# Free tty1 from the getty login prompt so ly can own it.
sudo systemctl disable getty@tty1.service || true
# Turn off the other display managers so two greeters don't race for tty1.
disable_service greetd.service
disable_service lightdm.service
# ly presents the login screen on tty1.
enable_service ly@tty1.service

log "ly display manager installed and enabled. It takes over tty1 on next boot."
