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

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

# Remove the temporary OEM configuration user, if possible.
if getent passwd oem >/dev/null; then
	deluser --quiet --remove-home oem || true
fi

# 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
	case $FRONTEND in
		debconf_ui)
			export DEBIAN_FRONTEND=dialog
			;;
		gtk_ui)
			export DEBIAN_FRONTEND=gnome
			;;
		kde_ui)
			export DEBIAN_FRONTEND=kde
			;;
	esac
	# We're about to pull the rug out from under our own feet, so this
	# has to run very late.
	oem-config-remove || true
fi

exit 0
