#!/usr/bin/ksh
DXXDIR="/opt/IBMdb2xml/V7.1"
INSTHOME=$HOME

cd
#check if $HOME/dxx exists
#if not create $HOME/dxx
if [ ! -d ${INSTHOME?}/dxx ]; then
mkdir -p ${INSTHOME?}/dxx
fi

ln -fs ${DXXDIR?}/bin  ${INSTHOME?}/dxx/bin

ln -fs ${DXXDIR?}/bnd  ${INSTHOME?}/dxx/bnd

#copy template of dxxprofile from root source to
# to ${INSTHOME?}/dxx
cp ${DXXDIR?}/bin/dxxprofile ${INSTHOME?}/dxx

cd ${INSTHOME?}/sqllib/function
ln -fs ${DXXDIR?}/lib/libdb2xml.so db2xml
ln -fs ${DXXDIR?}/lib/db2xmlfn.so db2xmlfn
ln -fs ${DXXDIR?}/lib/libmqxml.so mqxml

# Find out if the instance owner's home directory contains a sqllib/db2profile
# If sqllib/db2profile exists, then add the line . dxx/dxxprofile
# at the end.

if [ -f ${INSTHOME?}/sqllib/db2profile -a -w ${INSTHOME?}/sqllib/db2profile ]; then
    /usr/bin/egrep -v '#' ${INSTHOME?}/sqllib/db2profile | \
        /usr/bin/grep ". \${INSTHOME\?}/dxx/dxxprofile" 1>/dev/null 2>/dev/null
    if [ $? -ne 0 ]; then
        /usr/bin/echo "
# The following three lines have been added by DB2 XML Extender.
if [ -f \${INSTHOME?}/dxx/dxxprofile ]; then
    . \${INSTHOME?}/dxx/dxxprofile
fi
" >> ${INSTHOME?}/sqllib/db2profile 2>/dev/null
        if [ $? -ne 0 ]; then
            echo 'Unable to modify sqllib/db2profile'
        fi
    fi
fi

