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

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

VERSIONDIR="3_0"
SEABASE=$BASEDIR/SUNWseam/$VERSIONDIR

SEAETCROOT="/etc/opt/SUNWseam" 
SEAVAROOT="/var/opt/SUNWseam" 
SEAETCDIR="${SEAETCROOT}/${VERSIONDIR}"
SEAVARDIR="${SEAVAROOT}/${VERSIONDIR}"


##########################################################################
# Create configuration subdirectories in /etc/opt

echo "Creating configuration directories..."
if [ ! -d "/etc/opt" ]
  then 
    mkdir /etc/opt
    chmod 755 /etc/opt
fi

if [ ! -d "${SEAETCROOT}" ]
  then 
    mkdir $SEAETCROOT
    chmod -R 755 $SEAETCROOT
fi

if [ ! -d "${SEAETCDIR}" ]
  then
    mkdir $SEAETCDIR
    chmod -R 755 $SEAETCDIR
fi

if [ ! -d "${SEAETCDIR}/client" ]
  then   
    mkdir $SEAETCDIR/client
    chmod -R 755 ${SEAETCDIR}/client
fi

if [ ! -d "${SEAETCDIR}/server" ] 
  then   
    mkdir $SEAETCDIR/server 
    chmod -R 755 $SEAETCDIR/server
fi

##########################################################################
# Create scopes and log directories in /var/opt

echo "Creating log and scopes directories..."
if [ ! -d "/var/opt" ]
  then 
    mkdir /var/opt
    chmod 755 /var/opt
fi

if [ ! -d "${SEAVAROOT}" ]
  then  
    mkdir $SEAVAROOT
    chmod 755 $SEAVAROOT
fi

if [ ! -d "${SEAVARDIR}" ]
  then 
    mkdir $SEAVARDIR
    chmod 755 $SEAVARDIR
fi


if [ ! -d "${SEAVARDIR}/client" ]
  then
    mkdir $SEAVARDIR/client
    chmod 777 $SEAVARDIR/client
fi
 
if [ ! -d "${SEAVARDIR}/log" ]
  then
    mkdir $SEAVARDIR/log
    chmod 755 $SEAVARDIR/log
fi

##########################################################################
# Create the admin.conf file.  Blow away any existing one.

echo "Creating admin.conf configuration file..."
cat << END > ${SEAETCDIR}/admin.temp
# SEAS Management configuration file - Do Not Edit
admin.base.dir=${SEABASE}
END
if [ -f ${SEAETCDIR}/admin.old ]; then
   rm ${SEAETCDIR}/admin.old
fi
if [ -f ${SEAETCDIR}/admin.conf ]; then
   mv ${SEAETCDIR}/admin.conf ${SEAETCDIR}/admin.old
fi
mv ${SEAETCDIR}/admin.temp ${SEAETCDIR}/admin.conf

##########################################################################
# Copy properties files into etc directories, update base directory property.

echo "Updating base directory in AdminClient.properties"
echo "/admin.base.dir/c\\
admin.base.dir=${SEABASE}
" > /tmp/sed
sed -f /tmp/sed ${SEABASE}/etc/AdminClient.properties > ${SEAETCDIR}/client/AdminClient.properties
rm -f /tmp/sed

echo "Updating base directory in AdminServer.properties"
echo "/admin.base.dir/c\\
admin.base.dir=${SEABASE}
" > /tmp/sed
sed -f /tmp/sed ${SEABASE}/etc/AdminServer.properties > ${SEAETCDIR}/server/AdminServer.properties
rm -f /tmp/sed

##########################################################################
# Copy server daemon start/stop script into /etc/init.d
# Set boot time start and stop links in /etc/rc3.d
# We append the version number to the script and link names!

echo "Setting up init.d start/stop script and links..."
MSVR=admsvr${VERSIONDIR}
    cp $SEABASE/sbin/admsvr /etc/init.d/${MSVR}
    chmod 755 /etc/init.d/${MSVR}

if [ ! -f /etc/rc3.d/S83admsvr${VERSIONDIR} ]
  then
    ln -s  /etc/init.d/${MSVR} /etc/rc3.d/S83admsvr${VERSIONDIR}
fi

if [ ! -f /etc/rc3.d/K83admsvr${VERSIONDIR} ]
  then
    ln -s  /etc/init.d/${MSVR} /etc/rc3.d/K83admsvr${VERSIONDIR}
fi

if [ "$?" != "0" ]; then
    echo "AdminSuite installation failed"
    exit 1
fi

###########################################################################################
# Register with the SMC application registry, if its installed

if [ -x /usr/sadm/smc/lib/smcappadm ]; then
	echo "Registering with the Solaris Management Console..."
	/usr/sadm/smc/lib/smcappadm -R -n "AdminSuite"   -b "$SEABASE/bin/admapp" -t XAPP -c "Infrastructure" -p user -i /usr/sadm/smc/images/xapp.gif
else
	echo "AdminSuite cannot be registered with the Solaris Management Console"
fi


#################################################################################################################
## Done
exit 0
