#!/bin/bash

# Check for an xorg.conf
if [ ! -e /etc/X11/xorg.conf ]
then
	echo "ERROR: /etc/X11/xorg.conf cannot be found! Exiting"
	exit 1
fi

if [ -f /sbin/livecd-functions.sh ]
then
	source /sbin/livecd-functions.sh
else
	echo "ERROR: /sbin/livecd-functions.sh could not be loaded!"
	exit 1
fi

livecd_check_root || exit 1

#first, get paths right if we're getting started b4 login
source /etc/profile

livecd_get_cmdline || exit 1

for x in $CMDLINE
do
        if [ "$x" = "agpgart" ]
        then
			modprobe agpgart > /dev/null 2>&1
        fi
done

get_video_cards || exit 1

if [ -x /usr/sbin/opengl-update-livecd ]
then
	/usr/sbin/opengl-update-livecd $GLTYPE
elif [ -x /usr/bin/eselect -a -e /usr/share/eselect/modules/opengl.eselect ]
then
	/usr/bin/eselect opengl set $GLTYPE --dst-prefix=/etc/opengl
elif [ -x /usr/sbin/opengl-update ]
then
	/usr/sbin/opengl-update --dst-prefix=/etc/opengl $GLTYPE
else
	echo "ERROR: no opengl-update script can be located"
	exit 1
fi

#exec /usr/bin/xinit
