#####################################################################################################################################################################
#
# FileName: upgradeSRAjes2jes3
#
# Author : Ranbir Mazumdar
#
# The idea of this primer is to make the reader comfortable with this JES3 upgrade script. I will basically add my comments inline with the code so that the reader
# will have the actual code that needs to be explained. Note that as standard practice, I shall use # as the beginning of the comments so that this file shall have
# the syntactic sanctity. I will give gyan on the general layout of the file and then add my specific comments inline
#
# We start off with a description of the upgrade script. The action starts at the Main part Look for ?# Main? minus quotes in the script. We ascertain the
# /etc/opt/SUNWps/PSConfig.properties as the state file which will be sourced (i.e. Read from) to get some values. Here it is $ps_props
#
# A typical case of sourcing the JDK directory is shown below to highlight what is happening:
#
#     GrabConfig $STATE_FILE "JDK_DIR" "="
#     if [ "$ANSWER" != "" ]; then
#        JDK_DIR=$ANSWER
#    else
#       $ECHO "Error: Cannot determine JDK_DIR."
#       exit 1
#    fi
# Here we call GrabConfig passing the state file and look for JDK_DIR value. If there exists an entry for JDK_DIR as a ?key=value? type entry, that is used in $ANSWER,
# else Error is spitted out. Similarly there are a bunch of values that are received from the state file. Once done, there is this concept of upgrading ldif file and
# schema xml attribute updates. What it means is that there are new attributes that have been added to the ldif file and schema xml, that need upgrade. We will look at
# such an example like the Upgrade Netlet schema (Look for ?# Netlet Upgrade? minus the quotes, in this document). Here the flow is like this:
#
# So a pseudo-code for this operation will be something like:
# <Start-ldif-modify>
#     1. Create a temp FILE variable
#       2. Add the attribute(s) that has(have) changed something like:
#        dn: cn=schema
#        changetype:modify
#        attributeTypes: ( sunPortalNetletLaunchMode-oid NAME 'sunPortalNetletLaunchMode' DESC 'SunOne Portal Netlet Attribute'
#                   SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN 'SunOne Portal defined' )
#       3. Add the object class if changed, e.g. :
#        dn: cn=schema
#        changetype:modify
#        add:objectClasses
#        objectClasses: ( sunPortalNetletService-oid NAME 'sunPortalNetletService' DESC 'SunOne Portal Netlet Service' SUP top
#                 AUXILIARY MAY ( sunPortalNetletRules $ sunPortalNetletPortWarn $ sunPortalNetletDoReauth $ sunPortalNetletClientLoopbackPort
#                 $ sunPortalNetletKeepAliveInterval $ sunPortalNetletAccessRules $ sunPortalNetletDenyRules $ sunPortalNetletAccessHosts
#                 $ sunPortalNetletDenyHosts $ sunPortalNetletExecute $ sunPortalNetletKSSLDefaultCipher $ sunPortalNetletJSSEDefaultCipher
#                 $ sunPortalNetletUserCipher $ sunPortalNetletPassword $ sunPortalNetletTerminateAtLogout $ sunPortalNetletProxyType
#                 $ sunPortalNetletProxyHost $ sunPortalNetletProxyPort $ sunPortalNetletProxyOverride $ sunPortalNetletPortWarnCheckbox
#                 $ sunPortalNetletClientBindIP $ sunPortalNetletLaunchMode $ sunPortalNetletKeepJWSWinMinimized $ sunPortalNetletDownloadDefault )
#                 X-ORIGIN 'SunOne Portal defined' )
#        EOF
#
#
#       4.  Call ldapmodify with given parameters
#    5.  Delete the temp file
# </Start-ldif-modify>
#
# <Start-schema-modify>
#
#     We have the actual netlet xml which you can find under /ps/srap/src/com/sun/portal/netlet/xml/srapNetlet.xml # That has two xml infosets,
#    (1) Dynamic attributes and (2) Static attributes. Look under <Dynamic> </Dynamic> for the dynamic attributes and under <User> </User> for the user attributes.
#    The basic idea is to have these dynamic and user attributes captured as different files, and added to the final service xmls for final consumption. Here is
#    a pseudo-code for this operation :
#    
#    1.Create a temp FILE variables, one each for the dynamic attributes, user attributes and schema attributes.
#       2 call eval amadmin command passing necessary params.
#
# </Start-schema-modify>
#
#######################################################################################################################################################################

#!/bin/sh

###############################################
# Sourcing macros
# DIRNAME=/usr/bin/dirname
#. `$DIRNAME $0` ../lib/psmacros
###############################################
. ../lib/psmacros

###############################################
# Get configuration from file
###############################################
GrabConfig() {
  GRABCONFIG_KEY=$1
  GRABCONFIG_FILE=$2
  GRABCONFIG_SEPARATOR=$3
  ANSWER_CONFIG=`$GREP "^$GRABCONFIG_KEY$GRABCONFIG_SEPARATOR" $GRABCONFIG_FILE | $UNIQ | $SED -e "s/$GRABCONFIG_KEY$GRABCONFIG_SEPARATOR//" | $SED -e "s/^ //"`
}

###############################################
# Get password
###############################################
GetPassword() {
  local PROMPT=$1
  local DONE=""

  DONE="n"
  while [ "$DONE" = "n" ]; do
    eval $ECHO "$PROMPT \$OMIT_CHAR"
    $STTY -echo
    read ANSWER
    $STTY echo
    $ECHO ""
    if [ "$ANSWER" != "" ]; then
      DONE="y"
      fi
  done
}

##############################################################################################
# Load the Resource bundle to Directory Server
##############################################################################################

LoadResourceBundle() {
    if [ "$1" == "Proxylet" ]; then
        FILE="/tmp/srapProxylet.properties"   
        NAME="srapProxylet"
        SEDFILE="/tmp/srapProxylet.sed"

$CAT > $FILE <<EOF
xProxylet3.rules=Proxylet Rules
xProxylet3.rules.link=Edit
helptoc.doc=srahelp.html
onlinehelp.doc=ps/attrib6.html
EOF

$CAT > $SEDFILE <<EOF
\$d
1,3d
/xProxylet3.rules/d
/xProxylet3.rules.link/d
/helptoc.doc/d
/onlinehelp.doc/d
/xProxylet3.rules.help/d
EOF

    # Now get the existing resource bundle and write to a tmp file
    curDir=$PWD
    cd ${IDSAME_BASE_DIR}/${IDSAME_PRODUCT_DIR}/bin/
        ./amadmin --runasdn "$AM_ADMIN_DN" --password "$IDSAME_ADMIN_PASSWORD" --verbose --getresourcestrings $NAME > $FILE-tmp

    # Now remove the success message and create the temp file again
    $SED -f $SEDFILE  $FILE-tmp >> $FILE
    
    #Remove the existing resource bundle.
    ./amadmin --runasdn "$AM_ADMIN_DN"  --password "$IDSAME_ADMIN_PASSWORD" --verbose --deleteresourcebundle $NAME
   
    # Now upload the resource bundle with additions appended
    ./amadmin --runasdn "$AM_ADMIN_DN"  --password "$IDSAME_ADMIN_PASSWORD" --verbose --addresourcebundle $NAME --resourcebundlefilename $FILE
        cd ${curDir}
    $RM $FILE $FILE-tmp $SEDFILE

    elif [ "$1" == "Netlet" ]; then
        FILE="/tmp/srapNetlet.properties"
    NAME="srapNetlet"
        SEDFILE="/tmp/srapNetlet.sed"
$CAT > $FILE << EOF

d08=Keep Alive Interval (seconds)
d14=Launch Netlet Using
EOF

$CAT > $SEDFILE << EOF
\$d
1,3d
/d08/d
/d14/d
EOF

        # Now get the existing resource bundle and write to a tmp file
    curDir=$PWD
    cd ${IDSAME_BASE_DIR}/${IDSAME_PRODUCT_DIR}/bin/
        ./amadmin --runasdn "$AM_ADMIN_DN" --password "$IDSAME_ADMIN_PASSWORD" --verbose --getresourcestrings $NAME >> $FILE-tmp
   
    # Now remove the success message and replace new key values
        $SED -f $SEDFILE $FILE-tmp >> $FILE
   
    # Now upload the resource bundle with additions appended
    #./amadmin --runasdn \"$AM_ADMIN_DN\" --password "$IDSAME_ADMIN_PASSWORD" --verbose --addresourcebundle $NAME --resourcebundlefilename $FILE
    ./amadmin --runasdn "$AM_ADMIN_DN" --password "$IDSAME_ADMIN_PASSWORD" --verbose --addresourcebundle $NAME --resourcebundlefilename $FILE
        cd ${curDir}
    $RM $FILE
        $RM $FILE-tmp
        $RM $SEDFILE
elif [ "$1" == "Gateway" ]; then
        FILE="/tmp/srapGatewayAdminConsole.properties"
    NAME="srapGatewayAdminConsole"
        SEDFILE="/tmp/srapGatewayAdminConsole.sed"
$CAT > $FILE << EOF
g21=Timeout for Persistent Socket Connections (seconds)
g22=Grace Timeout to Account for Turnaround Time (seconds)
g26=Gateway Timeout (seconds)
g28=Cached Socket Timeout (seconds)
g42=Server Retry Interval (seconds)
EOF

$CAT > $SEDFILE << EOF
\$d
1,3d
/g21/d
/g22/d
/g26/d
/g28/d
/g42/d
EOF

        # Now get the existing resource bundle and write to a tmp file
    curDir=$PWD
    cd ${IDSAME_BASE_DIR}/${IDSAME_PRODUCT_DIR}/bin/
        ./amadmin --runasdn "$AM_ADMIN_DN" --password "$IDSAME_ADMIN_PASSWORD" --verbose --getresourcestrings $NAME >> $FILE-tmp
   
    # Now remove the success message and replace new key values
        $SED -f $SEDFILE $FILE-tmp >> $FILE
   
    # Now upload the resource bundle with additions appended
    #./amadmin --runasdn \"$AM_ADMIN_DN\" --password "$IDSAME_ADMIN_PASSWORD" --verbose --addresourcebundle $NAME --resourcebundlefilename $FILE
    ./amadmin --runasdn "$AM_ADMIN_DN" --password "$IDSAME_ADMIN_PASSWORD" --verbose --addresourcebundle $NAME --resourcebundlefilename $FILE
        cd ${curDir}
    $RM $FILE
        $RM $FILE-tmp
        $RM $SEDFILE
   
     else
         $ECHO "$1 : Module Specified doesn't exist"
     fi
}

#############################################
# Upgrade SRA Core componet
############################################

UpgradeSRACore () {
ps_props="$PS_CONFIG_DIR/PSConfig.properties"
gw_support_props="$PS_CONFIG_DIR/SRAConfig.properties"
gw_props="$PS_CONFIG_DIR/GWConfig.properties"
amconfig_props="$IDSAME_CONFIG_DIR/config/AMConfig.properties"

LOG_DIR="/var/opt/sun/portal/tmp/"
LOG_FILE="$LOG_DIR/upgradeSRAJ3.log"
LOG_FILE="/tmp/upgradeSRAJ3.log"

GrabConfig "IDSAME_BASEDIR" $ps_props "="
IDSAME_BASE_DIR=$ANSWER_CONFIG

GrabConfig "DEPLOY_URI" $ps_props "="
PORTAL_DEPLOY_URI=$ANSWER_CONFIG

GrabConfig "IDSAME_AMSERVER" $ps_props "="
AMSERVER_DEPLOY_URI=$ANSWER_CONFIG

GrabConfig "IDSAME_AMCONSOLE" $ps_props "="
AMCONSOLE_DEPLOY_URI=$ANSWER_CONFIG

GrabConfig "SERVER_DOMAIN" $gw_support_props "="
PORTAL_SERVER_DOMAIN=$ANSWER_CONFIG

GrabConfig "DS_HOST" $ps_props "="
DS_HOST=$ANSWER_CONFIG

GrabConfig "DS_PORT" $ps_props "="
DS_PORT=$ANSWER_CONFIG

GrabConfig "DS_DIRMGR_DN" $ps_props "="
DS_ADMIN_DN=$ANSWER_CONFIG

GrabConfig "BASEDIR" $ps_props "="
PS_BASEDIR=$ANSWER_CONFIG

GrabConfig "DEPLOY_TYPE" $ps_props "="
DEPLOY_TYPE=$ANSWER_CONFIG

GrabConfig "DEPLOY_DIR" $ps_props "="
DEPLOY_DIR=$ANSWER_CONFIG

GrabConfig "com.iplanet.am.version" $amconfig_props "="
AM_VERSION=$ANSWER_CONFIG

GrabConfig "com.sun.identity.authentication.super.user" $amconfig_props "="
USER_NAMING_ATTR=`$ECHO $ANSWER_CONFIG | $CUT -f1 -d =`

GetPassword "What is the Directory server $DS_HOST:$DS_PORT password for $DS_ADMIN_DN ?"
DS_DIRMGR_PASSWORD=$ANSWER
export DS_DIRMGR_PASSWORD

GetPassword "What is the IS amadmin password ?"
IDSAME_ADMIN_PASSWORD=$ANSWER
export IDSAME_ADMIN_PASSWORD

GetPassword "What is the SRA log user password ?"
SRA_LOG_USER_PASSWORD=$ANSWER
export SRA_LOG_USER_PASSWORD

AM_ADMIN_DN="amadmin"

GrabConfig "com.iplanet.am.rootsuffix" $amconfig_props "="
DS_BIND_DN=$ANSWER_CONFIG

AMADMIN=$IDSAME_BASE_DIR/$IDSAME_PRODUCT_DIR/bin/amadmin
DPADMIN=$PS_BASEDIR/$PS_PRODUCT_DIR/bin/dpadmin

export LD_LIBRARY_PATH=$IDSAME_BASE_DIR/$IDSAME_PRODUCT_DIR/ldaplib/ldapsdk:/usr/lib/mps:$LD_LIBRARY_PATH

GrabConfig "SERVER_PROTOCOL" $ps_props "="
PORTAL_SERVER_PROTOCOL=$ANSWER_CONFIG

GrabConfig "PS_HOST" $ps_props "="
PORTAL_SERVER_HOST=$ANSWER_CONFIG

GrabConfig "PS_PORT" $ps_props "="
PORTAL_SERVER_PORT=$ANSWER_CONFIG

GrabConfig "com.iplanet.am.server.protocol" $amconfig_props "="
IS_SERVER_PROTOCOL=$ANSWER_CONFIG

GrabConfig "com.iplanet.am.server.host" $amconfig_props "="
IS_SERVER_HOST=$ANSWER_CONFIG

GrabConfig "com.iplanet.am.server.port" $amconfig_props "="
IS_SERVER_PORT=$ANSWER_CONFIG

LOAD_BALANCER_URL="$PORTAL_SERVER_PROTOCOL://$PORTAL_SERVER_HOST:$PORTAL_SERVER_PORT$PORTAL_DEPLOY_URI"

IS_AMSERVER_URL="$IS_SERVER_PROTOCOL://$IS_SERVER_HOST:$IS_SERVER_PORT$AMSERVER_DEPLOY_URI"
IS_AMCONSOLE_URL="$IS_SERVER_PROTOCOL://$IS_SERVER_HOST:$IS_SERVER_PORT$AMCONSOLE_DEPLOY_URI"

$ECHO "Placing Netfile .so file in library path..."
PS_LIB_DIR=$PS_BASEDIR/$PS_PRODUCT_DIR/lib
if [ "$DEPLOY_TYPE" = "IWS" ]; then
$CP $PS_LIB_DIR/libgetpwnam.so $DEPLOY_DIR/bin/https/lib
$CP $PS_LIB_DIR/libgetpwnam2.so $DEPLOY_DIR/bin/https/lib
fi

ORG_DN=`$GREP "^com.iplanet.am.defaultOrg=" $amconfig_props | $SED -e "s/com.iplanet.am.defaultOrg=//"`
PEOPLE_DN="ou=People,$ORG_DN"

##############################################################################################
# Begin Netlet Upgrade
##############################################################################################

$ECHO "Upgrading Netlet"
$ECHO "Upgrading Netlet" >> $LOG_FILE

FILE="/tmp/srapNetlet.ldif"

# Upload the corresponding ldif file.
$CAT > $FILE <<EOF
#
# Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
# PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
#
dn: cn=schema
changetype:modify
add:attributeTypes
attributeTypes: ( sunPortalNetletLaunchMode-oid NAME 'sunPortalNetletLaunchMode' DESC 'SunOne Portal Netlet Attribute' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE X-ORIGIN 'SunOne Portal defined' )


dn: cn=schema
changetype:modify
add:objectClasses
objectClasses: ( sunPortalNetletService-oid NAME 'sunPortalNetletService' DESC 'SunOne Portal Netlet Service' SUP top AUXILIARY MAY ( sunPortalNetletRules $ sunPortalNetletPortWarn $ sunPortalNetletDoReauth $ sunPortalNetletClientLoopbackPort $ sunPortalNetletKeepAliveInterval $ sunPortalNetletAccessRules $ sunPortalNetletDenyRules $ sunPortalNetletAccessHosts $ sunPortalNetletDenyHosts $ sunPortalNetletExecute $ sunPortalNetletKSSLDefaultCipher $ sunPortalNetletJSSEDefaultCipher $ sunPortalNetletUserCipher $ sunPortalNetletPassword $ sunPortalNetletTerminateAtLogout $ sunPortalNetletProxyType $ sunPortalNetletProxyHost $ sunPortalNetletProxyPort $ sunPortalNetletProxyOverride $ sunPortalNetletPortWarnCheckbox $ sunPortalNetletClientBindIP $ sunPortalNetletLaunchMode ) X-ORIGIN 'SunOne Portal defined' )
EOF

curdir=$PWD
cd ${IDSAME_BASE_DIR}/${IDSAME_PRODUCT_DIR}/bin/
#./ldapmodify -a -h ${DS_HOST} -p ${DS_PORT} -D "${DS_ADMIN_DN}" -w "${DS_DIRMGR_PASSWORD}" -f ${FILE} >> $LOG_FILE 2>&1
./ldapmodify -a -h ${DS_HOST} -p ${DS_PORT} -D "${DS_ADMIN_DN}" -w "${DS_DIRMGR_PASSWORD}" -f ${FILE}  >> $LOG_FILE 2>&1
cd ${curdir}

$RM -f $FILE

FILE="/tmp/upgradeNetlet.xml"
FILE1="/tmp/addDynamicNetletAttributeSchema.xml"
FILE2="/tmp/addUserNetletAttributeSchema.xml"

$CAT > $FILE1 <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright (c) 2003 Sun Microsystems. Inc. All rights reserved.
Use is subject to license terms.
-->
<!DOCTYPE Requests
PUBLIC "-//iPlanet/Sun ONE Identity Server 6.0 Admin CLI DTD//EN"
"jar://com/sun/identity/sm/sms.dtd"
>
<Requests>
<AttributeSchema name="sunPortalNetletLaunchMode"
  type="single_choice"
  syntax="string"
  any="adminDisplay|userReadOnly"
  cosQualifier="default"
  i18nKey="d14">
  <ChoiceValues>
  <ChoiceValue>Applet</ChoiceValue>
  <ChoiceValue>Java Web Start</ChoiceValue>
  </ChoiceValues>
  <DefaultValues>
  <Value>Applet</Value>
  </DefaultValues>
</AttributeSchema>
</Requests>
EOF

$CAT > $FILE2 <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright (c) 2003 Sun Microsystems. Inc. All rights reserved.
Use is subject to license terms.
-->
<!DOCTYPE Requests
PUBLIC "-//iPlanet/Sun ONE Identity Server 6.0 Admin CLI DTD//EN"
"jar://com/sun/identity/sm/sms.dtd"
>
<Requests>
<AttributeSchema name="sunPortalNetletLaunchMode"
  type="single_choice"
  syntax="string"
  any="adminDisplay|userReadOnly"
  cosQualifier="default"
  i18nKey="d14">
  <ChoiceValues>
  <ChoiceValue>Applet</ChoiceValue>
  <ChoiceValue>Java Web Start</ChoiceValue>
  </ChoiceValues>
  <DefaultValues>
  <Value>Applet</Value>
  </DefaultValues>
</AttributeSchema>
</Requests>
EOF

$CAT > $FILE <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright (c) 2003 Sun Microsystems. Inc. All rights reserved.
Use is subject to license terms.
-->
<!DOCTYPE Requests
PUBLIC "-//iPlanet/Sun ONE Identity Server 6.0 Admin CLI DTD//EN"
"jar://com/iplanet/am/admin/cli/amAdmin.dtd"
>

<Requests>
<!-- add new values -->
<SchemaRequests serviceName="srapNetletService"
  SchemaType="Dynamic">
  <AddAttributeSchema fileName="$FILE1"/>
</SchemaRequests>
<SchemaRequests serviceName="srapNetletService"
  SchemaType="User">
  <AddAttributeSchema fileName="$FILE2"/>
</SchemaRequests>
</Requests>
EOF


eval $AMADMIN -u \"$AM_ADMIN_DN\" -w "$IDSAME_ADMIN_PASSWORD" -v -t $FILE >> $LOG_FILE 2>&1

$RM -f $FILE $FILE1 $FILE3


# Upgrade the netlet resource file now

MODULE="Netlet"
LoadResourceBundle $MODULE

$ECHO "Done !"

##############################################################################################
# Begin Proxylet Upgrade
##############################################################################################

$ECHO "Upgrading Proxylet"
$ECHO "Upgrading Proxylet" >> $LOG_FILE

FILE="/tmp/srapProxylet.ldif"

# Upload the corresponding ldif file.
$CAT > $FILE <<EOF
#
# Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
# PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
#
dn: cn=schema
changetype:modify
add:attributeTypes
attributeTypes: ( sunPortalProxyletRules-oid NAME 'sunPortalProxyletRules' DESC 'SunOne Portal Proxylet Attribute' SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 X-ORIGIN 'SunOne Portal defined' )


dn: cn=schema
changetype:modify
add:objectClasses
objectClasses: ( sunPortalProxyletService-oid NAME 'sunPortalProxyletService' DESC 'SunOne Portal Proxylet Service' SUP top AUXILIARY MAY (sunPortalProxyletBindIP $ sunPortalProxyletPort $ sunPortalProxyletDownloadDefault $ sunPortalProxyletRules ) X-ORIGIN 'SunOne Portal defined' )
EOF

curDir=$PWD
cd $IDSAME_BASE_DIR/$IDSAME_PRODUCT_DIR/bin/
#./ldapmodify -a -h $DS_HOST -p $DS_PORT -D "$DS_ADMIN_DN" -w "$DS_DIRMGR_PASSWORD" -f $FILE >> $LOG_FILE 2>&1
./ldapmodify -a -h ${DS_HOST} -p ${DS_PORT} -D "${DS_ADMIN_DN}" -w "${DS_DIRMGR_PASSWORD}" -f ${FILE} >> $LOG_FILE 2>&1
cd $curDir

$RM -f $FILE

FILE="/tmp/upgradeProxylet.xml"
FILE1="/tmp/addDynamicProxyletAttributeSchema.xml"
FILE2="/tmp/addUserProxyletAttributeSchema.xml"

$CAT > $FILE <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright (c) 2003 Sun Microsystems. Inc. All rights reserved.
Use is subject to license terms.
-->
<!DOCTYPE Requests
PUBLIC "-//iPlanet/Sun ONE Identity Server 6.0 Admin CLI DTD//EN"
"jar://com/iplanet/am/admin/cli/amAdmin.dtd"
>

<Requests>
<SchemaRequests serviceName="srapProxyletService"
  SchemaType="Dynamic">
<RemoveAttributeSchema>
   <Attribute name ="sunPortalProxyletRules"/>
 </RemoveAttributeSchema>
</SchemaRequests>
</Requests>
EOF

eval $AMADMIN -u \"$AM_ADMIN_DN\" -w "$IDSAME_ADMIN_PASSWORD" -v -t $FILE >> $LOG_FILE 2>&1

$CAT > $FILE1 <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright (c) 2003 Sun Microsystems. Inc. All rights reserved.
Use is subject to license terms.
-->
<!DOCTYPE Requests
PUBLIC "-//iPlanet/Sun ONE Identity Server 6.0 Admin CLI DTD//EN"
"jar://com/sun/identity/sm/sms.dtd"
>
<Requests>
	<AttributeSchema name="sunPortalProxyletRules"
		type="single"
		syntax="string"
		uitype="link"
           propertiesViewBeanURL="${LOAD_BALANCER_URL}/proxyletadmin/ProxyletRulesReorder"
		any="adminDisplay|userReadOnly"
		cosQualifier="default"
		i18nKey="xProxylet3.rules">
		<DefaultValues>
		<Value>${PORTAL_SERVER_DOMAIN}:proxylethost:proxyletport</Value>
		</DefaultValues>
	</AttributeSchema>
</Requests>
EOF

$CAT > $FILE <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Copyright (c) 2003 Sun Microsystems. Inc. All rights reserved.
Use is subject to license terms.
-->
<!DOCTYPE Requests
PUBLIC "-//iPlanet/Sun ONE Identity Server 6.0 Admin CLI DTD//EN"
"jar://com/iplanet/am/admin/cli/amAdmin.dtd"
>

<Requests>
<!-- add new values -->
<SchemaRequests serviceName="srapProxyletService"
  SchemaType="Dynamic">
  <AddAttributeSchema fileName="$FILE1"/>
</SchemaRequests>
</Requests>
EOF

eval $AMADMIN -u \"$AM_ADMIN_DN\" -w "$IDSAME_ADMIN_PASSWORD" -v -t $FILE >> $LOG_FILE 2>&1

$RM -f $FILE $FILE1 $FILE3


# Upgrade the proxylet resource file now

MODULE="Proxylet"
LoadResourceBundle $MODULE

$ECHO "Done !"

###############################################################################
# Update Default Gateway Rule
###############################################################################

curDir=$PWD
cd ${PS_BASEDIR}/${PS_PRODUCT_DIR}/bin/

# Get the file using this command
./rwadmin get -r default_gateway_ruleset -u uid=amAdmin,$PEOPLE_DN  -w "$IDSAME_ADMIN_PASSWORD" > /tmp/DefaultGatewayRuleSet.xml
find /tmp -name "DefaultGatewayRuleSet.xml" -exec perl -pi -e 's/SServer.class/com\/sun\/portal\/netlet\/client\/applet\/NetletApplet\.class/g' {} \;
find /tmp -name "DefaultGatewayRuleSet.xml" -exec perl -pi -e 's/NetletEnvDetect.class/com\/sun\/portal\/netlet\/client\/applet\/NetletEnvDetect\.class/g' {} \;
# Deleting rule set
./rwadmin remove -u uid=amAdmin,$PEOPLE_DN  -w "$IDSAME_ADMIN_PASSWORD" -r default_gateway_ruleset

# Upload the file back using command
./rwadmin store -u uid=amAdmin,$PEOPLE_DN  -w "$IDSAME_ADMIN_PASSWORD"  /tmp/DefaultGatewayRuleSet.xml

# Upgrade the gateway resource file now

echo "Upgrading Gateway resource bundle"
MODULE="Gateway"
LoadResourceBundle $MODULE


###############################################
# Replace tokens in DesktopConfig properties file.

FILE=$PS_CONFIG_DIR/desktop/desktopconfig.properties
if [ "$OSTYPE" = "SunOS" ]; then
$INSTALLF "SUNWpsdt" $FILE
fi
$CP $FILE $FILE-tmp
$SED -e "s#%PS_BASEDIR%#$PS_BASEDIR#g" \
-e "s#%PS_PRODUCT_DIR%#$PS_PRODUCT_DIR#g" \
-e "s#%PS_CONFIG_DIR%#$PS_CONFIG_DIR#g" $FILE-tmp > $FILE
$RM -f $FILE-tmp
if [ "$OSTYPE" = "SunOS" ]; then
$INSTALLF -f "SUNWpsdt"
fi

###################################################################################
# Gateway fix
###################################################################################

FILE1="/tmp/unassignUserRole.xml"
$CAT > $FILE1 <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Requests SYSTEM
"jar://com/iplanet/am/admin/cli/amAdmin.dtd">
<!-- Unassigning Deny Write Access Role for the User amService-srapGateway --> 
<Requests>
<RoleRequests DN="cn=Deny Write Access,$ORG_DN">
<RemoveUsers>
  <DN>$USER_NAMING_ATTR=amService-srapGateway,$PEOPLE_DN</DN>
</RemoveUsers>
</RoleRequests>
</Requests>
EOF
eval $AMADMIN -u \"$AM_ADMIN_DN\" -w "$IDSAME_ADMIN_PASSWORD" -v -t $FILE1 >> $LOG_FILE 2>&1
rm $FILE1




FILE2="/tmp/deleteGWUser.xml"
$CAT > $FILE2 <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Requests SYSTEM
"jar://com/iplanet/am/admin/cli/amAdmin.dtd">
<!-- Delete gateway logging user -->
<Requests>
<PeopleContainerRequests DN="$PEOPLE_DN">
<DeleteUsers>
  <DN>$USER_NAMING_ATTR=amService-srapGateway,$PEOPLE_DN</DN>
</DeleteUsers>
</PeopleContainerRequests>
</Requests>
EOF

eval $AMADMIN -u \"$AM_ADMIN_DN\" -w "$IDSAME_ADMIN_PASSWORD" -v -t $FILE2 >> $LOG_FILE 2>&1
rm $FILE2




if [ "$AM_VERSION" = "6.3" ]; then
FILE3="/tmp/createAgent.xml"
$CAT > $FILE3 <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Requests
PUBLIC "-//iPlanet//iDSAME 5.0 Admin CLI DTD//EN"
"jar://com/iplanet/am/admin/cli/amAdmin.dtd"
>
<!-- create Agent amService-srapGateway for logging -->
<Requests>
<OrganizationRequests DN="$ORG_DN">
<CreateEntity createDN="amService-srapGateway" entityType="agent">
<AttributeValuePair>
<Attribute name="userpassword"/>
<Value>$SRA_LOG_USER_PASSWORD</Value>
</AttributeValuePair>
<AttributeValuePair>
<Attribute name="sunIdentityServerDeviceStatus"/>
<Value>Active</Value>
</AttributeValuePair>
</CreateEntity>
</OrganizationRequests>
</Requests>
EOF
fi

if [ "$AM_VERSION" = "6.2" ]; then
FILE3="/tmp/createAgent.xml"
$CAT > $FILE3 <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Requests
PUBLIC "-//iPlanet//iDSAME 5.0 Admin CLI DTD//EN"
"jar://com/iplanet/am/admin/cli/amAdmin.dtd"
>
<Requests>
<OrganizationRequests DN="$ORG_DN">
<CreateAgent createDN="amService-srapGateway" >
<AttributeValuePair>
<Attribute name="userpassword"/>
<Value>$SRA_LOG_USER_PASSWORD</Value>
</AttributeValuePair>
<AttributeValuePair>
<Attribute name="sunIdentityServerDeviceStatus"/>
<Value>Active</Value>
</AttributeValuePair>
</CreateAgent>
</OrganizationRequests>
</Requests>
EOF

#Following step modifies the SRA log password for gateway.
#This step is added as previous upgrade script use to add
#a hardcoded password. BugId: 6192579
FILE4="/tmp/modifyAgent.xml"
$CAT > $FILE4 <<EOF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Requests
PUBLIC "-//iPlanet//iDSAME 5.0 Admin CLI DTD//EN"
"jar://com/iplanet/am/admin/cli/amAdmin.dtd"
>
<Requests>
<OrganizationRequests DN="$ORG_DN">
<ModifyAgent modifyDN="uid=amService-srapGateway,ou=Agents,$ORG_DN" >
<AttributeValuePair>
<Attribute name="userpassword"/>
<Value>$SRA_LOG_USER_PASSWORD</Value>
</AttributeValuePair>
</ModifyAgent>
</OrganizationRequests>

</Requests>
EOF
fi

eval $AMADMIN -u \"$AM_ADMIN_DN\" -w "$IDSAME_ADMIN_PASSWORD" -v -t $FILE3 >> $LOG_FILE 2>&1

eval $AMADMIN -u \"$AM_ADMIN_DN\" -w "$IDSAME_ADMIN_PASSWORD" -v -t $FILE4 >> $LOG_FILE 2>&1
rm $FILE3  $FILE4


##############################################################
# Adding jnlpclient.jar & netletjsse.jar in non auth- URL 
##############################################################
FILE1=/tmp/gatewayInstancesDN.ldif
FILE2=/tmp/upgradeGatewayInstances.ldif
FILE3=/tmp/instances.ldif
echo "Getting profile DN for GW ... "

curdir=$PWD
cd ${IDSAME_BASE_DIR}/${IDSAME_PRODUCT_DIR}/bin/

./ldapsearch -h ${DS_HOST}  -D "${DS_ADMIN_DN}" -w "${DS_DIRMGR_PASSWORD}"  -b "${ORG_DN}" -T -1 "(&(entrydn=*,ou=Gateway-Profiles,ou=default,ou=GlobalConfig,ou=1.0,ou=srapGatewayService,ou=services,*)(sunkeyvalue=*))" dn > $FILE1


while read GWProfileDN
do
  if [ "$GWProfileDN" != "" ]; then

    GWProfileDN=`echo $GWProfileDN | sed -e "s/^dn: //"`

    ./ldapsearch -h ${DS_HOST} -D "${DS_ADMIN_DN}" -w "${DS_DIRMGR_PASSWORD}"  -b "${ORG_DN}" -T -1 "(&(entrydn=$GWProfileDN)(sunkeyvalue=*))" |
grep "^sunkeyvalue" > $FILE2

    echo "Modifying values now ...."

#Append the new values.
$CAT > $FILE3<<EOF
dn: $GWProfileDN
changetype:modify
replace: sunkeyvalue
sunkeyvalue: sunPortalGatewayNonAuthenticatedURLPath=/portal/netlet/jnlpclient.jar
sunkeyvalue: sunPortalGatewayNonAuthenticatedURLPath=/portal/netlet/netletjsse.jar
EOF

$CAT $FILE3 $FILE2 > $FILE2-tmp
$MV $FILE2-tmp $FILE2

     ./ldapmodify -a -h  ${DS_HOST} -D "${DS_ADMIN_DN}" -w "${DS_DIRMGR_PASSWORD}"  -f $FILE2

  fi
done <$FILE1
$RM $FILE1 $FILE2 $FILE3 
cd $curdir

}

################################################################
# Get the Gateway profile name from GWConfig state file.
################################################################

GetGatewayProfileName() {

    GrabConfig "GW_GATEWAY_PROFILE" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        GW_GATEWAY_PROFILE=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine GW_GATEWAY_PROFILE. $BELL_CHAR"
        exit 1
    fi

}


################################################################
# Read all the configuration informations
################################################################

GetGWConfigInfo() {

    # JDK base directory
    GrabConfig "com.iplanet.am.jdk.path" "$IS_CONFIG_FILE" "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        JDK_DIR=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine JDK_DIR. $BELL_CHAR"
        exit 1
    fi

    # Gateway base directory
    GrabConfig "GW_BASEDIR" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        GW_BASEDIR=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine GW_BASEDIR. $BELL_CHAR"
        exit 1
    fi

    # Gateway protocol
    GrabConfig "GW_PROTOCOL" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        GW_PROTOCOL=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine GW_PROTOCOL. $BELL_CHAR"
        exit 1
    fi

    # Gateway host
    GrabConfig "GW_HOST" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        GW_HOST=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine GW_HOST. $BELL_CHAR"
        exit 1
    fi

    # Gateway port
    GrabConfig "GW_PORT" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        GW_PORT=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine GW_PORT. $BELL_CHAR"
        exit 1
    fi

    # Gateway IP address
    GrabConfig "GW_IP" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        GW_IP=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine GW_IP. $BELL_CHAR"
        exit 1
    fi

    # Create self signed certficate ?
    GrabConfig "SELF_SIGNED_CERT" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SELF_SIGNED_CERT=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SELF_SIGNED_CERT. $BELL_CHAR"
        exit 1
    fi

    # Certificate information
    if [ "$SELF_SIGNED_CERT" = "y" ]; then
        GrabConfig "CERT_INFO" $GW_STATE_FILE "="
        if [ "$ANSWER_CONFIG" != "" ]; then
            CERT_INFO=$ANSWER_CONFIG
        else
            $ECHO "Error: Cannot determine CERT_INFO. $BELL_CHAR"
            exit 1
        fi
    fi

    # Start gateway after installation ?
    GrabConfig "START_GATEWAY" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        START_GATEWAY=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine START_GATEWAY. $BELL_CHAR"
        exit 1
    fi

    # Identity server protocol
    GrabConfig "SERVER_PROTOCOL" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SERVER_PROTOCOL=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SERVER_PROTOCOL. $BELL_CHAR"
        exit 1
    fi
    # Identity server host
    GrabConfig "SERVER_HOST" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SERVER_HOST=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SERVER_HOST. $BELL_CHAR"
        exit 1
    fi

    # Identity server port
    GrabConfig "SERVER_PORT" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SERVER_PORT=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SERVER_PORT. $BELL_CHAR"
        exit 1
    fi

    # Portal server load balancer URL.
    GrabConfig "LOAD_BALANCER_URL" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        PS_LB_URL=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine LOAD_BALANCER_URL. $BELL_CHAR"
        exit 1
    fi

    # Derive PS_PROTOCOL, PS_HOST, PS_PORT, PS_URL and DEPLOY_URI from PS_LB_URL.
    PS_PROTOCOL=`echo $PS_LB_URL | awk '{ print substr($0, 0, index($0,":")-1) }'`

    TMP_STR=`echo $PS_LB_URL | awk '{ print substr($0, index($0,"/")+2) }'`
    DEPLOY_URI=`echo $TMP_STR | awk '{ print substr($0, index($0,"/")) }'`

    TMP_STR=`echo $TMP_STR | awk '{ print substr($0, 0, index($0,"/")-1) }'`
    PS_HOST=`echo $TMP_STR | awk '{ print substr($0, 0, index($0,":")-1) }'`

    if [ "$PS_HOST" == "" ]; then
      PS_HOST=$TMP_STR
      PS_PORT="80"
    else
      PS_PORT=`echo $TMP_STR | awk '{ print substr($0, index($0,":")+1) }'`
    fi

    PS_URL="$PS_PROTOCOL://$PS_HOST:$PS_PORT"

    # Identity server/SDK base directory
    GrabConfig "IDSAME_BASEDIR" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        IS_BASEDIR=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine IDSAME_BASEDIR. $BELL_CHAR"
        exit 1
    fi

    # Create IS instance ?
    GrabConfig "CREATE_IS_INSTANCE" $GW_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        CREATE_IS_INSTANCE=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine CREATE_IS_INSTANCE. $BELL_CHAR"
        exit 1
    fi

}

################################################################
# Initializes some of the GW required variables
################################################################

InitializeGWOther() {

    BIN_DIR=$GW_BASEDIR/$PS_PRODUCT_DIR/bin
    LIB_DIR=$GW_BASEDIR/$PS_PRODUCT_DIR/lib
    PLATFORM_CONF=$PS_CONFIG_DIR/platform.conf.$GW_GATEWAY_PROFILE
    echo "Platform Conf = $PLATFORM_CONF"

    CERT_DIR=$PS_CONFIG_DIR/cert/$GW_GATEWAY_PROFILE
    KEY3_DB_FILE="$CERT_DIR/key3.db"
    CERT7_DB_FILE="$CERT_DIR/cert7.db"
    SECMOD_DB_FILE="$CERT_DIR/secmod.db"
    NICKNAME="server-cert"

    SERVER_URL=$SERVER_PROTOCOL://$SERVER_HOST:$SERVER_PORT
    GW_VIRTUAL_HOST="$GW_HOST $GW_IP"
    SSL_CONNECTION="true"
}


############################################################
#Replace the tokens in specified files
################################################################

ReplaceGWTokens() {

    FILES=$*
    for FILE in $FILES; do
        if [ "$OSTYPE" = "SunOS" ]; then
          $INSTALLF "SUNWpsgw" $FILE
        fi
        $CP -p $FILE $FILE-tmp
        $SED -e "s#\${BASE_DIR}#$GW_BASEDIR#g" \
             -e "s#\${IDSAME_BASE_DIR}#$IS_BASEDIR#g" \
             -e "s#\${PRODUCT_DIR}#$PS_PRODUCT_DIR#g" \
             -e "s#\${PS_VAR_DIR}#$PS_VAR_DIR#g" \
             -e "s#\${JAVA_BASE_DIR}#$JDK_DIR#g" \
             -e "s#SERVER_PROTO#$PS_PROTOCOL#g" \
             -e "s#SERVER_HOST#$PS_HOST#g" \
             -e "s#SERVER_PORT#$PS_PORT#g" \
             -e "s#SERVER_URL#$PS_URL#g" \
             -e "s#GW_HOST#$GW_HOST#g" \
             -e "s#GATEWAY_IPADDR#$GW_IP#g" \
             -e "s#GW_PORT#$GW_PORT#g" \
             -e "s#GW_PROTOCOL#$GW_PROTOCOL#g" \
             -e "s#GW_VIRTUAL_HOST#$GW_VIRTUAL_HOST#g" \
             -e "s#DEPLOY_URI#$DEPLOY_URI#g" \
             -e "s#SSL_CONNECTION#$SSL_CONNECTION#g" \
             -e "s#CERT_DB_DIR#$CERT_DIR#g" \
             -e "s#WEBSERVER_HOST#$SERVER_HOST#g" \
        $FILE-tmp > $FILE
        $RM -f $FILE-tmp
    done
    if [ "$OSTYPE" = "SunOS" ]; then
      $INSTALLF -f "SUNWpsgw"
    fi

}


################################################################
# Replace Gateway configuration files Tokens
################################################################

ReplaceGatewayFilesTokens() {

    FILES="$BIN_DIR/gateway $BIN_DIR/certadmin $BIN_DIR/checkgw $PLATFORM_CONF /etc/init.d/gateway $BIN_DIR/chroot/mkchroot $BIN_DIR/changepasswd"
    ReplaceGWTokens $FILES

}

###################################################################################
# Upgrade Gateway
###################################################################################
UpgradeGateway(){

# Get GW Profile name
GetGatewayProfileName

# Read the required informations from GWConfig state file
GetGWConfigInfo

# Initialize the other variables
InitializeGWOther

# Replace Gateway scripts Tokens
ReplaceGatewayFilesTokens

if [ ! "$AM_VERSION" = "6.3" ]; then
#Append the jss3.jar in JSS_JAR path
FILE=$GW_BASEDIR/$PS_PRODUCT_DIR/bin/gateway
$CP $FILE $FILE-tmp
$SED -e 's#JSS_JAR=$JSS_JAR_LIB_DIR/jss4.jar#JSS_JAR=$JSS_JAR_LIB_DIR/jss4.jar:$JSS_JAR_LIB_DIR/jss3.jar#g'  $FILE-tmp > $FILE
$RM -f $FILE-tmp
fi
}

################################################################
# Get the Gateway profile name from RWPConfig state file.
################################################################
GetRewriterProfileName() {

    GrabConfig "RWP_GATEWAY_PROFILE" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        RWP_GATEWAY_PROFILE=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine RWP_GATEWAY_PROFILE. $BELL_CHAR"
        exit 1
    fi

}


################################################################
# Update the state file pointer to point to current state file.
################################################################

UpdateRWPStateFilePointer() {

    NEW_RWP_STATE_FILE="$PS_CONFIG_DIR/RWPConfig-$RWP_GATEWAY_PROFILE.properties"
    RWP_STATE_FILE=$NEW_RWP_STATE_FILE

}

################################################################
# Read all the configuration informations
################################################################
GetRWPConfigInfo() {
  
    # JDK base directory
    GrabConfig "com.iplanet.am.jdk.path" "$IS_CONFIG_FILE" "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        JDK_DIR=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine JDK_DIR. $BELL_CHAR"
        exit 1
    fi

    # Rewriter proxy base directory
    GrabConfig "RWP_BASEDIR" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        RWP_BASEDIR=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine RWP_BASEDIR. $BELL_CHAR"
        exit 1
    fi

    # Rewriter proxy protocol
    GrabConfig "RWP_PROTOCOL" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        RWP_PROTOCOL=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine RWP_PROTOCOL. $BELL_CHAR"
        exit 1
    fi

    # Rewriter proxy host
    GrabConfig "RWP_HOST" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        RWP_HOST=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine RWP_HOST. $BELL_CHAR"
        exit 1
    fi

    # Rewriter proxy port
    GrabConfig "RWP_PORT" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        RWP_PORT=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine RWP_PORT. $BELL_CHAR"
        exit 1
    fi

    # Rewriter proxy IP address
    GrabConfig "RWP_IP" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        RWP_IP=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine RWP_IP. $BELL_CHAR"
        exit 1
    fi

    # Create self signed certficate ?
    GrabConfig "SELF_SIGNED_CERT" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SELF_SIGNED_CERT=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SELF_SIGNED_CERT. $BELL_CHAR"
        exit 1
    fi

    # Certificate information
    if [ "$SELF_SIGNED_CERT" = "y" ]; then
        GrabConfig "CERT_INFO" $RWP_STATE_FILE "="
        if [ "$ANSWER_CONFIG" != "" ]; then
            CERT_INFO=$ANSWER_CONFIG
        else
            $ECHO "Error: Cannot determine CERT_INFO. $BELL_CHAR"
            exit 1
        fi
    fi

    # Start rewriter proxy after installation ?
    GrabConfig "START_REWRITERPROXY" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        START_REWRITERPROXY=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine START_REWRITERPROXY. $BELL_CHAR"
        exit 1
    fi

    # Identity server protocol
    GrabConfig "SERVER_PROTOCOL" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SERVER_PROTOCOL=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SERVER_PROTOCOL. $BELL_CHAR"
        exit 1
    fi

    # Identity server host
    GrabConfig "SERVER_HOST" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SERVER_HOST=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SERVER_HOST. $BELL_CHAR"
        exit 1
    fi

    # Identity server port
    GrabConfig "SERVER_PORT" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SERVER_PORT=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SERVER_PORT. $BELL_CHAR"
        exit 1
    fi

    # Portal server load balancer URL.
    GrabConfig "LOAD_BALANCER_URL" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        PS_LB_URL=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine LOAD_BALANCER_URL. $BELL_CHAR"
        exit 1
    fi

    # Derive PS_PROTOCOL, PS_HOST, PS_PORT, PS_URL and DEPLOY_URI from PS_LB_URL.
    PS_PROTOCOL=`echo $PS_LB_URL | awk '{ print substr($0, 0, index($0,":")-1) }'`

    TMP_STR=`echo $PS_LB_URL | awk '{ print substr($0, index($0,"/")+2) }'`
    DEPLOY_URI=`echo $TMP_STR | awk '{ print substr($0, index($0,"/")) }'`

    TMP_STR=`echo $TMP_STR | awk '{ print substr($0, 0, index($0,"/")-1) }'`
    PS_HOST=`echo $TMP_STR | awk '{ print substr($0, 0, index($0,":")-1) }'`

    if [ "$PS_HOST" == "" ]; then
      PS_HOST=$TMP_STR
      PS_PORT="80"
    else
      PS_PORT=`echo $TMP_STR | awk '{ print substr($0, index($0,":")+1) }'`
    fi
    PS_URL="$PS_PROTOCOL://$PS_HOST:$PS_PORT"

    # Identity server/SDK base directory
    GrabConfig "IDSAME_BASEDIR" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        IS_BASEDIR=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine IDSAME_BASEDIR. $BELL_CHAR"
        exit 1
    fi
  # Create IS instance ?
    GrabConfig "CREATE_IS_INSTANCE" $RWP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        CREATE_IS_INSTANCE=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine CREATE_IS_INSTANCE. $BELL_CHAR"
        exit 1
    fi

}

################################################################
# Initializes some of the required variables
################################################################

InitializeRWPOther() {

    BIN_DIR=$RWP_BASEDIR/$PS_PRODUCT_DIR/bin
    LIB_DIR=$RWP_BASEDIR/$PS_PRODUCT_DIR/lib
    PLATFORM_CONF=$PS_CONFIG_DIR/platform.conf.$RWP_GATEWAY_PROFILE

    CERT_DIR=$PS_CONFIG_DIR/cert/$RWP_GATEWAY_PROFILE
    KEY3_DB_FILE="$CERT_DIR/key3.db"
    CERT7_DB_FILE="$CERT_DIR/cert7.db"
    SECMOD_DB_FILE="$CERT_DIR/secmod.db"
    NICKNAME="server-cert"

    SERVER_URL=$SERVER_PROTOCOL://$SERVER_HOST:$SERVER_PORT
    GW_VIRTUAL_HOST="$RWP_HOST $RWP_IP"
    SSL_CONNECTION="true"
}

################################################################
# Replace the tokens in specified files
################################################################
ReplaceRWPTokens() {

    FILES=$*
    for FILE in $FILES; do
        if [ "$OSTYPE" = "SunOS" ]; then
          $INSTALLF "SUNWpsrwp" $FILE
        fi
        $CP -p $FILE $FILE-tmp
        $SED -e "s#\${BASE_DIR}#$RWP_BASEDIR#g" \
             -e "s#\${IDSAME_BASE_DIR}#$IS_BASEDIR#g" \
             -e "s#\${PRODUCT_DIR}#$PS_PRODUCT_DIR#g" \
             -e "s#\${JAVA_BASE_DIR}#$JDK_DIR#g" \
             -e "s#SERVER_PROTO#$PS_PROTOCOL#g" \
             -e "s#SERVER_HOST#$PS_HOST#g" \
             -e "s#SERVER_PORT#$PS_PORT#g" \
             -e "s#SERVER_URL#$PS_URL#g" \
             -e "s#GW_HOST#$RWP_HOST#g" \
             -e "s#GATEWAY_IPADDR#$RWP_IP#g" \
             -e "s#GW_PORT#$RWP_PORT#g" \
             -e "s#GW_PROTOCOL#$RWP_PROTOCOL#g" \
             -e "s#GW_VIRTUAL_HOST#$RWP_VIRTUAL_HOST#g" \
             -e "s#DEPLOY_URI#$DEPLOY_URI#g" \
             -e "s#SSL_CONNECTION#$SSL_CONNECTION#g" \
             -e "s#CERT_DB_DIR#$CERT_DIR#g" \
             -e "s#WEBSERVER_HOST#$SERVER_HOST#g" \
        $FILE-tmp > $FILE
        $RM -f $FILE-tmp
    done
    if [ "$OSTYPE" = "SunOS" ]; then
      $INSTALLF -f "SUNWpsrwp"
    fi

}

################################################################
# Replace Rewriter Proxy configuration files Tokens
################################################################

ReplaceRewriterProxyFilesTokens(){
    FILES="$BIN_DIR/rwproxyd $BIN_DIR/certadmin $BIN_DIR/checkrp /etc/init.d/rwproxyd $BIN_DIR/chroot/mkchroot"
    ReplaceRWPTokens $FILES
}

###############################################
# Upgrade RewriterProxy
###############################################
UpgradeRewriterProxy(){

#Get RW Profile name
GetRewriterProfileName

# Update RWP_STATE_FILE variable to point to correct state file.
UpdateRWPStateFilePointer

# Read the required informations from RWPConfig state file
GetRWPConfigInfo

# Initialize the other variables
InitializeRWPOther

# Replace Rewriter Proxy scripts tokens
ReplaceRewriterProxyFilesTokens
}


################################################################
# Get the Gateway profile name from NLPConfig state file.
################################################################
GetNetletProfileName() {

    GrabConfig "NLP_GATEWAY_PROFILE" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        NLP_GATEWAY_PROFILE=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine NLP_GATEWAY_PROFILE. $BELL_CHAR"
        exit 1
    fi

}


################################################################
# Update the state file pointer to point to current state file.
################################################################

UpdateNLPStateFilePointer() {

    NEW_NLP_STATE_FILE="$PS_CONFIG_DIR/NLPConfig-$NLP_GATEWAY_PROFILE.properties"
    NLP_STATE_FILE=$NEW_NLP_STATE_FILE

}

################################################################
# Exit if NLPConfig state file in not present
################################################################

CheckNLPStateFile() {

    if [ ! -f $NLP_STATE_FILE ]; then
        $ECHO "Error: $NLP_STATE_FILE does not exist. $BELL_CHAR"
        exit 1
    fi

}

################################################################
# Read all the configuration informations
################################################################
GetNLPConfigInfo() {

    # JDK base directory
    GrabConfig "com.iplanet.am.jdk.path" "$IS_CONFIG_FILE" "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        JDK_DIR=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine JDK_DIR. $BELL_CHAR"
        exit 1
    fi

    # Netlet proxy base directory
    GrabConfig "NLP_BASEDIR" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        NLP_BASEDIR=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine NLP_BASEDIR. $BELL_CHAR"
        exit 1
    fi

    # Netlet proxy protocol
    GrabConfig "NLP_PROTOCOL" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        NLP_PROTOCOL=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine NLP_PROTOCOL. $BELL_CHAR"
        exit 1
    fi

    # Netlet proxy host
    GrabConfig "NLP_HOST" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        NLP_HOST=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine NLP_HOST. $BELL_CHAR"
        exit 1
    fi

    # Netlet proxy port
    GrabConfig "NLP_PORT" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        NLP_PORT=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine NLP_PORT. $BELL_CHAR"
        exit 1
    fi

    # Netlet proxy IP address
    GrabConfig "NLP_IP" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        NLP_IP=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine NLP_IP. $BELL_CHAR"
        exit 1
    fi

  # Create self signed certficate ?
    GrabConfig "SELF_SIGNED_CERT" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SELF_SIGNED_CERT=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SELF_SIGNED_CERT. $BELL_CHAR"
        exit 1
    fi

    # Certificate information
    if [ "$SELF_SIGNED_CERT" = "y" ]; then
        GrabConfig "CERT_INFO" $NLP_STATE_FILE "="
        if [ "$ANSWER_CONFIG" != "" ]; then
            CERT_INFO=$ANSWER_CONFIG
        else
            $ECHO "Error: Cannot determine CERT_INFO. $BELL_CHAR"
            exit 1
        fi
    fi

    # Start netlet proxy after installation ?
    GrabConfig "START_NETLETPROXY" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        START_NETLETPROXY=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine START_NETLETPROXY. $BELL_CHAR"
        exit 1
    fi

    # Portal server protocol
    GrabConfig "SERVER_PROTOCOL" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SERVER_PROTOCOL=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SERVER_PROTOCOL. $BELL_CHAR"
        exit 1
    fi

    # Portal server host
    GrabConfig "SERVER_HOST" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SERVER_HOST=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SERVER_HOST. $BELL_CHAR"
        exit 1
    fi

    # Portal server port
    GrabConfig "SERVER_PORT" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SERVER_PORT=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SERVER_PORT. $BELL_CHAR"
        exit 1
    fi

   # Portal server port
    GrabConfig "SERVER_PORT" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        SERVER_PORT=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine SERVER_PORT. $BELL_CHAR"
        exit 1
    fi

    # Portal server load balancer URL.
    GrabConfig "LOAD_BALANCER_URL" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        PS_LB_URL=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine LOAD_BALANCER_URL. $BELL_CHAR"
        exit 1
    fi

    # Derive PS_PROTOCOL, PS_HOST, PS_PORT, PS_URL and DEPLOY_URI from PS_LB_URL.
    PS_PROTOCOL=`echo $PS_LB_URL | awk '{ print substr($0, 0, index($0,":")-1) }'`

    TMP_STR=`echo $PS_LB_URL | awk '{ print substr($0, index($0,"/")+2) }'`
    DEPLOY_URI=`echo $TMP_STR | awk '{ print substr($0, index($0,"/")) }'`

    TMP_STR=`echo $TMP_STR | awk '{ print substr($0, 0, index($0,"/")-1) }'`
    PS_HOST=`echo $TMP_STR | awk '{ print substr($0, 0, index($0,":")-1) }'`

    if [ "$PS_HOST" == "" ]; then
      PS_HOST=$TMP_STR
      PS_PORT="80"
    else
      PS_PORT=`echo $TMP_STR | awk '{ print substr($0, index($0,":")+1) }'`
    fi

    PS_URL="$PS_PROTOCOL://$PS_HOST:$PS_PORT"

    # Identity server/SDK base directory
    GrabConfig "IDSAME_BASEDIR" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        IS_BASEDIR=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine IDSAME_BASEDIR. $BELL_CHAR"
        exit 1
    fi

    # Create IS instance ?
    GrabConfig "CREATE_IS_INSTANCE" $NLP_STATE_FILE "="
    if [ "$ANSWER_CONFIG" != "" ]; then
        CREATE_IS_INSTANCE=$ANSWER_CONFIG
    else
        $ECHO "Error: Cannot determine CREATE_IS_INSTANCE. $BELL_CHAR"
        exit 1
    fi

}

################################################################
# Initializes some of the required variables
################################################################

InitializeNLPOther() {

    BIN_DIR=$NLP_BASEDIR/$PS_PRODUCT_DIR/bin
    LIB_DIR=$NLP_BASEDIR/$PS_PRODUCT_DIR/lib
    PLATFORM_CONF=$PS_CONFIG_DIR/platform.conf.$NLP_GATEWAY_PROFILE

    CERT_DIR=$PS_CONFIG_DIR/cert/$NLP_GATEWAY_PROFILE
    KEY3_DB_FILE="$CERT_DIR/key3.db"
    CERT7_DB_FILE="$CERT_DIR/cert7.db"
    SECMOD_DB_FILE="$CERT_DIR/secmod.db"
    NICKNAME="server-cert"

    SERVER_URL=$SERVER_PROTOCOL://$SERVER_HOST:$SERVER_PORT
    GW_VIRTUAL_HOST="$NLP_HOST $NLP_IP"
    SSL_CONNECTION="true"
}

################################################################
# Replace the tokens in specified files
################################################################
ReplaceNLPTokens() {

    FILES=$*
    for FILE in $FILES; do
        if [ "$OSTYPE" = "SunOS" ]; then
          $INSTALLF "SUNWpsnlp" $FILE
        fi
        $CP -p $FILE $FILE-tmp
        $SED -e "s#\${BASE_DIR}#$NLP_BASEDIR#g" \
             -e "s#\${IDSAME_BASE_DIR}#$IS_BASEDIR#g" \
             -e "s#\${PRODUCT_DIR}#$PS_PRODUCT_DIR#g" \
             -e "s#\${JAVA_BASE_DIR}#$JDK_DIR#g" \
             -e "s#SERVER_PROTO#$PS_PROTOCOL#g" \
             -e "s#SERVER_HOST#$PS_HOST#g" \
             -e "s#SERVER_PORT#$PS_PORT#g" \
             -e "s#SERVER_URL#$PS_URL#g" \
             -e "s#GW_HOST#$NLP_HOST#g" \
             -e "s#GATEWAY_IPADDR#$NLP_IP#g" \
             -e "s#GW_PORT#$NLP_PORT#g" \
             -e "s#GW_PROTOCOL#$NLP_PROTOCOL#g" \
             -e "s#GW_VIRTUAL_HOST#$NLP_VIRTUAL_HOST#g" \
             -e "s#DEPLOY_URI#$DEPLOY_URI#g" \
             -e "s#SSL_CONNECTION#$SSL_CONNECTION#g" \
             -e "s#CERT_DB_DIR#$CERT_DIR#g" \
             -e "s#WEBSERVER_HOST#$SERVER_HOST#g" \
        $FILE-tmp > $FILE
        $RM -f $FILE-tmp
    done
    if [ "$OSTYPE" = "SunOS" ]; then
      $INSTALLF -f "SUNWpsnlp"
    fi

}

################################################################
# Replace Netlet configuration files Tokens
################################################################
ReplaceNetletProxyFilesTokens() {
    FILES="$BIN_DIR/netletd $BIN_DIR/certadmin $BIN_DIR/checknetletd /etc/init.d/netletd $BIN_DIR/changepasswd"
    ReplaceNLPTokens $FILES
}


##############################################
# Upgrade Netlet Proxy
##############################################
UpgradeNetletProxy() {

#Set NetletProxy Profile name
GetNetletProfileName

# Update NLP_STATE_FILE variable to point to correct state file.
UpdateNLPStateFilePointer

# Make sure the NLPConfig state file is present
CheckNLPStateFile

# Read the required informations from NLPConfig state file
GetNLPConfigInfo

# Initialize the other variables
InitializeNLPOther

# Replace Netlet Proxy scripts Tokens
ReplaceNetletProxyFilesTokens

#Append jss3.jar in JSS_JAR path incase IS is older than 6.3
if [ ! "$AM_VERSION" = "6.3" ]; then
FILE=$NLP_BASEDIR/$PS_PRODUCT_DIR/bin/netletd
$CP $FILE $FILE-tmp
$SED -e 's#JSS_JAR=$JSS_JAR_LIB_DIR/jss4.jar#JSS_JAR=$JSS_JAR_LIB_DIR/jss4.jar:$JSS_JAR_LIB_DIR/jss3.jar#g'  $FILE-tmp > $FILE
$RM -f $FILE-tmp
fi

}

################################################################
# Exit if non root user is executing this script
################################################################

CheckUser() {

    if [ `$ID | $AWK '{print $1}'` != "uid=0(root)" ]; then
        $ECHO "You must be root user. $BELL_CHAR"
        exit 1
    fi

}


###############################################
# Main
###############################################

GW_STATE_FILE="$PS_CONFIG_DIR/GWConfig.properties"
NLP_STATE_FILE="$PS_CONFIG_DIR/NLPConfig.properties"
RWP_STATE_FILE="$PS_CONFIG_DIR/RWPConfig.properties"

IS_CONFIG_FILE="$IDSAME_CONFIG_DIR/config/AMConfig.properties"

LOG_DIR="/var/opt/sun/portal/tmp/"
LOG_FILE="$LOG_DIR/upgradeSRAJ3.log"
LOG_FILE="/tmp/upgradeSRAJ3.log"

BELL_CHAR='\a'

amconfig_props="$IDSAME_CONFIG_DIR/config/AMConfig.properties"
GrabConfig "com.iplanet.am.version" $amconfig_props "="
AM_VERSION=$ANSWER_CONFIG

GrabConfig "com.sun.identity.authentication.super.user" $amconfig_props "="
USER_NAMING_ATTR=`$ECHO $ANSWER_CONFIG | $CUT -f1 -d =`

# Make sure root is executing this script.
CheckUser

GrabConfig "com.iplanet.am.server.protocol" $amconfig_props "="
IS_SERVER_PROTOCOL=$ANSWER_CONFIG

GrabConfig "com.iplanet.am.server.host" $amconfig_props "="
IS_SERVER_HOST=$ANSWER_CONFIG

GrabConfig "com.iplanet.am.server.port" $amconfig_props "="
IS_SERVER_PORT=$ANSWER_CONFIG

AM_ADMIN_DN="amadmin"

GrabConfig "com.iplanet.am.rootsuffix" $amconfig_props "="
DS_BIND_DN=$ANSWER_CONFIG

AMADMIN=$IDSAME_BASE_DIR/$IDSAME_PRODUCT_DIR/bin/amadmin
DPADMIN=$PS_BASEDIR/$PS_PRODUCT_DIR/bin/dpadmin

echo $LD_LIBRARY_PATH

IS_AMSERVER_URL="$IS_SERVER_PROTOCOL://$IS_SERVER_HOST:$IS_SERVER_PORT$AMSERVER_DEPLOY_URI"
IS_AMCONSOLE_URL="$IS_SERVER_PROTOCOL://$IS_SERVER_HOST:$IS_SERVER_PORT$AMCONSOLE_DEPLOY_URI"

  if [ "$OSTYPE" = "SunOS" ]; then
    SRA_PKGINFO_FILE="/var/sadm/pkg/SUNWpsgws/pkginfo"
    GW_PKGINFO_FILE="/var/sadm/pkg/SUNWpsgw/pkginfo"
    NLP_PKGINFO_FILE="/var/sadm/pkg/SUNWpsnlp/pkginfo"
    RWP_PKGINFO_FILE="/var/sadm/pkg/SUNWpsrwp/pkginfo"

       if [ -f $SRA_PKGINFO_FILE ]; then
       UpgradeSRACore
       echo "SRA upgraded"
       fi

      if [ -f $RWP_PKGINFO_FILE ]; then
       UpgradeRewriterProxy
       echo "RWP upgraded"
       fi

       if [ -f $GW_PKGINFO_FILE ]; then
        UpgradeGateway
        echo "Gateway upgraded"
       fi

       if [ -f $NLP_PKGINFO_FILE ]; then
           UpgradeNetletProxy
           echo "NLP upgraded"
       fi

fi
if [ "$OSTYPE" = "Linux" ]; then
       CONFIG_RPM="sun-portal-gatewayidentityagent"
       $RPM -q --quiet $CONFIG_RPM
       if [ $? -eq 0 ]; then
         UpgradeSRACore
         echo "SRA upgraded"
       fi

       CONFIG_RPM="sun-portal-rewriterproxy"
       $RPM -q --quiet $CONFIG_RPM
       if [ $? -eq 0 ]; then
        UpgradeRewriterProxy
        echo "RWP upgraded"
       fi


       CONFIG_RPM="sun-portal-gateway"
       $RPM -q --quiet $CONFIG_RPM
       if [ $? -eq 0 ]; then
        UpgradeGateway
        echo "Gateway upgraded"
       fi

       CONFIG_RPM="sun-portal-netletproxy"
       $RPM -q --quiet $CONFIG_RPM
       if [ $? -eq 0 ]; then
           UpgradeNetletProxy
           echo "NLP upgraded"
       fi

 fi

exit 0


