#!/bin/sh
# tpgxyz@gmail.com

if grep -q '\bsystemd.unit=calamares.target\b' /proc/cmdline; then
. /etc/locale.conf

# ensure plymouth really has stopped
    if pgrep "plymouthd" > /dev/null 2>&1; then
	/bin/plymouth quit --retain-splash
    fi

/bin/systemctl stop crond.service &

xset -dpms
xset s off

if [ -x /usr/bin/openbox ]; then
    /usr/bin/openbox &
else
    echo "openbox not found. Exiting."
    sleep 30
    reboot
fi
sleep 1

    if [ "$(pidof openbox)" ]; then
	# setup background
	if [ -e /usr/share/mdk/backgrounds/default.jpg ] && [ -f /usr/bin/xli ]; then
	    /usr/bin/xli -onroot -fillscreen /usr/share/mdk/backgrounds/default.jpg &
	fi

	/usr/bin/calamares
	sleep 1
    else
	echo "Can not start calamares. Rebooting..."
	sleep 5
    fi

# check if we are booted from cd drom to eject it
blkid /dev/sr0 >/dev/null 2>&1
if [[ $? -eq 0 ]]; then
    eject
    sleep 10
fi

sync
reboot

fi
