#!/bin/sh

# Enable onboard for user
systemctl enable onboard@"${SUBJECT}"

# Enable auto-rotate
systemctl --global enable auto-rotate.service touchswipe.service

# Enable autologin
echo -e "[Autologin]\nUser=${SUBJECT}\nSession=plasmax11" > /etc/sddm.conf.d/00-autologin.conf

# Add user to mandatory groups. Add each independently: usermod -aG validates
# the whole list up front and aborts atomically if any group is missing, so a
# single absent optional group (e.g. pipewire before its sysusers entry is
# processed) must not strip the user of video/audio/input. Losing video locks
# the session out of the GPU nodes (/dev/nvhost-gpu, /dev/dri/*) -> kwin_x11
# SIGSEGVs on GL init and the KDE session hangs before the desktop.
# pipewire: grants RT scheduling rights to libpipewire-module-rt via
# /etc/security/limits.d/25-pw-rlimits.conf, preventing audio underruns/skips.
for grp in wheel video audio input pipewire; do
	getent group "${grp}" >/dev/null 2>&1 && usermod -aG "${grp}" "${SUBJECT}"
done

# Remove openbox session file
rm -f /usr/share/xsessions/openbox.desktop
