#! /bin/sh
# Run oem-config, plus other things that need to run after it in X.
set -e

LANG=en_US.UTF-8 oem-config "$@"

# 'set -e' will cause us to exit if oem-config fails.  Otherwise:

# Don't run again.
rm -f /var/lib/oem-config/run

# Cleanup from anything the early command prepared
RET="$(echo GET oem-config/late_command | debconf-communicate)" || true
if [ "${RET%% *}" = 0 ]; then
	command="${RET#* }"
	log-output sh -c "$command" || true
fi
RET="$(echo GET oem-config/remove | debconf-communicate)"
if [ "${RET#* }" = true ]; then
	#debconf crashes with this set (LP: #641478)
	unset DBUS_SESSION_BUS_ADDRESS
	#mandb postinst doesn't like not knowing the locale
	if [ -r /etc/default/locale ]; then
		. /etc/default/locale
		export LANG LANGUAGE
	fi
	# We're about to pull the rug out from under our own feet, so this
	# has to run very late.
	case $FRONTEND in
		debconf_ui)
			export DEBIAN_FRONTEND=dialog
			oem-config-remove || true
			;;
		gtk_ui)
			oem-config-remove-gtk || true
			;;
		kde_ui)
			export DEBIAN_FRONTEND=kde
			oem-config-remove || true
			;;
	esac
fi

exit 0
