#!/bin/ksh -p
#
# ident "@(#)utgdmconfigpath.ksh	1.3	09/08/14 SMI"
#
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
PATH=/usr/bin:/bin:/usr/sbin:/sbin
export PATH

gdm_path=/etc/gdm:/etc/X11/gdm
status=0

function utdirpath {
	saveifs="$IFS"
	IFS=:
	for dir in $2; do
		if [ -f "$dir/$1" ]; then
			print "$dir/"
			break
		fi
	done
	IFS="$saveifs"

}

if [ "`uname -s`" = "SunOS" ]; then
    gdm_dir=$(utdirpath custom.conf $gdm_path)
    if [ -z "$gdm_dir" ]; then 
	status=1
    fi

else
    gdm_path=`rpm -ql "gdm" | grep "custom.conf"`
    if [ $? -ne 0 ]; then
	status=1
    else
	gdm_dir=${gdm_path%custom.conf}
    fi
fi

if [ "$status" -ne 0 ]; then
	print -u2 "$(basename $0): Cannot determine GDM install directory"
	exit 1;
fi

print $gdm_dir
exit 0
