#!/bin/ksh -p
#
# ident "@(#)gdmgreeter.ksh	1.4	06/06/30 SMI"
#
# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

UNAME=/bin/uname
LOGGER=/bin/logger
LOGGER_LEVEL="-p daemon.error"
GREETER_PREF="/usr/bin/gdmgreeter-"
GREETER_PROG=

# try using 'uname -p' first to determine the greeter program to use.  If the result
# is not currently supported, try using the 'uname -m'.  If both fails then log a
# message with a possible workaround.
#
ISA_P=`${UNAME} -p`
ISA_M=`${UNAME} -m`

for ISA in ${ISA_P} ${ISA_M}
do
	case "${ISA}" in
	i?86*|i86*|athlon)
		GREETER_PROG="${GREETER_PREF}i386";;
	x86_64)
		GREETER_PROG="${GREETER_PREF}x86_64";;
	esac

	if [ -n "${GREETER_PROG}" ] ;then
		# we have the greeter program name
		break
	fi
done

if [ -z "${GREETER_PROG}" ]; then
	$LOGGER $LOGGER_LEVEL \
	"gdmgreeter[$PPID]: unsupported system architecture ${ISA_P}.  Try creating the"\
	"symbolic link /usr/bin/gdmgreeter-${ISA_P} to point to either /usr/bin/gdmgreeter-i386"\
	"for a 32-bit server or /usr/bin/gdmgreeter-x86_64 for a 64-bit server."
	exit 1
elif [ ! -e "${GREETER_PROG}" ]; then
	$LOGGER $LOGGER_LEVEL "gdmgreeter[$PPID]: file ${GREETER_PROG} not found!"
	exit 1
elif [ ! -x "${GREETER_PROG}" ]; then
	$LOGGER $LOGGER_LEVEL "gdmgreeter[$PPID]: file ${GREETER_PROG} not executable!"
	exit 1
fi

exec "$GREETER_PROG" "$@"
