#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# gos720 src/gos/2d/XTOP_R7/app/xdm/config/Xsetup_0 1.2.1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2006,2011 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)54        1.2.1.1  src/gos/2d/XTOP_R7/app/xdm/config/Xsetup_0, xdmcp, gos720 7/15/11 05:12:58
#

/usr/bin/X11/xsetroot -solid black

#								
#  Set the X server's keyboard keysyms to the match the	
#  engravings of the user's keyboard.			
#
#   - Querying odm (querykbd) to get keyboard id (e.g. En_US).
#
#   - If querykbd returns NULL or there is no keyboard file found,
#  then the environment variable $LANG is used for the keymap.
#
#*****************************************************************

. /etc/environment

export LOCPATH ODMDIR NLSPATH LANG

#**************************************************************
# Look to see if the X property _XKB_RULES_NAMES exists.
# If it does, the X server has already set the keyboard mapping.
#***************************************************************
/usr/bin/X11/xprop -root | /usr/bin/grep -q "_XKB_RULES_NAMES"
if [ "$?" != "0" ]
then
    KBD=""
    XDIR=/usr/lpp/X11/defaults/xmodmap

    LONG_KBD_LANG=`/usr/lpp/X11/bin/querykbd`
    KBD_LANG=`echo $LONG_KBD_LANG | /usr/bin/cut -f1 -d'.'`

    if [ "$KBD_LANG" = "NULL" ]
    then
        echo "xdm: Failed to query odm for keyboard id\n"
    else
        if [ "$KBD_LANG" != "C" ]
        then
            if [ -r $IMKEYMAPPATH/$KBD_LANG/keyboard ]
            then
                KBD=$IMKEYMAPPATH/$KBD_LANG/keyboard
            else
                if [ "$IMKEYMAPPATH" = "/usr/lib/nls/im.alt"     	\
                    -a -r $XDIR/$KBD_LANG/keyboard.alt ]
                then
                    KBD=$XDIR/$KBD_LANG/keyboard.alt
                else
                    if [ -r $XDIR/$LONG_KBD_LANG/keyboard ]
                    then
                        KBD=$XDIR/$LONG_KBD_LANG/keyboard
                    else
                        if [ -r $XDIR/$KBD_LANG/keyboard ]
                        then
                            KBD=$XDIR/$KBD_LANG/keyboard
                        fi
                    fi
                fi
            fi
        fi
    fi

    if [ "$KBD" != "" ]
    then
        /usr/bin/X11/xmodmap $KBD
    else
        if [ "$IMKEYMAPPATH" = "/usr/lib/nls/im.alt"   \
            -a -r $XDIR/$LANG/keyboard.alt ]
        then
            /usr/bin/X11/xmodmap $XDIR/$LANG/keyboard.alt
        else
            if [ -r $XDIR/$LANG/keyboard ]
            then
                /usr/bin/X11/xmodmap $XDIR/$LANG/keyboard
            fi
        fi
    fi
fi