#!/bin/sh

#set -e

# initramfs-tools header

PREREQ=""

prereqs()
{
	echo "${PREREQ}"
}

case "${1}" in
	prereqs)
		prereqs
		exit 0
		;;
esac

# live-initramfs header

if [ -n "${NOXAUTOCONFIG}" ] || [ ! -x /root/usr/bin/X ] || [ -z "${XDRIVER}" ]
then
	exit 0
fi

. /scripts/live-functions

log_begin_msg "Configuring X video driver"

# live-initramfs script

. /live.vars

mount -o bind /sys /root/sys
mount -o bind /proc /root/proc
mount -o bind /dev /root/dev

if [ "${XDRIVER}" != "dexconf" ]
then

chroot /root debconf-communicate -fnoninteractive live-initramfs > /dev/null << EOF
set xserver-xorg/autodetect_video_card false
set xserver-xorg/config/device/driver ${XDRIVER}
EOF

fi

chroot /root dexconf

umount /root/sys
umount /root/proc
umount /root/dev

log_end_msg
