#!/bin/sh

PATH=/sbin:/usr/sbin:/bin:/usr/bin

# shut down any graphical boot that might exist
if [ -x /usr/bin/rhgb-client ]; then
    /usr/bin/rhgb-client --quit
fi

# We need to source this so that the login screens get translated
[ -f /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n

# Run preferred X display manager
preferred=
if [ -f /etc/sysconfig/desktop ]; then
  . /etc/sysconfig/desktop
  dm=$(echo "$DISPLAYMANAGER" | LC_COLLATE=C tr '[A-Z]' '[a-z]')
  dk=/usr/share/xdisplaymanager/"$dm".desktop
  if [ -x "$dk" ] ; then
    preferred=$(sed -n -e 's/^Exec=//p' "$dk")
  fi
fi

shopt -s execfail

[ -x "$preferred" ] && exec "$preferred" "$@" >/dev/null 2>&1 </dev/null

# Fallbacks, in order
exec gdm "$@" >/dev/null 2>&1 </dev/null
exec kdm "$@" >/dev/null 2>&1 </dev/null
exec wdm "$@" >/dev/null 2>&1 </dev/null
exec xdm "$@" >/dev/null 2>&1 </dev/null
# catch all exit error
exit 1
