#!/bin/bash
#
# gdm-early-login        Starts gdm in "early-login" mode
#
# chkconfig: 5 9 91 
# description: In early-login mode, GDM will present the login screen to the 
# user before the system is fully booted.  If the user tries to login, GDM will
# wait until the system is booted before trying to authenticate the users 
# credentials.  Note gdm-allow-login must be run to notify GDM that the system 
# is booted.

# Source function library.
. /etc/init.d/functions

[ -f /usr/bin/gdm-binary ] || exit 0
strstr "$(cat /proc/cmdline)" "early-login" || exit 0

# reinitialize i18n 
. /etc/sysconfig/i18n
export LANG LC_MESSAGES

# Determine whether firstboot will run
do_firstboot() {
  if grep -i reconfig /proc/cmdline >/dev/null || [ -f /etc/reconfigSys ]; then
    return 0;
  fi

  if [ -f /etc/sysconfig/firstboot ] && ! grep -q '^RUN_FIRSTBOOT=YES' /etc/sysconfig/firstboot; then
     return 1;
   fi
}

if do_firstboot; then
  exit 0;
fi

RETVAL=0

case "$1" in
  start)
 	echo -n $"Starting display manager: "
	daemon /usr/bin/gdm-binary --wait-for-bootup
	RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/gdm-early-login
	echo
	;;
  stop)
	echo -n $"Shutting down display manager: "
	killproc gdm-binary
	echo
	RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/gdm-early-login
	echo
	;;
  *)
	echo $"Usage: $0 {start|stop}"
	exit 1
esac

exit $RETVAL
