#!/bin/sh

## live-config(7) - System Configuration Scripts
## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.


Xinit ()
{
	# Checking if a display manager has been configured
	if [ "${_X11}" = "true" ]
	then
		rm -f /etc/profile.d/zz-live.sh

		return
	fi

	# Checking if package is installed or already configured
	if [ ! -e /var/lib/dpkg/info/xinit.list ] || \
	   [ -e /var/lib/live/config/xinit ]
	then
		return
	fi

	echo -n " xinit"

	Configure_xinit
}

Configure_xinit ()
{
	# Checking if package is already configured differently
	if [ -e /etc/profile.d/zz-live.sh ]
	then
		return
	fi

cat > /etc/profile.d/zz-live.sh << EOF
if [ -z "\${DISPLAY}" ] && [ \$(tty) = /dev/tty1 ]
then
	while true
	do
		if grep -qs quiet /proc/cmdline
		then
			startx > /dev/null 2>&1
		else
			startx
		fi
	done
fi
EOF

	# Creating state file
	touch /var/lib/live/config/xinit
}

Xinit
