#!/bin/sh
# LightDM starts this after authenticating the account, before launching its desktop.
set -eu

if [ "$#" -eq 0 ]; then
    printf '%s\n' 'Ovu skriptu pokreće LightDM. Za ručnu probu pokreni python3 -I clients/linux/gate.py iz korijena repozitorija.' >&2
    exit 2
fi

if [ ! -x /etc/X11/Xsession ]; then
    printf '%s\n' 'Nedostaje /etc/X11/Xsession. Provjeri postojeći session-wrapper naredbom sudo lightdm --show-config.' >&2
    exit 1
fi

groups=$(/usr/bin/id -nG)
case " $groups " in
    *" learning-gate-child "*)
        client_dir=${0%/*}
        exec /usr/bin/python3 -I "$client_dir/learning-gate-linux.pyz" --session /etc/X11/Xsession "$@"
        ;;
esac

exec /etc/X11/Xsession "$@"
