#!/bin/sh
# Makes greetd the boot target so the machine comes up straight in the kiosk Sway
# session (config in /etc/greetd/config.toml, shipped via includes.chroot).
set -eu

. /etc/thinclient-agent/config.env

chmod 0755 /usr/local/bin/kiosk-session

# greetd's own package user; it still needs to exist even though no greeter UI runs.
if ! id greeter >/dev/null 2>&1; then
  useradd --system --create-home --home-dir /var/lib/greetd --shell /usr/sbin/nologin greeter
fi

systemctl enable greetd
systemctl set-default graphical.target

# live-config would otherwise autologin its own account on tty1 and fight greetd for
# the VT. build-thin-client-iso.sh passes `noautologin` on the kernel command line;
# masking the getty on vt1 makes that robust even if someone edits the boot args.
systemctl mask getty@tty1.service

mkdir -p "/home/${KIOSK_USERNAME}/.config/sway"
chown -R "${KIOSK_USERNAME}:${KIOSK_USERNAME}" "/home/${KIOSK_USERNAME}/.config"
