#!/usr/bin/execlineb -P
# Do not use "exec -c" or "fdmove -c": that yields a restart loop
# and the host shows "Display output is not active". LightDM's own
# log (paths in lightdm.conf / /var/log/lightdm/) is enough; the s6
# pipeline still captures stdout without merging stderr via fdmove -c.
# Pause when another display manager is selected (OpenRC/runit pattern).
envfile /etc/s6-rc/config/lightdm.conf
importas -sCuD "" Args Args

ifelse {
	ifelse { test ! -s /etc/X11/default-display-manager } { true }
	redirfd -r 0 /etc/X11/default-display-manager
	grep -qx /usr/sbin/lightdm
} {
	foreground { mkdir -p /var/lib/lightdm/data }
	foreground { chown lightdm:lightdm /var/lib/lightdm /var/lib/lightdm/data }
	exec /usr/sbin/lightdm ${Args}
}
s6-pause
