#!/bin/sh

# Copyright  2004 Sun Microsystems, Inc. All rights reserved. 
# 
# Sun Microsystems, Inc. has intellectual property rights relating to
# technology embodied in the product that is described in this document.
# In particular, and without limitation, these intellectual property rights
# may include one or more of the U.S. patents listed at
# http://www.sun.com/patents and one or more additional patents or pending
# patent applications in the U.S. and in other countries.
# 
# U.S. Government Rights - Commercial software. Government users are subject
# to the Sun Microsystems, Inc. standard license agreement and applicable
# provisions of the FAR and its supplements.
# 
# Use is subject to license terms. 
# 
# This distribution may include materials developed by third parties. Sun,
# Sun Microsystems, the Sun logo, Java and Sun[tm] ONE are trademarks or
# registered trademarks of Sun Microsystems, Inc. in the U.S. and other
# countries. 
# 
# Copyright  2004 Sun Microsystems, Inc. Tous droits rservs. Sun
# Microsystems, Inc. dtient les droits de proprit intellectuels relatifs
#  la technologie incorpore dans le produit qui est dcrit dans ce document.
# En particulier, et ce sans limitation, ces droits de proprit
# intellectuelle peuvent inclure un ou plus des brevets amricains lists
#  l'adresse http://www.sun.com/patents et un ou les brevets supplmentaires
# ou les applications de brevet en attente aux Etats - Unis et dans les
# autres pays.
# 
# L'utilisation est soumise aux termes du contrat de licence.
# 
# Cette distribution peut comprendre des composants dvelopps par des
# tierces parties.
# 
# Sun, Sun Microsystems, le logo Sun, Java et Sun[tm] ONE sont des marques
# de fabrique ou des marques dposes de Sun Microsystems, Inc. aux
# Etats-Unis et dans d'autres pays.

prepareDirectoryTuner() {
    $ECHO `gettext "Preparing Directory Server Tuner..."`
    $ECHO $LINE_SEP
    $ECHO `gettext "Determining Current Settings..."`

    ROOT_SUFFIX=`getConfigEntry "com.iplanet.am.rootsuffix"`
    DS_INSTANCE_DIR=`getInstanceDir`

    tmp_file=/tmp/amtune-directory
    $ECHO `gettext "Creating Directory Server Tuner tar file: $tmp_file"`

    $CP $SCRIPT_LOCATION/amtune-directory.template $tmp_file
    replace_line $tmp_file "DEBUG_FILE="                "DEBUG_FILE=$AMTUNE_DEBUG_FILE_PREFIX-\`\$DATE +'%Y%m%d'\`-\$$"
    replace_line $tmp_file "DS_HOST="                   "DS_HOST='$DS_HOST'"
    replace_line $tmp_file "DS_PORT="                   "DS_PORT='$DS_PORT'"
    replace_line $tmp_file "ROOT_SUFFIX="               "ROOT_SUFFIX='$ROOT_SUFFIX'"
    replace_line $tmp_file "DIRMGR_UID="                "DIRMGR_UID='$DIRMGR_UID'"
    replace_line $tmp_file "RAM_DISK="                  "RAM_DISK='$RAM_DISK'"
    replace_line $tmp_file "DS_INSTANCE_DIR="           "DS_INSTANCE_DIR='$DS_INSTANCE_DIR'"

    $CP $SCRIPT_LOCATION/../../share/bin/amtune/amtune-utils /tmp/amtune-utils
    $CP $SCRIPT_LOCATION/../amutils /tmp/amutils
    $TAR -cvf /tmp/amtune-directory.tar /tmp/amtune-directory /tmp/amtune-utils /tmp/amutils
    $RM /tmp/amtune-utils
    $RM /tmp/amutils
    $RM /tmp/amtune-directory

    $ECHO 
    $ECHO `gettext "Directory Server Tuner tar file: $tmp_file"`
    $ECHO `gettext "Steps to tune directory server:"`
    $ECHO `gettext "1.  Copy the DS Tuner tar to the DS System"`
    $ECHO `gettext "2.  Untar the DS Tuner in a temporary location"`
    $ECHO `gettext "3.  Execute the following script in 'REVIEW' mode : amtune-directory"`
    $ECHO `gettext "4.  Review carefully the recommended tunings for DS"`
    $ECHO `gettext "5.  If you are sure of applying these changes to DS, modify the following lines in amtune-directory"`
    $ECHO `gettext "    a.  AMTUNE_MODE="`
    $ECHO `gettext "    b.  DEBUG_FILE="`
    $ECHO `gettext "Its highly recommended to run db2bak before running amtune-directory"`
    $ECHO 
    $ECHO 
}
#############################################################################
# Start of main program
#############################################################################
SCRIPT_LOCATION=`dirname $0`

# import the environment
if [ -f $SCRIPT_LOCATION/amtune-env ]; then
    if [ ! "$INIT_STATUS" = "INIT_COMPLETE" ]; then
        . $SCRIPT_LOCATION/amtune-env
    fi
fi

$ECHO "IS - Directory Server Tuner Preparation Script"      1>>$DEBUG_FILE 2>&1

prepareDirectoryTuner                                       1>>$DEBUG_FILE 2>&1

$ECHO $PARA_SEP                                             1>>$DEBUG_FILE 2>&1
