#!/bin/sh
# The installer desktop uses native XKB with a dedicated SDDM X11 session.
set -eu
args=" $(cat /proc/cmdline) "
case "$args" in *' boot=live '*) ;; *) exit 0 ;; esac
case "$args" in
    *' newworld.autoinstall=1 '*|*' newworld.debug=1 '*)
        # Only the running live overlay is changed. Calamares unpacks the
        # original Debian configuration from the read-only system image.
        printf '%s\n' 'run_im none' > /etc/X11/xinit/xinputrc
        # Debian's 0085-sddm writes the primary file. Select X11 there to
        # avoid losing the Wayland autologin session during VT handoff on
        # slower hardware. Keep the GPU driver chosen by the kernel.
        if [ -f /etc/sddm.conf ]; then
            install -m 0644 /usr/local/lib/newworld-installer/installer-session.desktop /usr/share/xsessions/newworld-setup.desktop
            sed -i '/^\[Autologin\]/,/^\[/s/^Session=.*/Session=newworld-setup.desktop/' /etc/sddm.conf
        fi
        ;;
esac
