#!/bin/sh
### BEGIN INIT INFO
# Provides:          oobe
# Should-Start:      console-screen kbd acpid dbus hal consolekit
# Required-Start:    $local_fs $remote_fs x11-common
# Required-Stop:     $local_fs $remote_fs
# X-Start-Before:    lightdm slim slimski sddm
# Default-Start:     5
# Default-Stop:      0 1 6
# Short-Description: OOBE
# Description:       Debian init script for the Out-of-Box Experience
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

case "$1" in
  start)
    #classic X11 mode
    CMD="/usr/bin/startx"
	# Boot will hold here since the process is not being forked.
	echo "Loading Out-of-Box Experience..."
	#check for kwin-wayland
	if [ -x "/usr/bin/kwin-wayland" ]; then
		export XDG_RUNTIME_DIR=/run/user/0
		mkdir -p $XDG_RUNTIME_DIR
		chmod 0700 $XDG_RUNTIME_DIR
		export KWIN_ALLOW_OWNS_WINDOW=1
		CMD="/usr/bin/kwin-wayland --xwayland --exit-with-session"
	fi
	"$CMD" /usr/bin/oobe.sh 2>/dev/null
	# Boot will continue after the OOBE application and X exits.
	;;
esac
exit 0
