# Deploy /etc + /usr/local/bin config files (see 02-system/files/).

# v4l2loopback virtual camera (for OBS virtual webcam)
deploy etc/modprobe.d/v4l2loopback.conf
deploy etc/modules-load.d/v4l2loopback.conf

# Logitech mice (logiops) — config + udev restart rule
deploy etc/logid.cfg
deploy etc/udev/rules.d/90-logid-start-restart.rules

# AirPlay receiver
deploy etc/shairport-sync.conf

# No autologin: plain tty1 password prompt, then ~/.zprofile exec's Hyprland.
# Drop any autologin override left by earlier provisioning.
DROPIN=/etc/systemd/system/getty@tty1.service.d/autologin.conf
if [ -f "$DROPIN" ]; then
  rm -f "$DROPIN"
  rmdir --ignore-fail-on-non-empty "$(dirname "$DROPIN")" 2>/dev/null || true
  systemctl daemon-reload
  info "removed stale autologin drop-in"
fi

# Desktop only: never sleep/suspend
if [ "$IS_DESKTOP" = 1 ]; then
  deploy etc/sleep.conf.d/disable-sleep.conf
fi

# Unlock the keyring at login (what GDM normally does). Idempotent; 'optional'
# so a missing module never blocks login. pam_gnome_keyring.so ships with gnome-keyring.
PAM=/etc/pam.d/login
if ! grep -q pam_gnome_keyring.so "$PAM"; then
  sed -i '/^auth[[:space:]]\+include[[:space:]]\+system-local-login/a auth       optional     pam_gnome_keyring.so' "$PAM"
  sed -i '/^session[[:space:]]\+include[[:space:]]\+system-local-login/a session    optional     pam_gnome_keyring.so auto_start' "$PAM"
  info "wired pam_gnome_keyring into $PAM"
fi

# Keep the login keyring's password in sync when you change your Unix password.
PAM_PW=/etc/pam.d/passwd
if ! grep -q pam_gnome_keyring.so "$PAM_PW"; then
  sed -i '/^password[[:space:]]\+include[[:space:]]\+system-auth/a password   optional     pam_gnome_keyring.so' "$PAM_PW"
  info "wired pam_gnome_keyring into $PAM_PW"
fi

# One-time: pam unlocks the "login" keyring (password = your login password).
# Fresh install creates it automatically; on an existing box, make the login keyring
# the default with that password in Seahorse, or wipe ~/.local/share/keyrings/* and re-login.
