#!/bin/sh -x
# This script does some of the postinstall tasks for
# the Seabreeze installation.
#
# Copyright (c) 1998 by Sun Microsystems, Inc.
# All rights reserved.
#
# @(#)postinstall	1.10          09/01/99 
#

##########################################################################
# set the version sub-directory and configuration paths

VERSIONDIR="3_0"

##############################################################################################
############### Do authorization/scope and directory table setups ###################

## If the primary admin variable is set,do the configuration otherwise ask the user to run the configuration command

if [ "${PRIMARYADMIN}" = "" ]; then

    echo "\nYou have not set the Primary Administrator."
    echo "You must log on as root when you start AdminSuite and define a Primary Administrator" 
    echo " with the Users application.\n"
fi


AUTHSCOPE="all"
SCOPETYPE="all"
HOSTNAME=`uname -n`
OPTPARAM="initial"
STARTSCRIPT="/etc/init.d/admsvr${VERSIONDIR}"
USERNAME=${PRIMARYADMIN}
 
 
# Set Java JRE home directory path
#
if [ "$JAVA_HOME" = "" ]; then
    JAVA_HOME=/usr/java1.1
    export JAVA_HOME
fi
 
# Set base directory path
#
 BASEPATH=${BASEDIR}/SUNWseam/${VERSIONDIR}


############ Set directory path and system property name for client properties file ##################

if [ -f /etc/opt/SUNWseam/${VERSIONDIR}/client/AdminClient.properties ]; then
    PROPPATH=/etc/opt/SUNWseam/${VERSIONDIR}/client
else
    PROPPATH=${BASEPATH}/etc
fi
PROPNAME="admin.client.properties"
 
# Set path name of the file containing the default set of authorizations
AUTHFILE=${BASEPATH}/etc/AdminAuths.properties
 
 
# Set directory path and system property name for server properties file
# assume that we've got our writable version in /etc...
#
if [ -f /etc/opt/SUNWseam/${VERSIONDIR}/server/AdminServer.properties ]; then
    PROPPATH2=/etc/opt/SUNWseam/${VERSIONDIR}/server
else
    PROPPATH2=${BASEPATH}/etc
fi
export PROPPATH2
 
PROPPROP="admin.server.properties"
export PROPPROP
 
 
OSARCH=`uname -p`
LD_LIBRARY_PATH=${BASEPATH}/lib:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
echo LIBRARY_PATH:  ${LD_LIBRARY_PATH}
 
if [ -f ${BASEPATH}/admswt10.jar ]; then
    CODEPATH=${BASEPATH}/admswt10.jar
else
    CODEPATH=${BASEPATH}/classes
fi

CLASSPATH=${CODEPATH}:${JAVA_HOME}/lib/classes.zip
export CLASSPATH
echo CLASSPATH: ${CLASSPATH}
 
############# Configure the directory/authorization tables on all manageable scopes for this server ##########

echo "Setting up directory tables ..."
${JAVA_HOME}/bin/java  -D"${PROPPROP}=${PROPPATH2}" com.sun.admin.cis.service.directorytable.DirectoryTableSetup ${OPTPARAM}

    if [ "$?" != "0" ]; then

       echo " Directory table setup failed....."
 
    fi
 
echo "Setting up authorization..."
${JAVA_HOME}/bin/java  -D"${PROPPROP}=${PROPPATH2}" com.sun.admin.cis.service.authorization.AuthSetup ${AUTHFILE} ${AUTHSCOPE} ${USERNAME}

  if [ "$?" != "0" ]; then 

       echo " Authorization setup failed....." 
  
    fi 
 
echo "Setting up default scope..."
${JAVA_HOME}/bin/java -D"${PROPNAME}=${PROPPATH}" com.sun.admin.cis.common.ScopeSetup ${SCOPETYPE}

  if [ "$?" != "0" ]; then 

       echo " Scopes  setup failed....." 
  
    fi 
 
 
###################### Now start the server #######################################################################
echo "Starting the server ...."
CDARCHIVE=`pwd`

cd /tmp

/bin/nohup ${STARTSCRIPT} start >/dev/null 

cd ${CDARCHIVE}


#################################################################################################################
## Done
echo "AdminSuite installation completed..."
exit 0
