#! /bin/ksh
# @(#)31  1.4  src/cde/cde1/dtconfig/ibm/rc.dt.src, desktop, cde720 6/4/09 04:48:20
# *                                                                      * 
# * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
# * (c) Copyright 1993, 1994 International Business Machines Corp.       *
# * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
# * (c) Copyright 1993, 1994 Novell, Inc.                                *
#
# COMPONENT_NAME: DESKTOP rc.dt
#
# FUNCTIONS:
#
# ORIGINS: 27
#
# (C) COPYRIGHT International Business Machines Corp. 1994, 1995
# All Rights Reserved
# Licensed Materials - Property of IBM
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
####################################################################
# rc.dt -
#       starts the AIX Windows Desktop Login
#       waits for the X Server to start
####################################################################

if [ "$1" != "boot" -a -f /.bootsequence ]
then
#
#       clean things up from graphical boot
#
        /usr/bin/rm -f /.bootsequence
	if [ -f /.bootsequence ]; then
		echo "\n\nError: Unable to remove /.bootsequence.\n\n"
	fi

        /usr/bin/ps -ef | /usr/bin/grep "dtlogin" | /usr/bin/grep -v grep >/dev/null
        if [ "$?" -eq 0 ] ; then
                exit 0
        fi
fi


#
# Start the dtsrc subsystem
#
/usr/dt/bin/dtlogin -daemon

#
# Check for error on starting the dtsrc subsystem
#
rc=$?
if [ "$rc" != "0" ]; then
	echo "\n\nERROR: The AIX Windows Desktop is not correctly configured\n"
	exit 1
fi

echo "Starting AIX Windows Desktop....\c"

#
# Sleep for <= 10 secs for the X server to come up.
#

i=10
while [ "$i" != 0 ]
do
	#
	# checking if the X server is up and running.
	#
        XPID=`ps -ef | awk '$8~/^.*\/X$/{print $3}'`
        if [ -n "$XPID" ]; then                  
           ps -ef | grep $XPID | grep "dtlogin" | grep -v grep    1>/dev/null
           rc=$?                                          
        else                                                                    
           rc=1                                                                 
        fi                                                                      
	if [ "$rc" -eq "0" ]; then
		break 
	fi
	sleep 1
	echo ".\c"
	i=`expr $i - 1`  # decrement count
done

sleep 1