#!/bin/sh

## live-config(7) - System Configuration Scripts
## Copyright (C) 2006-2010 Daniel Baumann <daniel@debian.org>
##
## live-config 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-xinit.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 if package is already configured differently
	if [ -e /etc/profile.d/zz-xinit.sh ] || grep -qs "startx" /etc/skel/.bash_profile
	then
		return
	fi

	if [ -e /etc/profile.d ]
	then

# squeeze
cat > /etc/profile.d/zz-xinit.sh << EOF
if [ -z "\${DISPLAY}" ] && [ \$(tty) = /dev/tty1 ]
then
	while true
	do
		startx
	done
fi
EOF

	else

# lenny
cat >> /etc/skel/.bash_profile << EOF
if [ -z "\${DISPLAY}" ] && [ \$(tty) = /dev/tty1 ]
then
	while true
	do
		startx
	done
fi
EOF

	fi

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

Xinit
