#!/bin/sh

# FLL_AUTOLOGIN: DM logs in without a greeter prompt (all but encrypted homed).
# FLL_PASSWORDLESS: user has no password (non-homed only; homed always has one).
# These differ for a directory homed home: autologin yes, passwordless no.
FLL_AUTOLOGIN="yes"
FLL_PASSWORDLESS="yes"
if [ -x /usr/bin/homectl ]; then
	FLL_PASSWORDLESS="no"
	if mountpoint -q /home && [ ! -e /dev/mapper/fll-persist ]; then
		FLL_AUTOLOGIN="no"
	fi
fi

# The passwordless (non-homed) user cannot authenticate. Publish that as a /run
# marker (the single signal session scripts read to relax lock/idle) and deploy
# the blanket polkit grant, both kept out of the read-only image.
if [ "${FLL_PASSWORDLESS}" = "yes" ]; then
	mkdir -p /run/fll
	: > /run/fll/passwordless

	mkdir -p /run/polkit-1/rules.d
	cp /usr/share/fll-live-initscripts/90-fll.rules /run/polkit-1/rules.d/90-fll.rules
fi

# setup desktop autologin for live user
. /usr/share/fll-live-initscripts/fll_desktop

# systemd-homed support
if [ -x /usr/bin/homectl ]; then
	. /usr/share/fll-live-initscripts/fll_homectl
else
	. /usr/share/fll-live-initscripts/fll_adduser
fi

# relax screen locking for a passwordless live user (no-op otherwise)
. /usr/share/fll-live-initscripts/fll_session_passwordless
