#!/bin/sh
# Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
#  $Id: dbcreate.sh 109677 2015-03-31 12:24:31Z pc161604 $
#
#  Author: Bill Weir
#  Database creation script
ans_host=`hostname`
if [ -f "$INSTDIR/$ans_host.answers" ]; then
    . "$INSTDIR/$ans_host.answers"
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


if [ -z "$0" ]; then
  who_i_am=""
else
  who_i_am=`expr "//$0" : '.*/\(.*\)' `
fi

lf_nomessages="No message files installed for LANG="
l_langdefault="Attempting to use default English (en-us) messages"
l_langunknown="Unrecognized \$LANG: "
l_langunset="\$LANG is not set."
lf_langright="Please check the \$LANG variable is correct."
l_langsetto="\$LANG is currently set to: "
l_gottheselangs="Message files are installed for the following languages:"
l_usinglang="Using messages in"
[ -z "$LANG" ] && LANG="C"

TTALANG=$LANG
case "$TTALANG" in
C)  TTALANG="en-us"
    ;;
[a-z][a-z]_[A-Z][A-Z])
    # convert LANG format from ab_CD to ab-cd
    TTALANG=`echo "$TTALANG" | LANG=C LC_ALL=C tr '[A-Z]_' '[a-z]-'`
esac

if [ ! -d $TTALANG -o -z "$TTALANG" ]; then
  [ ! -z "$TTALANG" ] && posslangs=`find . -type d -name "$TTALANG*" -print 2>/dev/null | sed 's;.*\/.*\/.*;;'`

  [ -z "$posslangs" ] && posslangs=`find . -type d -name '[a-z][a-z]-[a-z][a-z]*' -print 2>/dev/null | sed 's;.*\/.*\/.*;;'`

  nposslangs=`echo $posslangs | wc -w`
  if [ "$nposslangs" -gt 1 ]; then
    case "$TTALANG" in ?) TTALANG=en-us;; esac
    tmpTTALANG=$TTALANG
    for a_lang in $posslangs; do
      output=`echo $a_lang | sed -e 's/.*\///'`
      if [ -f $output/common -o -f ../$output/common ]; then
	[ "$tmpTTALANG" != "en-us" ] && tmpTTALANG=$output
      fi
    done
    [ "$TTALANG" = "$tmpTTALANG" ] && TTALANG=en-us || TTALANG=$tmpTTALANG	
  elif [ "$nposslangs" -eq 1 ]; then
    TTALANG=`echo $posslangs | sed -e 's/.*\///'`
  else
    echo "$lf_reinst"
    exit 5
  fi
fi

TTAMSG=`pwd`/$TTALANG
export TTAMSG TTALANG
if [ $trace ]; then echo "   trace: Language dir = $TTAMSG"; fi

if [ -f $TTAMSG/common ]; then
  . $TTAMSG/common
else
  _lang=`basename $TTAMSG`
  _parent=`dirname $TTAMSG`
  _parent=`dirname $_parent`
  if [ -f $_parent/$_lang/common ]; then
    . $_parent/$_lang/common
  else
    echo "Unable to open message file: $TTAMSG/common"
    exit 1
  fi
fi
if [ -f $TTAMSG/setup ]; then
  . $TTAMSG/setup
else
  echo "Unable to open message file: $TTAMSG/setup"
  exit 1
fi

GetPrivUsrGrp()
{
    cat $INSTDIR/var/serverconfig/global/array.properties 2>/dev/null | awk -F= \
	'BEGIN { u="ttasys"; wu="ttaserv"; g="ttaserv" }
	$1 == "tarantella.config.array.privilegeduser" { u = $2 }
	$1 == "tarantella.config.array.webserveruser" { wu = $2 }
	$1 == "tarantella.config.array.privilegedgroup" { g = $2 }
	END { print u " " wu " " g }'
}
_privusrgrp=`GetPrivUsrGrp`
privusr=`expr "$_privusrgrp" : '\([^ ]*\) .*'`
webservusr=`expr "$_privusrgrp" : '.* \([^ ]*\) .*'`
privgrp=`expr "$_privusrgrp" : '.* \([^ ]*\)$'`

export privusr webservusr privgrp
MkTtaDir()
{
    _newdirs="" _pflag=""
    case "$1" in
    -p) _pflag="-p"; shift
    esac
    for _d in "$@"; do
	while [ -n "$_d" ]; do
	    [ -d "$_d" ] && break
	    _newdirs="$_newdirs $_d"
	    _d=`dirname $_d`
	done
    done
    mkdir $_pflag "$@"
    [ -n "$_newdirs" ] && { chgrp $privgrp $_newdirs 2>/dev/null; chown $privusr $_newdirs 2>/dev/null; }
}


xflag=""
case "$trace" in
x) set -x; xflag="-x"
esac

ttacommand=$0
case "$ttacommand" in
/*) cd `dirname $ttacommand`
    ourdir=`dirname $ttacommand`
    ;;
*)  fullpath=`pwd`/$ttacommand
    cd `dirname $fullpath`
    ourdir=`dirname $fullpath`
    ;;
esac

CopyExtras()
{
    cmd="cp"
    case "$1" in
    --link) cmd="ln -s"; shift
    esac
    src="$1" dest="$2" pattern="${3:-.}" namepattern="$4"
    if [ -d "$src" ]; then
    (
      cd $src
      mkdir -p $dest 2>/dev/null
	find $pattern -depth $namepattern -print 2>/dev/null |
	    cpio -pdum $dest 2>/dev/null
	find $pattern \( ! -type d \) $namepattern -print 2>/dev/null |
	    sed 's/^\.\///' |
	    xargs -i@ echo $cmd $src/@ $dest/@ >>$instdir/etc/pkg/$pkginst/extras
    )
    fi
}

### Copy files to INSTDIR/var, no record is kept, files will not be
### removed during uninstall
NewCopyExtras()
{
    cmd="cp"
    case "$1" in
    --link) cmd="ln -s"; shift
    esac
    src="$1" dest="$2" pattern="${3:-.}" namepattern="$4"
    if [ -d "$src" ]; then
    (
      cd $src
      mkdir -p $dest 2>/dev/null
      find $pattern -depth $namepattern -print 2>/dev/null |
          cpio -pdum $dest 2>/dev/null
    )
    fi
}

### As NewCopyExtras(), but don't copy over the top of an 
### existing file
MaybeCopyExtras()
{
    cmd="cp"
    case "$1" in
    --link) cmd="ln -s"; shift
    esac
    src="$1" dest="$2" pattern="${3:-.}" namepattern="$4"
    if [ -d "$src" ]; then
    (
	cd $src
	mkdir -p $dest 2>/dev/null
	for copy in `find $pattern -depth $namepattern -print 2>/dev/null`; do
	    [ ! -f "$dest/$copy" -a ! -d "$copy" ] && echo "$copy"
	done | cpio -pdum $dest 2>/dev/null
    )
    fi   
}  

### As NewCopyExtras(), but don't copy if dest file exists and is different
### to template file
MaybeCopyExtras2()
{
    cmd="cp"
    case "$1" in
    --link) cmd="ln -s"; shift
    esac
    src="$1" dest="$2" template="$3"
    if [ -d "$src" ]; then
    (
        # a list of any files that the administrator has edited by hand or added
        NotUpgOut=$instdir/var/log/customized.list

        # a list of any files that the administrator has edited, and which would also 
        # have been changed by the upgrade 
        CustChanged=$instdir/var/log/customizedchanged.list
        CustMissing=$instdir/var/log/customized.missing

        cd $src
	mkdir -p $dest 2>/dev/null
	for copy in `find . -depth -print 2>/dev/null`; do
            case $copy in
                *_0x3d_*) thecopy=`echo $copy | sed 's;_0x3d_;=;g'` ;;
                * ) thecopy=$copy ;;
            esac	    
            if [ -f "$dest/$thecopy" ]; then
                res_cmp=`cmp -s $template/$copy $dest/$thecopy; echo $?` 
                case $res_cmp in
                    0 ) echo "$copy" ;;
                    1 ) echo "$dest/$thecopy" >> $NotUpgOut
                        # If the new file is different to the original template
                        res=`cmp -s $copy $template/$copy; echo $?`
                        case $res in
                            0 ) : ;;
                            1 ) echo "$dest/$thecopy" >>$CustChanged ;;
                            2 ) echo "$template/$copy" >>$CustMissing ;;
                        esac 
                    ;;                   
                    2 ) echo "$template/$copy" >>$CustMissing ;;
                esac
            elif [ ! -d $copy ]; then
                echo $copy 
            fi
	done | cpio -pdum $dest 2>/dev/null
    )
    fi   
}  

### Given the top level of an installed directory of webtop or login 
### themes ($2) check each theme directory against a template 
### theme directory ($3), if any file in a theme is found 
### to be modified, don't upgrade that theme from new templates ($1).
### Potentially, the files copied are .../locale_0x3d_..., renaming is handled
### by the files_rename script that is run after the templates script.
MaybeCopyExtras3()
{
    cmd="cp"
    case "$1" in
    --link) cmd="ln -s"; shift
    esac
    src="$1" dest="$2" template="$3"
    if [ -d "$src" ]; then
    (
        # a list of any files that the administrator has edited by hand or added
        NotUpgOut=$instdir/var/log/customized.list

        # a list of any files that the administrator has edited, and which would also 
        # have been changed by the upgrade 
        CustChanged=$instdir/var/log/customizedchanged.list
        CustMissing=$instdir/var/log/customized.missing

        cd $src
	mkdir -p $dest 2>/dev/null
        # get a list of all themes we want to install
        for theme in `ls -d * | grep -v "^\.$"`; do
            mod_flag=0
            # if a theme of the same name is already installed, check against 
            # the original template
            if [ -d $dest/$theme ]; then
  	        for copy in `find $theme -depth -print 2>/dev/null`; do
                    # locale templates haven't had the '0x3d' -> '=' conversion
                    case $copy in
                        *_0x3d_*) thecopy=`echo $copy | sed 's;_0x3d_;=;g'` ;;
                        * ) thecopy=$copy ;;
                    esac
	            if [ -f "$dest/$thecopy" ]; then
                        res_cmp=`cmp -s "$template/$copy" "$dest/$thecopy"; echo $?` 
                        case $res_cmp in
                            0 ) : ;;
                            1 ) # files are different, don't upgrade
                                mod_flag=1 
                                echo "$dest/$thecopy" >>$NotUpgOut 
                                # If the new file is different to the original template
                                res=`cmp -s $copy $template/$copy; echo $?`
                                case $res in
                                    0 ) : ;;
                                    1 ) echo "$dest/$thecopy" >>$CustChanged ;;
                                    2 ) echo $template/$copy >>$CustMissing ;;
                                esac
                            ;;
                            2 ) # cmp failed, possibly 'cos no template file - user added file?
                                echo "$template/$copy" >> $CustMissing ;;
                        esac
                    fi
                done
            fi
            case $mod_flag in
                0) find $theme -depth -print 2>/dev/null;;
                1) echo "Not upgrading theme $src/$theme" >> $NotUpgOut ;;
            esac
	done | cpio -pdum $dest 2>/dev/null
    )
    fi   
}  

### Almost identical to CopyExtras3, except that all themes are overwritten
### This just serves to tell the user what modifed bits have been changed.
### There is a check at the end to warn of user added themes that they will
### need to fix to work with 3.3.
### fitz/603863 for more.
MaybeCopyExtras4()
{
    cmd="cp"
    case "$1" in
    --link) cmd="ln -s"; shift
    esac
    src="$1" dest="$2" template="$3"
    if [ -d "$src" ]; then
    (
        # a list of any files that the administrator has edited by hand or added
        NotUpgOut=$instdir/var/log/customized.list

        # a list of any files that the administrator has edited, and which would also 
        # have been changed by the upgrade 
        CustChanged=$instdir/var/log/customizedchanged.list
        CustMissing=$instdir/var/log/customized.missing

        cd $src
	mkdir -p $dest 2>/dev/null
        # get a list of all themes we want to install
        for theme in `ls -d * | grep -v "^\.$"`; do
            mod_flag=0
            # if a theme of the same name is already installed, check against 
            # the original template
            if [ -d $dest/$theme ]; then
  	        for copy in `find $theme -depth -print 2>/dev/null`; do
                    # locale templates haven't had the '0x3d' -> '=' conversion
                    case $copy in
                        *_0x3d_*) thecopy=`echo $copy | sed 's;_0x3d_;=;g'` ;;
                        * ) thecopy=$copy ;;
                    esac
	            if [ -f "$dest/$thecopy" ]; then
                        res_cmp=`cmp -s "$template/$copy" "$dest/$thecopy"; echo $?` 
                        case $res_cmp in
                            0 ) : ;;
                            1 ) # files are different, don't upgrade
                                mod_flag=1 
                                echo "File $dest/$thecopy changed.">>$CustChanged
                                # don't care about original and new template diffs
                                # it's going to get replaced, whatever
                            ;;
                            2 ) # cmp failed, possibly 'cos no template file - user added file?
                                echo "$template/$copy" >> $CustMissing ;;
                        esac
                    fi
                done
            fi
            case $mod_flag in
                1) 
                    echo "Modified theme $dest/$theme has been replaced" >> $CustChanged 
                ;;
            esac
            find $theme -depth -print 2>/dev/null
	done | cpio -pdum $dest 2>/dev/null

        # now check for user added themes that won't have been upgraded
        cd $dest
        for theme in `ls -d * | grep -v "^\.$"`; do
            if [ ! -d $src/$theme ]; then
                echo "Theme $theme in $dest not upgraded" >> $NotUpgOut
            fi
        done
    )
    fi   
}  

### Given a directory of expect scripts
### $1 new templates
### $2 dir to install to
### $3 old templates for comparison
CopyExpect()
{
    set -x
    cmd="cp"
    case "$1" in
    --link) cmd="ln -s"; shift
    esac
    src="$1" dest="$2" template="$3"
    if [ -d "$src" ]; then
    (
        # a list of any files that the administrator has edited by hand
        # that we are going to everwrite
        ExpectUpg=$instdir/var/log/expectcustomized.list
        rm -f $ExpectUpg

        cd $src
        mkdir -p $dest 2>/dev/null
        # if a script of the same name is already installed, check against 
        # the original template
        for copy in `find . -type f -depth -print 2>/dev/null`; do 
            if [ -f "$dest/$copy" ]; then
                res_cmp=`cmp -s "$template/$copy" "$dest/$copy"; echo $?` 
                case $res_cmp in
                    1 ) # files are different, or we are about to install a
                        # new one, but they already have one of the same name.
                        # warn user
                        echo "$dest/$copy" >>$ExpectUpg
                    ;;
                esac
            fi
        done
        find . -depth -print 2>/dev/null | cpio -pdum $dest 2>/dev/null
        cd $dest
        for f in *; do
            if [ ! -f $src/$f -a "$f" != "wcpwts.exp" ]; then
                echo "File $dest/$f" >>$NotUpgOut
            fi      
        done
    )
    fi
    set +x
}  


MkTtaDir -p\
    $instdir/var/ens\
    $instdir/var/serverresources\
    $instdir/var/backup/serverconfig\
    2>/dev/null

chmod 711 $instdir/var/ens

# If we're a dev install, we need to install the static config now
if [ -n "${TTA_DEVINSTALL}" ]
then
    # want to overwrite this lot
    CopyExtras "$instdir/etc/templates/serverresources" \
        "$instdir/var/serverresources" "tfn schema cryptix adminconfig"
    MaybeCopyExtras
        "$instdir/etc/templates/serverresources/serverconfig"
        "$instdir/var/serverconfig"
fi


# Add our host config object to the global config
# Fitz 601881:2 added tarantella.config.host.tier2loadbalancing.weighting
  HOST=""
  _localbootprops="${instdir}/var/serverconfig/local/bootstrap.properties"
  [ -s "${_localbootprops}" ] && HOST=`sed -n '/server\.dns\.peer=/s/.*=//p' "${_localbootprops}" | tail -1`
  [ -z "${HOST}" ] && HOST=`${instdir}/bin/bin/ttahostname`

hostconfigfile=${instdir}/var/serverconfig/global/${HOST}.properties
if [ ! -f "$hostconfigfile" ]; then
    peerhostname=$HOST
    externalhostname=$HOST
    datestamp=`date`
    cat > $hostconfigfile <<EOF
# Original contents generated by postinstall script ($datestamp)
tarantella.config.type=server
tarantella.config.name=host
tarantella.config.host.dns.peer=$peerhostname
tarantella.config.host.dns.external=$externalhostname
tarantella.config.host.master=$peerhostname
tarantella.config.host.security.active=
tarantella.config.host.serviceids=scotta5250application,scotta3270application,scottaxapplication,scottacharacterapplication,scottawindowsapplication
tarantella.config.host.localprinting.status=0
tarantella.config.host.load.cpuload=100
tarantella.config.host.load.cpuloadref=0
tarantella.config.host.load.power=0
tarantella.config.host.acceptnewconnections=enabled
tarantella.config.host.locality=
tarantella.config.host.tier2loadbalancing.weighting=100
EOF
    [ -n "$privusr" ] && chown "$privusr" "$hostconfigfile"
fi

# Where are we relative to top of tta2 tree?
top=.
for _i in 0 1 2 3 4 5 6 7 8 9; do
    [ -d $top/bin/java -a -x $top/bin/tarantella ] && break
    [ -f $top/etc/passwd ] && { top=.; break; }
    top=../$top
done


# Set port numbers. Start by sourcing info/ports.properties.
if [ -r $top/var/info/ports.properties ]; then
	. $top/var/info/ports.properties
fi

# Use these as defaults for config
tarantella_config_array_externalport=${externalport:-3144}
tarantella_config_array_port=${peerport:-5427}
tarantella_config_array_secureport=${secureport:-5307}
#also include proxiedhttpsurl for firewall traversal
tarantella_config_server_proxiedhttpsurl=${proxiedhttpsurl:-""}
tarantella_config_array_privilegeduser=${privilegeduser:-""}
tarantella_config_array_privilegedgroup=${privilegedgroup:-""}
#also include privileged username for web authentication
tarantella_config_array_webserveruser=${webserveruser:-""}
# Include web auth key refresh
tarantella_config_login_webauth_refreshkeyonrestart=${refreshkeyonrestart:-""}

#Include attribute to tell ttawebtop whether to be verbose or not
tarantella_config_server_cgiverbose=${cgiverbose:-""}

#Include attribute used to modify the archive names
tarantella_config_server_archivemodifier=${archivemodifier:-""}

#Attribute for cgi-bin to tell client to bootstrap from
tarantella_config_server_cgibin_bootscript=${bootscript:-""}

#Attribute passed to client so it knows the route to the server.
tarantella_config_array_netservice_proxy_routes=${routes:-""}

#Attribute passed to client so it knows the correct external name of the server
tarantella_config_server_netservice_proxy_externalnames=${externalnames:-""}

#SHould we use ssl on peer connections? Admin tools need to know
tarantella_config_security_peerssl_enabled=${peerssl:-"0"}

# Use the bootstrap.properties file if we can.
_propfile="$top/var/serverconfig/global/bootstrap.properties"
[ -s "${_propfile}" -a -r "${_propfile}" ] && {
eval `tr -d '\\\\' <"${_propfile}" | egrep -v "^[ 	]*#|'|^tarantella\.config\.(name|type)=" | sed "/=/!d
:dotloop
s/^\([^=]*\)\.\([^=]*=.*\)\$/\1_\2/
tdotloop
s/^\([^=]*\)=\(.*\)/\1='\2'/"`
}

# Set the values in the expected variables.
externalport=$tarantella_config_array_externalport
secureport=$tarantella_config_array_secureport
peerport=$tarantella_config_array_port

# Set DNS names. Use the bootstrap.properties file if we can.
_propfile="$top/var/serverconfig/local/bootstrap.properties"
[ -s "${_propfile}" -a -r "${_propfile}" ] && {
eval `tr -d '\\\\' <"${_propfile}" | egrep -v "^[ 	]*#|'|^tarantella\.config\.(name|type)=" | sed "/=/!d
:dotloop
s/^\([^=]*\)\.\([^=]*=.*\)\$/\1_\2/
tdotloop
s/^\([^=]*\)=\(.*\)/\1='\2'/"`
}

# We need defaults if the properties file is unreadable or corrupt.
peerhost=${tarantella_config_server_dns_peer:-`$top/bin/bin/ttahostname`}
externalhost="${tarantella_config_server_dns_external:-$peerhost}"
auxhost="$peerhost"

# Get the value of proxiedhttpsurl/cgiverbose/archivemodifier/bootscript from 
# server.properties
_propfile="$top/var/serverconfig/local/server.properties"
[ -s "${_propfile}" -a -r "${_propfile}" ] && {
eval `tr -d '\\\\' <"${_propfile}" | egrep -v "^[ 	]*#|'|^tarantella\.config\.(name|type)=" | sed "/=/!d
:dotloop
s/^\([^=]*\)\.\([^=]*=.*\)\$/\1_\2/
tdotloop
s/^\([^=]*\)=\(.*\)/\1='\2'/"`
}

# Get the properties from array.properties
_propfile="$top/var/serverconfig/global/array.properties"
[ -s "${_propfile}" -a -r "${_propfile}" ] && {
eval `tr -d '\\\\' <"${_propfile}" | egrep -v "^[ 	]*#|'|^tarantella\.config\.(name|type)=" | sed "/=/!d
:dotloop
s/^\([^=]*\)\.\([^=]*=.*\)\$/\1_\2/
tdotloop
s/^\([^=]*\)=\(.*\)/\1='\2'/"`
}

# Get web auth properties
_propfile="$top/var/serverconfig/global/webauth.properties"
[ -s "${_propfile}" -a -r "${_propfile}" ] && {
eval `tr -d '\\\\' <"${_propfile}" | egrep -v "^[ 	]*#|'|^tarantella\.config\.(name|type)=" | sed "/=/!d
:dotloop
s/^\([^=]*\)\.\([^=]*=.*\)\$/\1_\2/
tdotloop
s/^\([^=]*\)=\(.*\)/\1='\2'/"`
}

# Get peerssl properties
_propfile="$top/var/serverconfig/global/security.properties"
[ -s "${_propfile}" -a -r "${_propfile}" ] && {
eval `tr -d '\\\\' <"${_propfile}" | egrep -v "^[ 	]*#|'|^tarantella\.config\.(name|type)=" | sed "/=/!d
:dotloop
s/^\([^=]*\)\.\([^=]*=.*\)\$/\1_\2/
tdotloop
s/^\([^=]*\)=\(.*\)/\1='\2'/"`
}

proxiedhttpsurl=$tarantella_config_server_proxiedhttpsurl
privilegeduser=$tarantella_config_array_privilegeduser
privilegedgroup=$tarantella_config_array_privilegedgroup
webauthrefresh=$tarantella_config_login_webauth_refreshkeyonrestart
cgiverbose=$tarantella_config_server_cgiverbose
archivemodifier=$tarantella_config_server_archivemodifier
bootscript=$tarantella_config_server_cgibin_bootscript
routes=$tarantella_config_array_netservice_proxy_routes
externalnames=$tarantella_config_server_netservice_proxy_externalnames
peerssl=$tarantella_config_security_peerssl_enabled
peersslciphers=$tarantella_config_security_peerssl_ciphers
webserveruser=$tarantella_config_array_webserveruser

INSTALLDIR=$top
export INSTALLDIR


exec >>${INSTDIR}/var/log/setup.log 2>&1

exit 0

