#!/bin/sh -e

# Unfortunately, we can't use in-target here as this doesn't allow to set the
# debconf frontend to noninteractive.

. /lib/chroot-setup.sh

if ! chroot_setup; then
	logger -t live-installer -- "Unexpected error; command not executed: '$@'"
	exit 1
fi

DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND

# Reconfigure X.org
if [ -e /target/var/lib/dpkg/info/xserver-xorg.postinst ]; then
	if [ -s /target/etc/X11/xorg.conf ]; then
		cp /target/etc/X11/xorg.conf /target/etc/X11/xorg.conf.orig
	fi

	log-output -t live-installer chroot /target \
	dpkg-reconfigure --no-reload xserver-xorg

	if [ -e /target/etc/X11/xorg.conf.orig ]; then
		mv /target/etc/X11/xorg.conf.orig /target/etc/X11/xorg.conf
	fi
fi

chroot_cleanup
