#!/bin/sh
#  $Id: preinstall.sh 144933 2017-02-08 09:50:25Z justin.carveley@oracle.com $
#  Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
#  This software code contains proprietary information 
#  and should be treated as confidential.
#
#  Component: Secure Global Desktop Gateway
#  Author: Bill Weir

if [ -f /tmp/pkgadd.debug ]; then
    echo "Debug Output On"
    echo "---------------"
    echo " "
    set
    set -x	
    trace=x export trace
fi

# This is a generic product script used to establish an environment
# before starting/stopping a product or component.
# This script was built from shell library
#   $Id$
# This script has to run on every platform we support.  Any suggestions
# for improvement are welcome (but must be portable!)

# Version numbers
PRODUCT_VERSION="5.60.514"
PRODUCT_VERSION_FULL="5.60.514"
PRODUCT_VERSION_MAJOR=5
PRODUCT_VERSION_FEATURE=6
PRODUCT_VERSION_BUG=0
PRODUCT_VERSION_BUILD=514
PRODUCT_VERSION_BUILD_DECIMAL=514
PRODUCT_VERSION_AS_NUMBER=560514
PRODUCT_VERSION_CAB=5,6,0,514
PRODUCT_VERSION_RPM=5.60-514

# Product names
PRODUCT_FULL_NAME="Oracle Secure Global Desktop"
PRODUCT_SHORT_NAME="Secure Global Desktop"
PRODUCT_IDENT="SSGD"
PRODUCT_SHORT_FILENAME="Tarantella"
PRODUCT_LSBSCRIPTNAME="sun.com-sgd-base"
PRODUCT_LSBSCRIPT_RUN_LEVEL="90"
TSP_FULL_NAME="Oracle Secure Global Desktop Security Pack"
TSP_SHORT_NAME="Security Pack"
WCP_FULL_NAME="Oracle Secure Global Desktop Windows Connectivity Pack"
WCP_SHORT_NAME="Windows Connectivity Pack"
TN3270_FULL_NAME="Oracle Secure Global Desktop Mainframe Connectivity Pack"
TN3270_SHORT_NAME="Mainframe Connectivity Pack"
AS400_FULL_NAME="Oracle Secure Global Desktop AS/400 Connectivity Pack"
AS400_SHORT_NAME="AS/400 Connectivity Pack"
S1PSTK_FULL_NAME="Oracle Secure Global Desktop Channel for Sun ONE Portal Server"
S1PSIP_FULL_NAME="Oracle Secure Global Desktop Integration Pack for Sun ONE Portal Server"
S1PSTK_SHORT_NAME="Secure Global Desktop Channel for Sun ONE Portal Server"
S1PSIP_SHORT_NAME="Secure Global Desktop Integration Pack for Sun ONE Portal Server"

OBJECT_MGR_NAME="Object Manager"
ARRAY_MGR_NAME="Array Manager"
NATIVE_WIN16_FULL_NAME="Oracle Secure Global Desktop Native Client for Windows 3.1"
NATIVE_WIN16_SHORT_NAME="Native Client for Windows 3.1"
NATIVE_WIN32_FULL_NAME="Oracle Secure Global Desktop Native Client for Windows 95, 98 and NT"
NATIVE_WIN32_SHORT_NAME="Native Client for Windows 95, 98 and NT"
NATIVE_WYSE_FULL_NAME="Oracle Secure Global Desktop Native Client for Wyse"
NATIVE_WYSE_SHORT_NAME="Native Client for Wyse"
NATIVE_FULL_NAME="Oracle Secure Global Desktop Native Client"
NATIVE_SHORT_NAME="Native Client"
NATIVE_REGISTRY_NAME="Tarantella Native Client"
INTCLI_FULL_NAME="Oracle Secure Global Desktop Client"
INTCLI_SHORT_NAME="Client"
TCC_FULL_NAME="Oracle Secure Global Desktop Client"
TCC_HELPER_NAME="Oracle Secure Global Desktop Client Helper"
TCC_ACTIVEX_NAME="Oracle Secure Global Desktop ActiveX Control"
TCC_PLUGIN_NAME="Oracle Secure Global Desktop Netscape Plug-in"
T3COMPONENT_WIN_NAME="Oracle Secure Global Desktop Enhancement Module for Windows"
T3COMPONENT_UNIX_NAME="Oracle Secure Global Desktop Enhancement Module for UNIX(TM) and Linux Platforms"
T3COMPONENT_SHORT_UNIX_NAME="tem"
T3COMPONENT_NAME="Oracle Secure Global Desktop Enhancement Module"
T3COMPONENT_LSBSCRIPTNAME="sun.com-sgd-em"
T3COMPONENT_LSBSCRIPT_RUN_LEVEL="90"
GWCOMPONENT_UNIX_NAME="Oracle Secure Global Desktop Gateway for UNIX(TM) and Linux Platforms"
GWCOMPONENT_NAME="Oracle Secure Global Desktop Gateway"
GWCOMPONENT_SHORTNAME="SGD Gateway"
GWCOMPONENT_LSBSCRIPTNAME="sun.com-sgd-gw"
GWCOMPONENT_LSBSCRIPT_RUN_LEVEL="91"

# Watch the length of these names: IE refuses to remove packages if
# the name is too long.
ARCHIVE_NAME_ttalw="TCC Helper, version"
ARCHIVE_NAME_asad="3.x Framework Java Archive"
#ARCHIVE_NAME_tta="3.x Java Archive"
#ARCHIVE_NAME_tta="3.x Combined Java Archive"
ARCHIVE_NAME_tta="Client, "
ARCHIVE_NAME_tsp="3.x Security Java Archive"
ARCHIVE_NAME_proxy="3.x Proxy Java Archive"
WEBSTART_JAR_NAME="sgdwscs"
ARCHIVE_SUFFIX="K"

NS_REGKEY="java/download/com/tarantella/tta"

PRODUCT_VENDOR="Oracle Corporation, Inc."
PRODUCT_SHORT_VENDOR="Oracle"

# Capabilities:
# The format for the capabilities required by the client end of a
# connection is: CAPABILITIES_protocol_type_REQUIRED="expression"

# The format for the capabilities provided by the server end of a
# connection is: CAPABILITIES_protocol_type_PROVIDED="c1 c2 ... c3"

# Asad between a webtop client and server:
CAPABILITIES_ASAD_WEBTOPCLIENT_REQUIRED="(1.1 || 1.2)"
CAPABILITIES_ASAD_WEBTOPCLIENT_PROVIDED="1.1 1.2"

# Asad between two peer servers, or an admin tool and a server:
# 1.1 is core E3 array functionality.
# 1.2 is 3.01 array interoperability functionality.
# 2.1 is core Pisa client device mapping functionality (not a requirement)
CAPABILITIES_ASAD_PEER_REQUIRED="(1.1 || 1.2)"
CAPABILITIES_ASAD_PEER_PROVIDED="1.1 1.2 2.1"

# Client versions of server strings; same format, name prefixed by CLIENT
# Asad between a webtop client and server:
CLIENTCAPABILITIES_ASAD_WEBTOPCLIENT_REQUIRED="(1.1 || 1.2)"
CLIENTCAPABILITIES_ASAD_WEBTOPCLIENT_PROVIDED="1.1 1.2"

# Top-level item names in ENS datastore
DEFAULT_ROOT_ENS="organization"
SYSTEM_ROOT_ENS="Tarantella System Objects"
APP_ROOT_ENS="applications"
APPSERVER_ROOT_ENS="appservers"

WEB_SERVICES_VERSION=1.9


#versioninfo
# Version numbers
PRODUCT_VERSION="5.60.514"
PRODUCT_VERSION_FULL="5.60.514"
PRODUCT_VERSION_MAJOR=5
PRODUCT_VERSION_FEATURE=6
PRODUCT_VERSION_BUG=0
PRODUCT_VERSION_BUILD=514
PRODUCT_VERSION_BUILD_DECIMAL=514
PRODUCT_VERSION_AS_NUMBER=560514
PRODUCT_VERSION_CAB=5,6,0,514
PRODUCT_VERSION_RPM=5.60-514

# Product names
PRODUCT_FULL_NAME="Oracle Secure Global Desktop"
PRODUCT_SHORT_NAME="Secure Global Desktop"
PRODUCT_IDENT="SSGD"
PRODUCT_SHORT_FILENAME="Tarantella"
PRODUCT_LSBSCRIPTNAME="sun.com-sgd-base"
PRODUCT_LSBSCRIPT_RUN_LEVEL="90"
TSP_FULL_NAME="Oracle Secure Global Desktop Security Pack"
TSP_SHORT_NAME="Security Pack"
WCP_FULL_NAME="Oracle Secure Global Desktop Windows Connectivity Pack"
WCP_SHORT_NAME="Windows Connectivity Pack"
TN3270_FULL_NAME="Oracle Secure Global Desktop Mainframe Connectivity Pack"
TN3270_SHORT_NAME="Mainframe Connectivity Pack"
AS400_FULL_NAME="Oracle Secure Global Desktop AS/400 Connectivity Pack"
AS400_SHORT_NAME="AS/400 Connectivity Pack"
S1PSTK_FULL_NAME="Oracle Secure Global Desktop Channel for Sun ONE Portal Server"
S1PSIP_FULL_NAME="Oracle Secure Global Desktop Integration Pack for Sun ONE Portal Server"
S1PSTK_SHORT_NAME="Secure Global Desktop Channel for Sun ONE Portal Server"
S1PSIP_SHORT_NAME="Secure Global Desktop Integration Pack for Sun ONE Portal Server"

OBJECT_MGR_NAME="Object Manager"
ARRAY_MGR_NAME="Array Manager"
NATIVE_WIN16_FULL_NAME="Oracle Secure Global Desktop Native Client for Windows 3.1"
NATIVE_WIN16_SHORT_NAME="Native Client for Windows 3.1"
NATIVE_WIN32_FULL_NAME="Oracle Secure Global Desktop Native Client for Windows 95, 98 and NT"
NATIVE_WIN32_SHORT_NAME="Native Client for Windows 95, 98 and NT"
NATIVE_WYSE_FULL_NAME="Oracle Secure Global Desktop Native Client for Wyse"
NATIVE_WYSE_SHORT_NAME="Native Client for Wyse"
NATIVE_FULL_NAME="Oracle Secure Global Desktop Native Client"
NATIVE_SHORT_NAME="Native Client"
NATIVE_REGISTRY_NAME="Tarantella Native Client"
INTCLI_FULL_NAME="Oracle Secure Global Desktop Client"
INTCLI_SHORT_NAME="Client"
TCC_FULL_NAME="Oracle Secure Global Desktop Client"
TCC_HELPER_NAME="Oracle Secure Global Desktop Client Helper"
TCC_ACTIVEX_NAME="Oracle Secure Global Desktop ActiveX Control"
TCC_PLUGIN_NAME="Oracle Secure Global Desktop Netscape Plug-in"
T3COMPONENT_WIN_NAME="Oracle Secure Global Desktop Enhancement Module for Windows"
T3COMPONENT_UNIX_NAME="Oracle Secure Global Desktop Enhancement Module for UNIX(TM) and Linux Platforms"
T3COMPONENT_SHORT_UNIX_NAME="tem"
T3COMPONENT_NAME="Oracle Secure Global Desktop Enhancement Module"
T3COMPONENT_LSBSCRIPTNAME="sun.com-sgd-em"
T3COMPONENT_LSBSCRIPT_RUN_LEVEL="90"
GWCOMPONENT_UNIX_NAME="Oracle Secure Global Desktop Gateway for UNIX(TM) and Linux Platforms"
GWCOMPONENT_NAME="Oracle Secure Global Desktop Gateway"
GWCOMPONENT_SHORTNAME="SGD Gateway"
GWCOMPONENT_LSBSCRIPTNAME="sun.com-sgd-gw"
GWCOMPONENT_LSBSCRIPT_RUN_LEVEL="91"

# Watch the length of these names: IE refuses to remove packages if
# the name is too long.
ARCHIVE_NAME_ttalw="TCC Helper, version"
ARCHIVE_NAME_asad="3.x Framework Java Archive"
#ARCHIVE_NAME_tta="3.x Java Archive"
#ARCHIVE_NAME_tta="3.x Combined Java Archive"
ARCHIVE_NAME_tta="Client, "
ARCHIVE_NAME_tsp="3.x Security Java Archive"
ARCHIVE_NAME_proxy="3.x Proxy Java Archive"
WEBSTART_JAR_NAME="sgdwscs"
ARCHIVE_SUFFIX="K"

NS_REGKEY="java/download/com/tarantella/tta"

PRODUCT_VENDOR="Oracle Corporation, Inc."
PRODUCT_SHORT_VENDOR="Oracle"

# Capabilities:
# The format for the capabilities required by the client end of a
# connection is: CAPABILITIES_protocol_type_REQUIRED="expression"

# The format for the capabilities provided by the server end of a
# connection is: CAPABILITIES_protocol_type_PROVIDED="c1 c2 ... c3"

# Asad between a webtop client and server:
CAPABILITIES_ASAD_WEBTOPCLIENT_REQUIRED="(1.1 || 1.2)"
CAPABILITIES_ASAD_WEBTOPCLIENT_PROVIDED="1.1 1.2"

# Asad between two peer servers, or an admin tool and a server:
# 1.1 is core E3 array functionality.
# 1.2 is 3.01 array interoperability functionality.
# 2.1 is core Pisa client device mapping functionality (not a requirement)
CAPABILITIES_ASAD_PEER_REQUIRED="(1.1 || 1.2)"
CAPABILITIES_ASAD_PEER_PROVIDED="1.1 1.2 2.1"

# Client versions of server strings; same format, name prefixed by CLIENT
# Asad between a webtop client and server:
CLIENTCAPABILITIES_ASAD_WEBTOPCLIENT_REQUIRED="(1.1 || 1.2)"
CLIENTCAPABILITIES_ASAD_WEBTOPCLIENT_PROVIDED="1.1 1.2"

# Top-level item names in ENS datastore
DEFAULT_ROOT_ENS="organization"
SYSTEM_ROOT_ENS="Tarantella System Objects"
APP_ROOT_ENS="applications"
APPSERVER_ROOT_ENS="appservers"

WEB_SERVICES_VERSION=1.9
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
# Modify these lists whenever the list of supported upgrades changes.
#
# The lists are egrep regular expressions.  Spaces can be inserted
# for readability: they are squeezed out at run time.
#
# POSSIBLE_UPGRADES is a full list of previous versions which stand
# a reasonable chance of being upgradable, although they may not
# necessarily all be supported.
#
# SUPPORTED_UPGRADES are the previous versions from which upgrades
# are officially supported.  SUPPORTED_UPGRADES should either be
# identical to POSSIBLE_UPGRADES, or a subset of POSSIBLE_UPGRADES.
#
POSSIBLE_UPGRADES='4\.63\.9[0-9][0-9] | 4\.71\.9[0-9][0-9] | 5\.(00|10|20|30)\.9[0-9][0-9]'
SUPPORTED_UPGRADES="${POSSIBLE_UPGRADES}"

#Marks RPM as obsoleting this version and below.
RPM_OBSOLETES=5.10
# the License Product Code
PRODUCT_LICENSE_PRODUCT_CODE="8388608"
TSP_US_LICENSE_PRODUCT_CODE="4194304"
TSP_INTL_LICENSE_PRODUCT_CODE="2097152"
USER_RESTRICTION="1"



if [ -z "$REQDIR" ]
then
    if [ -n "$INST_DATADIR" ]
    then
	REQDIR=${INST_DATADIR}/${PKG}/install
    else
	REQDIR=''
    fi
fi


[ -z "${INSTDIR}" ] && exit 1

# Returns 1 if $1 > $2 lexigraphically. 
# otherwise returns 0
strIsGreaterThan()
{
    if [ -x "/usr/bin/nawk" ]
    then
        AWK="nawk"
    else
        AWK="awk"
    fi

    echo "$1" "$2" | $AWK '{ print ( $1 > $2) ? "1" : "0" }'
}

# creates directory and sets ownership
# and permissions.
#
# Arguments
# 1 - Directory path to create.
createBackupDir()
{
    if [ ! -d "$1" ]
    then
        mkdir -p "$1"
        chown -R $privusr:$privgrp "$1"
        chmod -R 750 "$1"
    fi
}
# Checks an version number in the for {MAJOR}.{MINOR}.{BUILD}
# is newer than the refrence build number.
#
# Arguments
# 1 - Reference Version Major.
# 2 - Reference Version Minor.
# 3 - Reference Version Build.
# 4 - Instance Version Major.
# 5 - Instance Version Minor.
# 6 - Instance Version Build.
isVersionNewer()
{
    ref_major=$1
    ref_minor=$2
    ref_build=$3
    instance_major=$4
    instance_minor=$5
    instance_build=$6

    if [ \( $instance_major -gt $ref_major \) \
          -o \
          \( $instance_major -ge $ref_major -a \
            $instance_minor -gt $ref_minor \) \
          -o \
          \( $instance_major -ge $ref_major -a \
            $instance_minor -ge $ref_minor -a \
            $instance_build -gt $ref_build \) \
       ]
    then
        echo "1"
    else
        echo "0"
    fi
}

posslangs=`(cd "$REQDIR" ; ls ??-??_setup 2>/dev/null)`
case $posslangs in
  "" )						# no languages!
    PKGLANG=""
    echo "Can't find any language files in directory $REQDIR" >>$LOGFILE
    exit 1
  ;;
  ??-??_setup )    					# Good; just one
    PKGLANG=`expr "$posslangs" : "\(..-..\)"`
  ;;
  * )						# Choices, choices
    case $LANG in
      ""|C|POSIX )
      ;;					# Ignored
      * )					# Some OS specific string
        LA=`expr $LANG : "\(..\)"`    		# 1st two chars
        # must ensure tr uses C locale to lower case!
	la=`echo $LA | LANG=C LC_ALL=C tr '[A-Z]' '[a-z]'`
	goodlangs=`echo "$posslangs" | grep "^$la"`
	if [ -n "$goodlangs" ]
	then
	  posslangs=$goodlangs			# ones that match $LANG
        fi
	;;
    esac
    # Pick the first language in posslangs, or en-us if that is empty
    if [ -z "$posslangs" ]; then
	PKGLANG="en-us"
    else
	PKGLANG=`expr "$posslangs" : "\(..-..\)"`
    fi
  ;;
esac
if [ -n "$PKGLANG" ]; then
    # read the strings in
    . ${REQDIR}/${PKGLANG}_setup
    # store the strings file in the $PKGSAV directory
    if [ -n "${PKGSAV}" -a "${PKGSAV}" != "/" -a -d "${PKGSAV}" -a ! -f ${PKGSAV}/${PKGLANG}_setup ]; then
	cp ${REQDIR}/${PKGLANG}_setup ${PKGSAV}/${PKGLANG}_setup >/dev/null 2>&1
    fi
fi

privusr="sgdgsys"
privgrp="sgdgserv"


# check we have privileged user/group
badusers=""
getent group $privgrp >/dev/null || badusers=t
getent passwd $privusr >/dev/null || badusers=t

[ -z "${badusers}" ] && {
    # check that privileged user has a writable home directory
    sgdgsys_home=`su  - $privusr  -c 'test -n "$HOME" -a -w "$HOME" && echo HOME_OK:$HOME' 2>&1 | grep 'HOME_OK:.'`
    [ -z "${sgdgsys_home}" ] && badusers=t
}

[ -n "${badusers}" ] && {
    X="/tmp/SUNWsgdgCreateUsers.sh"
    printf "${i18n_setupusers_gw}\n" "${GWCOMPONENT_NAME}" "${X}"
    cat >${X} <<\!
#!/bin/sh
#  $Id: GWCreateUsers.sh 24621 2015-03-31 12:25:50Z pc161604 $
#  Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
#  Create user accounts required by Oracle Secure Global Desktop Gateway.

u="`LANG=C LC_ALL=C id | sed 's/.*uid=\([0-9][0-9]*\).*/\1/'`"
[ "$u" = "0" ] || { echo "You must be root to run this program" >&2; exit 1; }

HOMEBASE="/home"
[ -d "/export/home" ] && HOMEBASE="/export/home"

# Create sgdgserv group
groupadd sgdgserv

# Create sgdgsys user
useradd -d ${HOMEBASE}/sgdgsys -m sgdgsys

# Lock user accounts
passwd -l sgdgsys

# Make home directories writeable
chown sgdgsys ${HOMEBASE}/sgdgsys
chmod 700 ${HOMEBASE}/sgdgsys

exit 0

!
    chmod 700 ${X} 2>/dev/null
    ##Clear partial GW Install from System##
    ADMINFILE=/tmp/$PKGINST.admin
cat >${ADMINFILE} <<_EOF
mail=
instance=unique
partial=nocheck
runlevel=nocheck
idepend=nocheck
rdepend=nocheck
space=nocheck
setuid=nocheck
conflict=nocheck
action=nocheck
basedir=default
_EOF

    cat > /tmp/SUNWsgdgtidy <<EOF
#!/bin/sh
sleep 5
pkgrm -n -a "${ADMINFILE}" "${PKGINST}"
exit 0
EOF
    # run the script outside pkgadd context
    nohup sh /tmp/SUNWsgdgtidy >/dev/null 2>&1 &
    # now exit with an error to abort pkgadd
    exit 1
}

[ -d "${INSTDIR}" ] && {
    cd "${INSTDIR}"
    [ `pwd` = "${INSTDIR}" -a -s etc/version -a -s proxy/etc/keystore ] && {
        . etc/version
        UPGRADE="${VERSION_SUNWsgdg}"
        OldVersionAsNumber=`echo "${UPGRADE}" | tr -d .`

        [ "${OldVersionAsNumber}" -lt "462900" ] && {
             printf "\nUpgrade from ${UPGRADE} is not supported.\n"
             exit 1
        }

        jive_Build=$UPGRADE;
  _currpatt="`expr \"${PRODUCT_VERSION_FULL}\" : '\(.....\).*' | sed 's/\./,./g;s/$/.*/' | tr ',' '\134'`"
  _patt="^(`echo \"${SUPPORTED_UPGRADES}|${_currpatt}\" | tr -d ' '`)\$"
  allowUpgrade="f"
  [ -n "`echo \"${jive_Build}\" | egrep \"${_patt}\"`" ] && allowUpgrade="t"

        [ "${allowUpgrade}" = "f" ] && {
            [ -f "${INSTDIR}/var/UPGRADE" ] && {
                printf "\n${i18n_forceupgrade}\n"
            } || {
                printf "\n${i18n_pf1_cantupgrade_gw}\n" "${UPGRADE}" "${INSTDIR}/var/UPGRADE"
                exit 1
            }
        }

        cp -p etc/version etc/version.prev
        case "${OldVersionAsNumber}" in
            [0-9][0-9][0-9][0-9][0-9][0-9]) ;;
            *) OldVersionAsNumber=0
        esac

        [ "${OldVersionAsNumber}" -gt 0 ] && {
            ${INSTDIR}/bin/gateway stop --force
            
            comp_backup_dir="$INSTDIR/var/upgrade-backup.${UPGRADE}"
            createBackupDir "${comp_backup_dir}"

            read apache_to_install \
                             < "${INST_DATADIR}/${PKG}/reloc/var/info/apacheversion"
            # Note: format of file is "2.2.31_openssl-1.0.2h_jk1.2.41_64"
            # does not include a httpd- prefix.
            httpd_version="`echo ${apache_to_install} | cut -d_ -f1`"

            httpd_major="`echo ${httpd_version} | cut -d. -f1`"
            httpd_minor="`echo ${httpd_version} | cut -d. -f2`"
            httpd_build="`echo ${httpd_version} | cut -d. -f3`"

            openssl_version="`echo ${apache_to_install} \
                                                   | cut -d_ -f2 | cut -d- -f2`"
            openssl_major="`echo ${openssl_version} | cut -d. -f1`"
            openssl_minor="`echo ${openssl_version} | cut -d. -f2`"
            openssl_build="`echo ${openssl_version} | cut -d. -f3`"

            openssl_build_num=`expr ${openssl_build} : '.*\([0-9]\).*'`
            openssl_build_letter=`expr ${openssl_build} : '.*\([a-z]\).*'`

            createBackupDir "${comp_backup_dir}/httpd"

            for httpd_instance in `ls ${INSTDIR}/httpd  | egrep "httpd.*-.*_openssl"`
            do
                # Verify httpd_instance is in the expected format
                httpd_regex="^httpd-[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*_openssl-[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*[a-z]*_jk[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]_64$"
                expr "$httpd_instance" : "$httpd_regex" 2>&1 >/dev/null
                exitCode=$?
                if [ $exitCode -ne 0 ]
                then 
                    continue
                fi

                # Note: httpd_instance will be prefixed with httpd-
                httpd_instance_version="`echo ${httpd_instance} | cut -d_ -f1 \
                                                                 | cut -d- -f2`"

                httpd_instance_major="`echo ${httpd_instance_version} \
                                                           | cut -d. -f1`"

                httpd_instance_minor="`echo ${httpd_instance_version} \
                                                           | cut -d. -f2`"

                httpd_instance_build="`echo ${httpd_instance_version} \
                                                           | cut -d. -f3`"

                openssl_instance_version="`echo ${httpd_instance} \
                                                 | cut -d_ -f2 | cut -d- -f2`"

                openssl_instance_major="`echo ${openssl_instance_version} \
                                                           | cut -d. -f1`"

                openssl_instance_minor="`echo ${openssl_instance_version} \
                                                           | cut -d. -f2`"

                openssl_instance_build="`echo ${openssl_instance_version} \
                                                           | cut -d. -f3`"

                openssl_instance_num="`expr ${openssl_instance_build} : '.*\([0-9]\).*'`"
                openssl_instance_letter="`expr ${openssl_instance_build} : '.*\([a-z]\).*'`"

                # Move any instance that has a newer version of httpd,
                # or openssl included.
                openssl_build_letter_newer=`strIsGreaterThan \
                                                   ${openssl_instance_letter} \
                                                   ${openssl_build_letter}`
                if [ \( `isVersionNewer   $httpd_major \
                                          $httpd_minor \
                                          $httpd_build \
                                          $httpd_instance_major \
                                          $httpd_instance_minor \
                                          $httpd_instance_build` = "1" \)  \
                      -o \
                      \( `isVersionNewer  $openssl_major \
                                          $openssl_minor \
                                          $openssl_build_num \
                                          $openssl_instance_major \
                                          $openssl_instance_minor \
                                          $openssl_instance_num` = "1" \)  \
                      -o \
                      \( ${openssl_instance_major} -eq ${openssl_major}     -a \
                         ${openssl_instance_minor} -eq ${openssl_minor}     -a \
                         ${openssl_instance_num}   -eq ${openssl_build_num} -a \
                         ${openssl_build_letter_newer} -eq 1 \)   \
                   ]
                then
                    mv "${INSTDIR}/httpd/${httpd_instance}" \
                                "${comp_backup_dir}/httpd"
                fi
            done

            if [ -d "${comp_backup_dir}/httpd/httpd-${VERSION_APACHE}/conf/" ]
            then
                # Copy the current httpd config back into a versioned
                # directory, the config directory will be picked up
                # by the upgrade and re-integrated.
                # The directory suffix ".${OLDVERSION}" is required for this.
                httpd_backup_dir="httpd/httpd-upgrade.${UPGRADE}"
                createBackupDir "${httpd_backup_dir}"
            
                # If a newer version has been backed up, move its config back
                # to be integrated post-upgrade.
                cp -R "${comp_backup_dir}/httpd/httpd-${VERSION_APACHE}/conf/" \
                      "${httpd_backup_dir}"
            fi
            
            for d in etc httpd/httpd-${VERSION_APACHE}/conf proxy/etc; do
                [ ! -d "${d}.${UPGRADE}" ] && cp -rp ${d} "${d}.${UPGRADE}" 2>/dev/null
            done
            rm -rf etc.${UPGRADE}/locale* etc.${UPGRADE}/pkg 2>/dev/null
        }

    }
}

chown $privusr:$privgrp ${INSTDIR}

exit 0
