#!/usr/bin/env /lib/runit/invoke-run
#Copyright: 2022 Lorenzo Puliti <plorenzo@disroot.org>
#           2026 Aitor <aitor@genuen.org>
#License: CC0-1.0

DEFAULT_DISPLAY_MANAGER=$(cat /etc/X11/default-display-manager 2>/dev/null || true)
if [ -n "$DEFAULT_DISPLAY_MANAGER" ] && [ "$DEFAULT_DISPLAY_MANAGER" != "/usr/sbin/lightdm" ]; then
	exit 161
fi

# Only wait for vdev when it is the device manager; otherwise eudev/mdev/etc.
[ ! -x /usr/sbin/vdevd ] || sv check vdev || exit 170
sv check dbus || exit 170
sv check elogind || exit 170
[ -x /usr/sbin/seatd ] && sv start seatd >/dev/null 2>&1 || true

# Shared user-data dir (USERS_DIR); missing on some live images.
mkdir -p /var/lib/lightdm/data
chown lightdm:lightdm /var/lib/lightdm /var/lib/lightdm/data 2>/dev/null || true

if [ -r /etc/default/locale ]; then
	. /etc/default/locale
	export LANG LANGUAGE
fi

if [ -x /bin/plymouth ]; then
	/bin/plymouth quit || true
fi

exec 2>&1

exec /usr/sbin/lightdm
