#!/usr/bin/env bash
# Install tanin-greet as the greetd greeter on THIS machine. Run with sudo:
#   sudo bash packaging/tanin-greet/install-local.sh
# Reversible: the current greetd config is backed up first.
set -euo pipefail
SRC="$(cd "$(dirname "$0")" && pwd)"
ts="$(date +%Y%m%d-%H%M%S)"

# 1) greeter binary + stylesheet
install -Dm755 "$SRC/tanin-greet"     /usr/bin/tanin-greet
install -Dm644 "$SRC/tanin-greet.css" /etc/greetd/tanin-greet.css

# 2) optional login wallpaper (greeter falls back to a dark scrim if absent)
if [ -f "${TANIN_LOGIN_BG:-}" ]; then
  install -Dm644 "$TANIN_LOGIN_BG" /usr/share/backgrounds/tanin/login.jpg
fi

# 3) point greetd at tanin-greet (back up the working config first)
[ -f /etc/greetd/config.toml ] && cp -a /etc/greetd/config.toml "/etc/greetd/config.toml.bak-$ts"
install -Dm644 "$SRC/config.toml" /etc/greetd/config.toml

cat <<EOF
tanin-greet installed.
  greeter:  /usr/bin/tanin-greet
  css:      /etc/greetd/tanin-greet.css
  greetd:   /etc/greetd/config.toml  ->  cage -s -- tanin-greet
  backup:   /etc/greetd/config.toml.bak-$ts

greetd is already enabled — it shows on the NEXT login. To see it now: log out
(or 'sudo systemctl restart greetd' from a TTY — Ctrl+Alt+F2).
If anything is wrong, switch to a TTY and revert:
  sudo cp /etc/greetd/config.toml.bak-$ts /etc/greetd/config.toml
EOF
