#!/bin/ksh -p
# $ID$

# Source Common Functions
. ${EXP_HOME}/lib/exp_tools

# Source the sunone functions
. ${EXP_HOME}/lib/exp_sunone

EXP_VERSION=4.0

which_gate_exit $script
# Run if specified to do so
if [ -z ${EXP_IPLANET} ]
then
	script=${0##*/}
	ln -s ${EXP_TARGET}/sunone ${EXP_TARGET}/iplanet
else
	script=iplanet
fi

run_app_collection () {

   (( i = i + 1 ))
   SERVER_ROOT=${i_array[${i}]}
   SERVER_ROOT2=`echo $SERVER_ROOT |sed 's/\//_/g'|sed 's/_//'`

   # Gather Version information
   # Application Server 6.0
   if [[ -d ${SERVER_ROOT}/ias ]]
   then
      get_cmd "${SERVER_ROOT}/ias/bin/version"		sunone/Application/${SERVER_ROOT2}/version_info/version
      get_cmd "${SERVER_ROOT}/ias/usr/java/bin/java -fullversion"	sunone/Application/${SERVER_ROOT2}/version_info/java_version
      get_file "${SERVER_ROOT}/ias/bin/beanreg"		sunone/Application/${SERVER_ROOT2}/deploy_scripts

      # Script files from the Application Server
      get_file "${SERVER_ROOT}/ias/bin/kjs"		sunone/Application/${SERVER_ROOT2}/process_scripts
      get_file "${SERVER_ROOT}/ias/bin/kxs"		sunone/Application/${SERVER_ROOT2}/process_scripts
      get_file "${SERVER_ROOT}/ias/bin/kas"		sunone/Application/${SERVER_ROOT2}/process_scripts
      get_file "${SERVER_ROOT}/ias/bin/kcs"		sunone/Application/${SERVER_ROOT2}/process_scripts

      # Environment script:
      get_file "${SERVER_ROOT}/ias/env/iasenv.ksh"	sunone/Application/${SERVER_ROOT2}/envionment_script

      # Starting and stopping of Application Server
      get_file "${SERVER_ROOT}/ias/bin/iascontrol"	sunone/Application/${SERVER_ROOT2}/startstop_scripts
      get_file "${SERVER_ROOT}/ias/bin/KIVAes.sh"	sunone/Application/${SERVER_ROOT2}/startstop_scripts

      # Registry File
      get_file "${SERVER_ROOT}/ias/registry/reg.dat"	sunone/Application/${SERVER_ROOT2}/registry_files
      get_file "${SERVER_ROOT}/ias/bin/kregedit"	sunone/Application/${SERVER_ROOT2}/registry_scripts
      get_file "${SERVER_ROOT}/ias/bin/kreg"		sunone/Application/${SERVER_ROOT2}/registry_scripts

      # Deploy Files
      get_file "${SERVER_ROOT}/ias/bin/j2eeappreg"	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/ias/bin/iasdeploy"	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/ias/bin/resreg"	   	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/ias/bin/beanreg"	   	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/ias/bin/dsreg"		sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/ias/bin/servletReg.sh"	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/ias/bin/ejbreg"	   	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/ias/bin/redeploy"	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/ias/bin/webappreg"	sunone/Application/${SERVER_ROOT2}/deploy_scripts

      # Migration Scripts
      get_file "${SERVER_ROOT}/ias/bin/convertNtv2Xml"	sunone/Application/${SERVER_ROOT2}/migration_scripts
      get_file "${SERVER_ROOT}/ias/bin/convertProps2Xml"	sunone/Application/${SERVER_ROOT2}/migration_scripts

      # Compilation Scripts
      get_file "${SERVER_ROOT}/ias/bin/ejbc"		sunone/Application/${SERVER_ROOT2}/compilation_scripts

      # Scripts Associated with Tools
      get_file "${SERVER_ROOT}/ias/bin/deploycmd"	sunone/Application/${SERVER_ROOT2}/tools_scripts
      get_file "${SERVER_ROOT}/ias/bin/ksvradmin"	sunone/Application/${SERVER_ROOT2}/tools_scripts
      get_file "${SERVER_ROOT}/ias/bin/deploytool"	sunone/Application/${SERVER_ROOT2}/tools_scripts
      get_file "${SERVER_ROOT}/ias/bin/redeploy"	sunone/Application/${SERVER_ROOT2}/tools_scripts

      # Registry Dump
      ${SERVER_ROOT}/ias/bin/kreg -save ${EXP_TARGET}/sunone/Application/${SERVER_ROOT2}/registry_files/registry_dump \SOFTWARE

      # Library Files
      get_cmd "/usr/bin/sum ${SERVER_ROOT}/ias/gxlib/*"  	sunone/Application/${SERVER_ROOT2}/lib_checksums/gxlib_checksums

      # Jar Files
      get_cmd "/usr/bin/sum ${SERVER_ROOT}/ias/classes/java/*"	  	sunone/Application/${SERVER_ROOT2}/lib_checksums/jar_checksums
      get_cmd "/usr/bin/sum ${SERVER_ROOT}/ias/java/jars/ias60.jar"	sunone/Application/${SERVER_ROOT2}/lib_checksums/ias60.jar_checksum

   fi
	
   # Netscape Application Server 4.0
   if [[ -d ${SERVER_ROOT}/nas ]]
   then
      get_cmd "${SERVER_ROOT}/nas/bin/version"		sunone/Application/${SERVER_ROOT2}/version_info/version
      get_cmd "${SERVER_ROOT}/nas/usr/java/bin/java -fullversion"	sunone/Application/${SERVER_ROOT2}/version_info/java_version

      # Script files from the Application Server
      get_file "${SERVER_ROOT}/nas/bin/kjs"		sunone/Application/${SERVER_ROOT2}/process_scripts
      get_file "${SERVER_ROOT}/nas/bin/kxs"		sunone/Application/${SERVER_ROOT2}/process_scripts
      get_file "${SERVER_ROOT}/nas/bin/kas"		sunone/Application/${SERVER_ROOT2}/process_scripts
      get_file "${SERVER_ROOT}/nas/bin/kcs"		sunone/Application/${SERVER_ROOT2}/process_scripts

      # Environment script:
      get_file "${SERVER_ROOT}/nas/env/iasenv.ksh"	sunone/Application/${SERVER_ROOT2}/envionment_script

      # Starting and stopping of Application Server
      get_file "${SERVER_ROOT}/nas/bin/iascontrol"	sunone/Application/${SERVER_ROOT2}/startstop_scripts
      get_file "${SERVER_ROOT}/nas/bin/KIVAes.sh"	sunone/Application/${SERVER_ROOT2}/startstop_scripts

      # Registry File
      get_file "${SERVER_ROOT}/nas/registry/reg.dat"	sunone/Application/${SERVER_ROOT2}/registry_files
      get_file "${SERVER_ROOT}/nas/bin/kregedit"	sunone/Application/${SERVER_ROOT2}/registry_scripts
      get_file "${SERVER_ROOT}/nas/bin/kreg"		sunone/Application/${SERVER_ROOT2}/registry_scripts

      # Deploy Files
      get_file "${SERVER_ROOT}/nas/bin/j2eeappreg"	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/nas/bin/iasdeploy"	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/nas/bin/beanreg"		sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/nas/bin/resreg"	   	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/nas/bin/dsreg"		sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/nas/bin/servletReg.sh"	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/nas/bin/ejbreg"	   	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/nas/bin/redeploy"   	sunone/Application/${SERVER_ROOT2}/deploy_scripts
      get_file "${SERVER_ROOT}/nas/bin/webappreg"   	sunone/Application/${SERVER_ROOT2}/deploy_scripts

      # Migration Scripts
      get_file "${SERVER_ROOT}/nas/bin/convertNtv2Xml"   	sunone/Application/${SERVER_ROOT2}/migration_scripts
      get_file "${SERVER_ROOT}/nas/bin/convertProps2Xml"   	sunone/Application/${SERVER_ROOT2}/migration_scripts

      # Compilation Scripts
      get_file "${SERVER_ROOT}/nas/bin/ejbc"	   	sunone/Application/${SERVER_ROOT2}/compilation_scripts

      # Scripts Associated with Tools
      get_file "${SERVER_ROOT}/nas/bin/deploycmd"	      	sunone/Application/${SERVER_ROOT2}/tools_scripts
      get_file "${SERVER_ROOT}/nas/bin/ksvradmin"	      	sunone/Application/${SERVER_ROOT2}/tools_scripts
      get_file "${SERVER_ROOT}/nas/bin/deploytool"	      	sunone/Application/${SERVER_ROOT2}/tools_scripts
      get_file "${SERVER_ROOT}/nas/bin/redeploy"	      	sunone/Application/${SERVER_ROOT2}/tools_scripts
      get_file "${SERVER_ROOT}/nas/bin/deployGUI"	      	sunone/Application/${SERVER_ROOT2}/tools_scripts
    
      # Registry Dump
      ${SERVER_ROOT}/nas/bin/kreg -save ${EXP_TARGET}/sunone/Application/${SERVER_ROOT2}/registry_files/registry_dump \SOFTWARE

      # Library Files
      get_cmd "/usr/bin/sum ${SERVER_ROOT}/nas/gxlib/*"  	sunone/Application/${SERVER_ROOT2}/lib_checksums/gxlib_checksums

      # Jar Files
      get_cmd "/usr/bin/sum ${SERVER_ROOT}/nas/classes/java/*"	  	sunone/Application/${SERVER_ROOT2}/lib_checksums/jar_checksums

   fi

   # Netscape Application Server 4.0 and its service packs.
   if [[ -d ${SERVER_ROOT}/nas ]]
   then
      get_file "${SERVER_ROOT}/nas/userinput.log"			sunone/Application/${SERVER_ROOT2}/userinputlog
      get_file "${SERVER_ROOT}/nas/java/jars/nas40.jar"			sunone/Application/${SERVER_ROOT2}
	 
      get_cmd "/usr/bin/sum ${SERVER_ROOT}/nas/java/jars/nas40.jar"	sunone/Application/${SERVER_ROOT2}/lib_checksums/nas40.jar_checksum
      get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/nas/logs/kas.log"	sunone/Application/${SERVER_ROOT2}/logs/kas.log
      for FILE in `ls -1 ${SERVER_ROOT}/nas/logs`
      do
	 case $FILE in
	 k?s*)
	    get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/nas/logs/${FILE}"	sunone/Application/${SERVER_ROOT2}/logs/${FILE}.log
	    ;;
	 *)
	    ;;
	    esac
      done
   fi

   # iPlanet Application Server 6.0 and it's service packs.
   get_file "${SERVER_ROOT}/ias/userinput.log"		sunone/Application/${SERVER_ROOT2}
   get_file "${SERVER_ROOT}/ias/classes/java/ias60.jar"	sunone/Application/${SERVER_ROOT2}

   # Log files
   get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/ias/logs/ias.log"	sunone/Application/${SERVER_ROOT2}/logs/ias.log
   for FILE in `ls -1 ${SERVER_ROOT}/ias/logs`
   do
      case $FILE in
      k?s*)
	 get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/ias/logs/${FILE}"	sunone/Application/${SERVER_ROOT2}/logs/${FILE}.log
	 ;;
      *)
	 ;;
	 esac
   done

   (( i = i + 1 ))
   while [[ ${i_array[${i}]} != "" ]]
   do
      # Get the config and log files for each instance
      INSTANCE=${i_array[${i}]}
      get_dir "${SERVER_ROOT}/${INSTANCE}/config"	sunone/Application/${SERVER_ROOT2}/${INSTANCE}/config
      get_dir "${SERVER_ROOT}/${INSTANCE}/logs"		sunone/Application/${SERVER_ROOT2}/${INSTANCE}/logs
      get_file "${SERVER_ROOT}/${INSTANCE}/start*"	sunone/Application/${SERVER_ROOT2}/${INSTANCE}
      (( i = i + 1 ))
   done
}

run_portal_collection () {

   (( i = i + 1 ))
   SERVER_ROOT=${i_array[${i}]}
   SERVER_ROOT2=`echo $SERVER_ROOT |sed 's/\//_/g'|sed 's/_//'`

   # Get the server root from the package installation, and compare to the config file
   INSTALL_SERVER_ROOT=`/usr/bin/egrep ips.basedir /etc/opt/SUNWips/platform.conf |cut -f2 -d"="`
   if [[ SERVER_ROOT != INSTALL_SERVER_ROOT ]]
   then
      # config file and installed server root do not match, using
      # installed server root.
      SERVER_ROOT=${INSTALL_SERVER_ROOT}
   fi

   # Try and grab the Java Home from the server...
   J_HOME=`grep "NSES_JDK" ${SERVER_ROOT2}/netscape/server4/https-admserv/start-jvm | cut -f2 -d= | cut -f1 -d";"`
   if [[ ! -z $J_HOME ]]
   then
	   get_cmd "${J_HOME}/bin/java -fullversion"	sunone/Portal/${SERVER_ROOT2}/java_version
   fi

   get_dir recursive "${SERVER_ROOT}/SUNWips/lib"	sunone/Portal/${SERVER_ROOT2}/ips_lib_jar

   get_dir recursive "/etc/opt/SUNWips/cert"	sunone/Portal/${SERVER_ROOT2}/ips_cert
   get_file "/etc/opt/SUNWips/.wtpass"		sunone/Portal/${SERVER_ROOT2}/etc_opt_SUNWips
   get_file "/etc/opt/SUNWips/.application"	sunone/Portal/${SERVER_ROOT2}/etc_opt_SUNWips
   get_file "/etc/opt/SUNWips/.version"		sunone/Portal/${SERVER_ROOT2}/etc_opt_SUNWips
   get_file "/etc/opt/SUNWips/.version-orig"	sunone/Portal/${SERVER_ROOT2}/etc_opt_SUNWips
   get_file "/etc/opt/SUNWips/platform.conf"	sunone/Portal/${SERVER_ROOT2}/config_files
   get_cmd "/bin/ls -alr /etc/opt/SUNWips/cert"	sunone/Portal/${SERVER_ROOT2}/cert/ls-alr

   # Startup scripts in the ${SERVER_ROOT}/SUNWips/bin directory
   get_file "${SERVER_ROOT}/SUNWips/bin/ipsnetletd"	sunone/Portal/${SERVER_ROOT}/startup_scripts
   get_file "${SERVER_ROOT}/SUNWips/bin/ipshttpd"	sunone/Portal/${SERVER_ROOT}/startup_scripts

   # Startup scripts in the /etc directory
   get_file "/etc/S*ipsserver"			sunone/Portal/${SERVER_ROOT2}/startup_scripts
   get_file "/etc/init.d/ipsgateway"		sunone/Portal/${SERVER_ROOT2}/startup_scripts
   get_file "/etc/init.d/ipsserver"		sunone/Portal/${SERVER_ROOT2}/startup_scripts
   get_file "/etc/init.d/ipsnetletd"		sunone/Portal/${SERVER_ROOT2}/startup_scripts
   get_file "/etc/init.d/ipshttpd"		sunone/Portal/${SERVER_ROOT2}/startup_scripts
   get_file "/etc/coreadm.conf"			sunone/Portal/${SERVER_ROOT2}
   get_file "/etc/named.pid"			sunone/Portal/${SERVER_ROOT2}
   get_file "/etc/dumpadm.conf"			sunone/Portal/${SERVER_ROOT2}
   get_file "/etc/system"			sunone/Portal/${SERVER_ROOT2}

   get_dir recursive "/etc/opt/SUNWips/auth"	sunone/Portal/${SERVER_ROOT2}/etc_opt_SUNWips_auth
   get_dir recursive "/etc/opt/SUNWips/xml"	sunone/Portal/${SERVER_ROOT2}/etc_opt_SUNWips_xml
   get_file "/etc/opt/SUNWips/properties.file"	sunone/Portal/${SERVER_ROOT2}/etc_opt_SUNWips
   get_file "/etc/opt/SUNWips/platform.*"	sunone/Portal/${SERVER_ROOT2}/etc_opt_SUNWips

   get_dir recursive "/etc/qlog"		sunone/Portal/${SERVER_ROOT2}/qlog
   get_dir recursive "/etc/cron.d"		sunone/Portal/${SERVER_ROOT2}/cron.d
   get_dir recursive "/etc/dfs"			sunone/Portal/${SERVER_ROOT2}/dfs
   get_dir recursive "/etc/saf"			sunone/Portal/${SERVER_ROOT2}/saf
   get_dir recursive "/var/opt/SUNWips"		sunone/Portal/${SERVER_ROOT2}/var_opt_SUNWips
   get_dir recursive "/var/sadm/install/logs"	sunone/Portal/${SERVER_ROOT2}/var_sadm_install_logs

   JAVA_HOME=`/usr/bin/egrep NSES_JDK= start-jvm|cut -f2 -d=|cut -f1 -d";"`
   get_cmd "${JAVA_DIR}/bin/java -fullversion"				sunone/Portal/${SERVER_ROOT2}/version_info/java_version
   get_cmd "${SERVER_ROOT}/SUNWips/bin/ipsadmin get component iplanet.com"	sunone/Portal/${SERVER_ROOT2}/ips_component/domain.xml
   get_cmd "${SERVER_ROOT}/SUNWips/bin/ipsadmin get component iwtGateway"	sunone/Portal/${SERVER_ROOT2}/ips_component/iwtGateway.xml
   get_cmd "${SERVER_ROOT}/SUNWips/bin/ipsserver version"			sunone/Portal/${SERVER_ROOT2}/version_info/version

   get_dir recursive "${SERVER_ROOT}/SUNWips/public_html"		sunone/Portal/${SERVER_ROOT2}/public_html
   get_cmd "/bin/ls -l ${SERVER_ROOT}/SUNWips/public_html"		sunone/Portal/${SERVER_ROOT2}/public_html-ls-l
   get_cmd "/bin/ls -lrt /etc/opt/SUNWips"				sunone/Portal/${SERVER_ROOT2}/etc_opt_SUNWips/ls-lrt

   get_cmd "${SERVER_ROOT}/netscape/directory4/slapd-`hostname`/db2ldif explorer_ldif"	sunone/Portal/${SERVER_ROOT2}/db2ldif
   get_file "${SERVER_ROOT}/netscape/directory4/bin/slapd/server/explorer_ldif"		sunone/Portal/${SERVER_ROOT2}/db2ldif

   # Log files
   for FILE in `ls -1 /var/opt/SUNWips/debug`
   do
      get_cmd "/usr/bin/tail -2000 /var/opt/SUNWips/debug/${FILE}"	sunone/Portal/${SERVER_ROOT2}/logs/${FILE}.log
   done
	
   for FILE in `ls -1 /var/opt/SUNWips/auth`
   do
      get_cmd "/usr/bin/tail -2000 /var/opt/SUNWips/auth/${FILE}"	sunone/Portal/${SERVER_ROOT2}/logs/${FILE}.log
   done
	
   for FILE in `ls -1 /var/opt/SUNWips/logs`
   do
      get_cmd "/usr/bin/tail -2000 /var/opt/SUNWips/logs/${FILE}"	sunone/Portal/${SERVER_ROOT2}/logs/${FILE}.log
   done

   # Portal instances...
   (( i = i + 1 ))
   while [[ ${i_array[${i}]} != "" ]]
   do
      INSTANCE=${i_array[${i}]}
      if [[ ${INSTANCE} == "https-admserv" ]]
      then
	 NET_DIR="netscape/server4"
	 get_file "${SERVER_ROOT}/${NET_DIR}/${INSTANCE}/start-jvm"		sunone/Portal/${SERVER_ROOT2}/${INSTANCE}
	 get_file "${SERVER_ROOT}/${NET_DIR}/${INSTANCE}/start"			sunone/Portal/${SERVER_ROOT2}/${INSTANCE}
	 get_dir recursive "${SERVER_ROOT}/${NET_DIR}/${INSTANCE}/config/"	sunone/Portal/${SERVER_ROOT2}/${INSTANCE}/config
	 get_dir recursive "${SERVER_ROOT}/${NET_DIR}/${INSTANCE}/logs/"	sunone/Portal/${SERVER_ROOT2}/${INSTANCE}/logs
      else
         # Get the config and log files for each instance
         NET_DIR="netscape/server4"
	 get_file "${SERVER_ROOT}/${NET_DIR}/${INSTANCE}/start"			sunone/Portal/${SERVER_ROOT2}/${INSTANCE}
	 get_dir recursive "${SERVER_ROOT}/${NET_DIR}/${INSTANCE}/config/"   	sunone/Portal/${SERVER_ROOT2}/${INSTANCE}/config
	 get_dir recursive "${SERVER_ROOT}/${NET_DIR}/${INSTANCE}/logs/"	sunone/Portal/${SERVER_ROOT2}/${INSTANCE}/logs
	 NET_DIR="netscape/directory4"
	 get_file "${SERVER_ROOT}/${NET_DIR}/${INSTANCE}/start"			sunone/Portal/${SERVER_ROOT2}/${INSTANCE}
	 get_dir recursive "${SERVER_ROOT}/${NET_DIR}/${INSTANCE}/config/"   	sunone/Portal/${SERVER_ROOT2}/${INSTANCE}/config
	 get_dir recursive "${SERVER_ROOT}/${NET_DIR}/${INSTANCE}/logs/"	sunone/Portal/${SERVER_ROOT2}/${INSTANCE}/logs
      fi
      (( i = i + 1 ))
   done
}

run_web_collection () {

   (( i = i + 1 ))
   SERVER_ROOT=${i_array[${i}]}
   SERVER_ROOT2=`echo $SERVER_ROOT |sed 's/\//_/g'|sed 's/_//'`

   # Gather the version information
   # For iWS 4.x, 6.x:
   OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
   LD_LIBRARY_PATH=${SERVER_ROOT}/bin/https/lib
   get_cmd "${SERVER_ROOT}/bin/https/bin/ns-httpd -v"		sunone/Web/${SERVER_ROOT2}/version

   # Config and log files...
   (( i = i + 1 ))
   while [[ ${i_array[${i}]} != "" ]]
   do
      # Get the config and log files for each instance
      INSTANCE=${i_array[${i}]}
      if [[ ${INSTANCE} == "https-admserv" ]]
      then
	 get_file "${SERVER_ROOT}/${INSTANCE}/start-jvm"	sunone/Web/${SERVER_ROOT2}/${INSTANCE}
	 get_file "${SERVER_ROOT}/${INSTANCE}/start"		sunone/Web/${SERVER_ROOT2}/${INSTANCE}
	 get_dir recursive "${SERVER_ROOT}/${INSTANCE}/config/" sunone/Web/${SERVER_ROOT2}/${INSTANCE}/config
	 get_dir recursive "${SERVER_ROOT}/${INSTANCE}/logs/"	sunone/Web/${SERVER_ROOT2}/${INSTANCE}/logs
      else
	 get_dir recursive "${SERVER_ROOT}/${INSTANCE}/config/"	sunone/Web/${SERVER_ROOT2}/${INSTANCE}/config
	 get_file "${SERVER_ROOT}/${INSTANCE}/start"		sunone/Web/${SERVER_ROOT2}/${INSTANCE}
	 get_dir recursive "${SERVER_ROOT}/${INSTANCE}/logs/"	sunone/Web/${SERVER_ROOT2}/${INSTANCE}/logs
      fi
      (( i = i + 1 ))
   done
   get_file "${SERVER_ROOT}/httpacl/*"				sunone/Web/${SERVER_ROOT2}/
   get_file "${SERVER_ROOT}/userdb/*"				sunone/Web//${SERVER_ROOT2}
   LD_LIBRARY_PATH=${OLD_LD_LIBRARY_PATH}

}


run_directory_collection () {

   OLD_LD_LIBRARY_PATH=${LD_LIBRARY_PATH}
   (( i = i + 1 ))
   SERVER_ROOT=${i_array[${i}]}
   SERVER_ROOT2=`echo $SERVER_ROOT |sed 's/\//_/g'|sed 's/_//'`

   LD_LIBRARY_PATH=${SERVER_ROOT}/lib:${SERVER_ROOT}/bin/slapd/lib:${LD_LIBRARY_PATH}
   (( i = i + 1 ))
   while [[ ${i_array[${i}]} != "" ]]
   do
      INSTANCE=${i_array[${i}]}
      # Find the version information
      # iPlanet Directory Server 4.15
      get_cmd "/usr/bin/egrep ersion ${SERVER_ROOT}/${INSTANCE}/log/default/default"	sunone/Directory/${SERVER_ROOT2}/${INSTANCE}/version
      get_cmd "${SERVER_ROOT}/${INSTANCE}/configutil"				sunone/Directory/${SERVER_ROOT2}/${INSTANCE}/configutil

      # iPlanet Directory Server 4.16
      get_cmd "${SERVER_ROOT}/bin/slapd/server/ns-slapd -V -f ${SERVER_ROOT}/${INSTANCE}/config/slapd.conf"	sunone/Directory/${SERVER_ROOT2}/${INSTANCE}/version

      # iPlanet Directory Server 5.0 & 5.1
      get_cmd "${SERVER_ROOT}/bin/slapd/server/ns-slapd -D ${SERVER_ROOT}/${INSTANCE} -V"	sunone/Directory/${SERVER_ROOT2}/${INSTANCE}/version
      get_dir recursive "${SERVER_ROOT}/shared/config"				sunone/Directory/${SERVER_ROOT2}/shared/config
      get_dir recursive "${SERVER_ROOT}/${INSTANCE}/config"			sunone/Directory/${SERVER_ROOT2}/${INSTANCE}/config
      get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/${INSTANCE}/logs/error"	sunone/Directory/${SERVER_ROOT2}/${INSTANCE}/logs/error
      get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/${INSTANCE}/logs/access"	sunone/Directory/${SERVER_ROOT2}/${INSTANCE}/logs/access
      (( i = i + 1 ))
   done

   # iPlanet Directory Server pre-4.16
   get_dir recursive "${SERVER_ROOT}/${INSTANCE}/config"			sunone/Directory/${SERVER_ROOT2}/${INSTANCE}/config
   get_dir recursive "${SERVER_ROOT}/shared/config"				sunone/Directory/${SERVER_ROOT2}/shared/config
   LD_LIBRARY_PATH=${OLD_LD_LIBRARY_PATH}

}


run_messaging_collection () {

   (( i = i + 1 ))
   SERVER_ROOT=${i_array[${i}]}
   SERVER_ROOT2=`echo $SERVER_ROOT |sed 's/\//_/g'|sed 's/_//'`

   (( i = i + 1 ))
   while [[ ${i_array[${i}]} != "" ]]
   do
      if [[ -d ${SERVER_ROOT}/${INSTANCE} ]]
      then
	 INSTANCE=${i_array[${i}]}
	 # Find the version information
	 # Check for version 4.15
	 if [[ -f ${SERVER_ROOT}/${INSTANCE}/log/default/default ]]
	 then
	    get_cmd "/usr/bin/egrep -e starting ${SERVER_ROOT}/${INSTANCE}/log/default/default*"	sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/version
	 fi

	 # Get the log files
	 if [[ "${INSTANCE}" != admin-serv ]]
	 then
	    get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/${INSTANCE}/log/default/default"	sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/log/default/default
	    get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/${INSTANCE}/log/http/http"	sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/log/http.log
	    get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/${INSTANCE}/log/imap/imap"	sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/log/imap.log
	    get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/${INSTANCE}/log/pop/pop"	sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/log/pop.log
	    if [[ -d ${SERVER_ROOT}/${INSTANCE}/log/smtp ]]
	    then
	       get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/${INSTANCE}/log/smtp/smtp"	sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/log/smtp.log
	    fi

	    if [[ -d ${SERVER_ROOT}/${INSTANCE}/log/imta ]]
	    then
	       get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/${INSTANCE}/log/imta/mail.log_current"	sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/log/mail.log_current
	    fi
	 fi

	 # Check for version 5.0, 5.1, & 5.2
	 if [[ -f ${SERVER_ROOT}/${INSTANCE}/imsimta ]]
	 then
	    get_cmd "${SERVER_ROOT}/${INSTANCE}/imsimta version"	sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/version
	    # Config information
	    get_cmd "${SERVER_ROOT}/${INSTANCE}/configutil"		sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/config
	    get_dir recursive "${SERVER_ROOT}/${INSTANCE}/imta/config"	sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/imta/config
	    get_cmd "/usr/bin/tail -2000 ${SERVER_ROOT}/${INSTANCE}/imta/mail.log_current"	sunone/Messaging/${SERVER_ROOT2}/${INSTANCE}/imta/mail.log_current
	 fi
      fi
      (( i = i + 1 ))
   done
   get_dir recursive "${SERVER_ROOT}/shared/config"		sunone/Messaging/${SERVER_ROOT2}/shared/config
}


# Main Routine
# Check for config file and bail out if not found.
if [[ ! -f ${EXP_ETC}/${script}.config ]]
then
   TEXT=`gettext "${EXP_ETC}/${script}.config file not found!"`
   logfile FATAL ${TEXT}
   echo_file ${script}/NOT_CONFIGURED "${EXP_ETC}/${script}.config file not found!"
   exit 1
fi

# validate the config file.
validate_iconfig ${EXP_ETC}/${script}.config

# The config file will be in an array from the validation function
# parse the array and get the type of product (web, app, etc)
# and run the commands for each particular type of product.

i=0
while (( ${i} < ${#i_array[*]} ))
do
   case ${i_array[${i}]} in
   Application)
      run_app_collection
      ;;
   Portal)
      run_portal_collection
      ;;
   Messaging)
      run_messaging_collection
      ;;
   Web)
      run_web_collection
      ;;
   Directory)
      run_directory_collection
      ;;
   *)
      (( i = i + 1 ))
      continue
      ;;
   esac
   (( i = i + 1 ))
done
