#! /bin/ksh
#::
#:: Host Publisher Problem Determination Bundling Tool - HPPDTOOL
#::
#:: Next Message - HPP1086
echo "."
echo "Host Publisher Problem Determination Bundling Tool - v2.0"
echo "(C) Copyright IBM Corp. 2000,2001. All Rights Reserved."
echo "."
echo "HPP1055I: This tool will gather and bundle product application files"
echo "          for problem determination purposes.  These files may contain"
echo "          sensitive customer information.  Cancel this tool if you do not "
echo "          wish to disclose any sensitive customer information.  Contact"
echo "          your service representative for more information."
echo "."
if [[ $1 = "" ]]
then 
   echo "HPP1039I: You must specify the Host Publisher root directory"
   echo "."
   echo "   Usage: hppdtool hostpubliser_root [ websphere_appserver_root [ java_root ] ]"
   echo "Examples: hppdtool /"
   echo "        : hppdtool /  /  /usr/myJDK"
   echo "        : hppdtool /  /myWebSphere  /usr/myJDK"
   echo "        : hppdtool /var/HostPublisher"
   exit 1
fi

echo "HPP1074R: Make sure WebSphere Application Server is running."
echo "HPP1056R: Press Control-C to cancel this tool."
echo "."

echo "Press ENTER to continue . . ."
read userResponse


#:STEP_000
#::---------------------------------------------
#:: Setup - 
#::---------------------------------------------
hppdTmp_P1=$1
hppdTmp_P2=$2

if [[ $2 = "/" ]] 
then 
hppdTmp_P2=""
fi
if [[ $2 = "." ]] 
then 
hppdTmp_P2=""
fi

if [[ $1 = "/" ]] 
then 
hppdTmp_P1="/."
fi
if [[ $1 = "." ]] 
then 
hppdTmp_P1="/."
fi

CURRENTDIR=`pwd`
hppdTmp_HP_ROOT=$hppdTmp_P1
hppdTmp_HP_STUDIO=$hppdTmp_P1"/Studio"
hppdTmp_HP_COMMON=$hppdTmp_P1"/Common"
hppdTmp_HP_LOG=$hppdTmp_P1"/log"
hppdTmp_JDK_ROOT=
hppdTmp_WAS_ROOT=
hppdTmp_TEMPDIR=$CURRNTDIR"/hppdTmp"
hppdTmp_TEMPDIR_MVS="/tmp/hppdTmp"
hppdTmp_IS_MVS="0"
hppdTmp_JDK_JAR_EXE=
hppdTmp_JDK_JAR_EXE_ORG=
hppdTmp_HP_VAR_DIR=
hppdTmp_HP_LPP_DIR=
#::---------------------------------------------

#::---------------------------------------------
#::---------------------------------------------
if [[ $2 = "/" ]] 
then 
hppdTmp_P2=""
fi
if [[ $2 = "." ]] 
then 
hppdTmp_P2=""
fi
#::---------------------------------------------


#:STEP_001
#::---------------------------------------------
#:: Locate HP Server Root
#::---------------------------------------------
hppdTmp_HP_SERVER=$hppdTmp_P1/var/HostPublisher/Server
   hppdTmp_HP_LOG=$hppdTmp_P1/var/HostPublisher/log
echo "HPP1001I: Checking HP Server root" $hppdTmp_HP_SERVER
if [ ! -d $hppdTmp_HP_SERVER ]
then 
   hppdTmp_HP_SERVER=$hppdTmp_P1/HostPublisher/Server
      hppdTmp_HP_LOG=$hppdTmp_P1/HostPublisher/log
   echo "HPP1001I: Checking HP Server root" $hppdTmp_HP_SERVER
   if [ ! -d $hppdTmp_HP_SERVER ]
   then 
      hppdTmp_HP_SERVER=$hppdTmp_P1/Server
         hppdTmp_HP_LOG=$hppdTmp_P1/log
      echo "HPP1001I: Checking HP Server root" $hppdTmp_HP_SERVER
      if [ ! -d $hppdTmp_HP_SERVER ]
      then
         echo "HPP1004W: Unable to locate HP Server root:"
         echo "HPP1005W: HP Server PD/PSI files will not be gathered"
         exit 1
      fi
   fi
fi
echo "HPP1002I: HP Server root located:" $hppdTmp_HP_SERVER
echo "HPP1003I: HP Server PD/PSI files will be gathered"
echo "."
#::---------------------------------------------

#:STEP_004
#::---------------------------------------------
#:: Locate WAS Server Root & set JDK to HP's JDK
#::---------------------------------------------
OSTYPE=aix
hppdTmp_WAS_ROOT=/usr/WebSphere/AppServer
hppdTmp_HP_LPP_DIR=/usr/lpp/HostPublisher
hppdTmp_JDK_ROOT=/usr/lpp/HostPublisher/common/jdk
echo "HPP1012I: Checking WAS root:" $hppdTmp_WAS_ROOT
if [ ! -d  $hppdTmp_WAS_ROOT ]
then
   if [[ $hppdTmp_P2 != "" ]]
   then      	
   OSTYPE=aix
   hppdTmp_WAS_ROOT=/usr$hppdTmp_P2
   hppdTmp_HP_LPP_DIR=/usr/lpp/HostPublisher
   hppdTmp_JDK_ROOT=/usr/lpp/HostPublisher/common/jdk
   echo "HPP1043I: Checking WAS root:" $hppdTmp_WAS_ROOT
   fi
   if [ ! -d  $hppdTmp_WAS_ROOT/java ]
   then
      OSTYPE=aix
      hppdTmp_WAS_ROOT=/usr/lpp/IBMWebAS
      hppdTmp_HP_LPP_DIR=/usr/lpp/HostPublisher
      hppdTmp_JDK_ROOT=/usr/lpp/HostPublisher/common/jdk
      echo "HPP1044I: Checking WAS root:" $hppdTmp_WAS_ROOT
      if [ ! -d  $hppdTmp_WAS_ROOT ]
      then
         if [[ $hppdTmp_P2 != "" ]]
         then      	
         OSTYPE=sol
         hppdTmp_WAS_ROOT=/opt$hppdTmp_P2
         hppdTmp_HP_LPP_DIR=/opt/HostPublisher
         hppdTmp_JDK_ROOT=/usr/java
         echo "HPP1045I: Checking WAS root:" $hppdTmp_WAS_ROOT
         fi
         if [ ! -d  $hppdTmp_WAS_ROOT/java ]
         then
            OSTYPE=sol
            hppdTmp_WAS_ROOT=/opt/IBMWebAS
            hppdTmp_HP_LPP_DIR=/opt/HostPublisher
            hppdTmp_JDK_ROOT=/usr/java
            echo "HPP1076I: Checking WAS root:" $hppdTmp_WAS_ROOT
            if [ ! -d  $hppdTmp_WAS_ROOT ]
            then
               OSTYPE=sol
               hppdTmp_WAS_ROOT=/opt/WebSphere
               hppdTmp_HP_LPP_DIR=/opt/HostPublisher
               hppdTmp_JDK_ROOT=/usr/java
               echo "HPP1075I: Checking WAS root:" $hppdTmp_WAS_ROOT
               if [ ! -d  $hppdTmp_WAS_ROOT ]
               then
                  OSTYPE=mvs12
                  #:: /config only exists WAS 1.2 , config does not exist for 3.02 or 3.5
                  hppdTmp_WAS_ROOT=/usr/lpp/WebSphere/AppServer/config
                  hppdTmp_HP_LPP_DIR=/usr/lpp/HostPublisher
                  hppdTmp_HP_VAR_DIR=/var/HostPublisher
                  hppdTmp_JDK_ROOT=
                  echo "HPP1046I: Checking WAS root:" $hppdTmp_WAS_ROOT
                  if [ ! -d  $hppdTmp_WAS_ROOT ]
                  then
                     OSTYPE=mvs3x
                     hppdTmp_WAS_ROOT=/usr/lpp/WebSphere/AppServer
                     hppdTmp_HP_LPP_DIR=/usr/lpp/HostPublisher
                     hppdTmp_HP_VAR_DIR=/var/HostPublisher
                     hppdTmp_JDK_ROOT=
                     echo "HPP1047I: Checking WAS root:" $hppdTmp_WAS_ROOT
                     if [ ! -d  $hppdTmp_WAS_ROOT ]
                     then
                        echo "HPP1015W: Unable to locate WAS root"
                        echo "HPP1016W: WAS PD/PSI files will not be gathered"
                        echo "."
                        exit 1
                     fi
                  fi
               fi
            fi
         fi
      fi
   fi
fi
#::---------------------------------------------

#::---------------------------------------------
#:: Check the Web server's configuration file for WAS v1.2 location
#::---------------------------------------------
if [ $OSTYPE = "mvs12" ]
then
   hppdTmp_WAS_ROOT=`grep "/usr/lpp/WebSphere/AppServer/lib/libadpter.so" /etc/httpd.conf | grep ServerInit | awk '{print $3}'`
   if [ ! -d $hppdTmp_WAS_ROOT ]
   then
      echo "HPP1070E: Could not locate WebSphere alternate server root directory"
      echo "."
      exit 1
   fi
fi
#::---------------------------------------------

#::---------------------------------------------
#:: Set tmp dir if MVS
#::---------------------------------------------
if [ $OSTYPE = "mvs12" ]
then
   hppdTmp_TEMPDIR=$hppdTmp_TEMPDIR_MVS
   hppdTmp_IS_MVS="1"
fi
if [ $OSTYPE = "mvs3x" ]
then
   hppdTmp_TEMPDIR=$hppdTmp_TEMPDIR_MVS
   hppdTmp_IS_MVS="1"
fi
#::---------------------------------------------

#:STEP_004_2
#::---------------------------------------------
#:: Locate WAS Server Root
#::---------------------------------------------
echo "HPP1013I: WAS root located: " $hppdTmp_WAS_ROOT
echo "HPP1014I: WAS PD/PSI files will be gathered"
echo "."
#::---------------------------------------------

#:STEP_005
#::---------------------------------------------
#:: Locate JDK root ( java directory )  23, 64-69
#::---------------------------------------------
if [[ $3 = "" ]]
then 
   echo "HPP1018I: Checking JDK root:" $hppdTmp_JDK_ROOT
   if [ ! -d  $hppdTmp_JDK_ROOT ]
   then 
      hppdTmp_JDK_ROOT=$hppdTmp_WAS_ROOT"/java"
      echo "HPP1019I: Checking JDK root:" $hppdTmp_JDK_ROOT
      if [ ! -d  $hppdTmp_JDK_ROOT ]
      then 
         hppdTmp_JDK_ROOT=/usr/IBMWebAS/java
         echo "HPP1020I: Checking JDK root:" $hppdTmp_JDK_ROOT
         if [ ! -d  $hppdTmp_JDK_ROOT ]
         then 
            hppdTmp_JDK_ROOT=/usr/WebSphere/AppServer/java
            echo "HPP1021I: Checking JDK root:" $hppdTmp_JDK_ROOT
            if [ ! -d  $hppdTmp_JDK_ROOT ]
            then 
               echo "HPP1023E: Unable to locate JDK root"
               echo "HPP1023E: Please specify parameter java_root"
               echo "."
               exit 1
            fi
         fi
      fi
   fi
else
   hppdTmp_JDK_ROOT=$3"/java"
   echo "HPP1022I: Checking JDK root:" $hppdTmp_JDK_ROOT
   if [ ! -d  $hppdTmp_JDK_ROOT ]
   then 
      hppdTmp_JDK_ROOT=$3"/bin"
      echo "HPP1080I: Checking JDK root:" $hppdTmp_JDK_ROOT
      if [ ! -d  $hppdTmp_JDK_ROOT ]
         then 
         echo "HPP1042E: Unable to locate JDK root"
         exit 1
      fi
   fi
fi
#::---------------------------------------------

#:STEP_007
#::---------------------------------------------
#:: Locate JDK ( JAR.exe )
#::---------------------------------------------
   hppdTmp_JDK_JAR_EXE=$hppdTmp_JDK_ROOT"/sh/jar"
   echo "HPP1082I: Checking JAR:" $hppdTmp_JDK_JAR_EXE
   if [ ! -f  $hppdTmp_JDK_JAR_EXE ]
   then 
      hppdTmp_JDK_JAR_EXE=$hppdTmp_JDK_ROOT"/bin/jar"
      echo "HPP1083I: Checking JAR:" $hppdTmp_JDK_JAR_EXE
      if [ ! -f  $hppdTmp_JDK_JAR_EXE ]
      then 
         hppdTmp_JDK_JAR_EXE=$hppdTmp_WAS_ROOT"/java/bin/jar"
         echo "HPP1084I: Checking JAR:" $hppdTmp_JDK_JAR_EXE
         if [ ! -f  $hppdTmp_JDK_JAR_EXE ]
         then 
            hppdTmp_JDK_JAR_EXE=$hppdTmp_JDK_ROOT"/jar"
            echo "HPP1084I: Checking JAR:" $hppdTmp_JDK_JAR_EXE
            if [ ! -f  $hppdTmp_JDK_JAR_EXE ]
            then
               hppdTmp_JDK_JAR_EXE="jar"
               echo "HPP1085I: Checking JAR:" $hppdTmp_JDK_JAR_EXE
               if [ $hppdTmp_IS_MVS = "0" ]
               then
                  echo "HPP1025E: Jar utility not found"
                  echo "."
                  exit 1
               fi
            fi
         fi
      fi
   fi

echo "HPP1025I: Jar utility found:" $hppdTmp_JDK_JAR_EXE
echo "."
#::---------------------------------------------

#::---------------------------------------------
echo "HPP1073I: Creating temporary directories"
#::---------------------------------------------
if [ -d $hppdTmp_TEMPDIR ] 
then
   rm -fr $hppdTmp_TEMPDIR
fi

mkdir $hppdTmp_TEMPDIR
mkdir $hppdTmp_TEMPDIR"/LOG"
mkdir $hppdTmp_TEMPDIR"/VAR"
mkdir $hppdTmp_TEMPDIR"/WAS"
mkdir $hppdTmp_TEMPDIR"/appmanifests"
mkdir $hppdTmp_TEMPDIR"/poolspecs"
mkdir $hppdTmp_TEMPDIR"/beans"
mkdir $hppdTmp_TEMPDIR"/documents"

if [ ! -d $hppdTmp_TEMPDIR"/WAS" ] 
then
   echo "HPP1036E: Unable to create:" $hppdTmp_TEMPDIR"/WAS"
   echo "HPP1037I: Make sure the above directory is in R/W mode"
   exit 1
fi
#::---------------------------------------------

#::---------------------------------------------
echo "HPP1026I: Building the exclusion list"
#::---------------------------------------------
echo HPAdmin                       >hppd.in
echo service_defaults             >>hppd.in
echo adminservice                 >>hppd.in
echo httpservice                  >>hppd.in
echo xmlLegacyPortal.jar          >>hppd.in
echo xmlLegacyGWS.jar             >>hppd.in
echo RIOServlet.jar               >>hppd.in
echo xmlLegacyGateway.application >>hppd.in
echo xmlLegacyPortal.application  >>hppd.in
echo RIOServlet.application       >>hppd.in
echo xmlLegacyGateway             >>hppd.in
echo xmlLegacyPortal              >>hppd.in
echo classes.zip                  >>hppd.in
echo HPubCommon.jar               >>hppd.in
echo RIO.jar                      >>hppd.in
echo nano.zip                     >>hppd.in
echo swingall.jar                 >>hppd.in
echo "."
#::---------------------------------------------

#::---------------------------------------------
#:: Collect the data
#::---------------------------------------------
echo "HPP1027I: Collecting PD/PSI files"
#::---------------------------------------------

#::---------------------------------------------
#:: Skipping HP Server?
#::---------------------------------------------
#if "$hppdTmp_HP_SERVER" == "" goto SKIP_HP_SERVER
#::---------------------------------------------

#::---------------------------------------------
echo "HPP1058I: Collecting PD/PSI files...HP Server directory list..."
#::---------------------------------------------
ls -lR $hppdTmp_HP_SERVER   >$hppdTmp_TEMPDIR"/DirectoryListingHPServer.txt"
#::---------------------------------------------

#::---------------------------------------------
echo "HPP1028I: Collecting PD/PSI files...HP Server production files..."
#::---------------------------------------------
if [ -d $hppdTmp_HP_SERVER"/production/appmanifests" ]
then 
   cp -r $hppdTmp_HP_SERVER"/production/appmanifests"                               $hppdTmp_TEMPDIR"/appmanifests"  # 1>/dev/null  2>/dev/null
else
   echo "HPP1078W: Missing "$hppdTmp_HP_SERVER"/production/appmanifests"
fi

if [ -d $hppdTmp_HP_SERVER"/production/poolspecs" ]
then 
   cp -r $hppdTmp_HP_SERVER"/production/poolspecs"                                  $hppdTmp_TEMPDIR"/poolspecs"     # 1>/dev/null  2>/dev/null
else
   echo "HPP1078W: Missing "$hppdTmp_HP_SERVER"/production/poolspecs"
fi

if [ -d $hppdTmp_HP_SERVER"/production/beans" ]
then 
   cp -r $hppdTmp_HP_SERVER"/production/beans"                                      $hppdTmp_TEMPDIR"/beans"         # 1>/dev/null  2>/dev/null
else
   echo "HPP1078W: Missing "$hppdTmp_HP_SERVER"/production/beans"
fi

if [ -d $hppdTmp_HP_SERVER"/production/documents" ]
then 
   cp -r $hppdTmp_HP_SERVER"/production/documents"                                  $hppdTmp_TEMPDIR"/documents"     # 1>/dev/null  2>/dev/null
else
   echo "HPP1078W: Missing "$hppdTmp_HP_SERVER"/production/documents"
fi

if [ -f $hppdTmp_HP_SERVER"/production/documents/xmlLegacyPortal/hPubPortalData.xml" ]
then
cp    $hppdTmp_HP_SERVER"/production/documents/xmlLegacyPortal/hPubPortalData.xml" $hppdTmp_TEMPDIR               # 1>/dev/null  2>/dev/null
fi

#::if [ -d $hppdTmp_HP_VAR_DIR ]
#::then
#::cp -r $hppdTmp_HP_VAR_DIR  $hppdTmp_TEMPDIR/VAR     # 1>/dev/null  2>/dev/null
#::fi

#::---------------------------------------------

#::---------------------------------------------
echo "HPP1028I: Collecting PD/PSI files...HP Server product XML files..."
#::---------------------------------------------
cp $hppdTmp_HP_SERVER"/product.xml"              $hppdTmp_TEMPDIR 1>/dev/null  2>/dev/null
cp $hppdTmp_HP_SERVER"/HostPubWASConfig.xml"     $hppdTmp_TEMPDIR 1>/dev/null  2>/dev/null
#::---------------------------------------------

#::---------------------------------------------
echo "HPP1062I: Collecting PD/PSI files...HP Server fixdata files..."
#::---------------------------------------------
cp -r $hppdTmp_HP_SERVER"/*fixdata*"               $hppdTmp_TEMPDIR  1>/dev/null  2>/dev/null
#::---------------------------------------------

#::---------------------------------------------
echo "HPP1029I: Collecting PD/PSI files...HP Server log files..."
#::---------------------------------------------
cp -r $hppdTmp_HP_LOG $hppdTmp_TEMPDIR"/LOG"  1>/dev/null  2>/dev/null
#::---------------------------------------------

#::---------------------------------------------
echo "HPP1030I: Collecting PD/PSI files...HP Server properties files..."
#::---------------------------------------------
cp $hppdTmp_HP_SERVER"/server.properties"  $hppdTmp_TEMPDIR     1>/dev/null  2>/dev/null
#::---------------------------------------------

#::---------------------------------------------
echo "."
echo "HPP1060I: Collecting PD/PSI files...WAS directory list..."
#::---------------------------------------------
ls -lR $hppdTmp_WAS_ROOT >$hppdTmp_TEMPDIR"/DirectoryListingWAS.txt"
#::---------------------------------------------

#::---------------------------------------------
#:: Gather WAS files - Gather WebSphere logs and 
#:: files, depending on level of WebSphere. Look 
#:: for the "hosts" as a flag for v3
#::---------------------------------------------

#::---------------------------------------------
# Gather WebSphere logs and files, depending on level of WebSphere. Look for the "hosts"
# directory under AppServer for V3
#::---------------------------------------------
if [ -d $hppdTmp_WAS_ROOT"/hosts" ]
then
   #:STEP_WAS_VERSION_3
   #::---------------------------------------------
   #:: We can't get the active configuration from a batch file, so the best we can do is
   #:: grab the configuration XML file under the Host Publisher directory. Log files are all
   #:: under HostPub/log, which we've already grabbed.
   #::---------------------------------------------
   echo "HPP1033I: Collecting PD/PSI files...WAS configuration files...( v3 )"
   #::---------------------------------------------
   cp $hppdTmp_WAS_ROOT"/bin/admin.config " $hppdTmp_TEMPDIR"/WAS"  1>/dev/null  2>/dev/null
   cp $hppdTmp_HP_LPP_DIR"/HostPubWASConfig.xml " $hppdTmp_TEMPDIR   1>/dev/null  2>/dev/null
   #::---------------------------------------------

   #::---------------------------------------------
   # Rewrite hostPubWAS.sh to perform an export of WAS configuration
   #::---------------------------------------------
   echo "HPP1071I: Collecting PD/PSI files...Exporting WAS configuration...( v3 )"
   cd $hppdTmp_HP_LPP_DIR
   if [ -f HostPubWAS.sh ]
   then
      sed 's/-import/-export/g' HostPubWAS.sh > HostPubWASexp.sh
      chmod +x HostPubWASexp.sh
      ./HostPubWASexp.sh $hppdTmp_TEMPDIR"/WAS/xmlConfig.out" > /dev/null
   else
      echo "HPP1077W: Missing file "$hppdTmp_HP_LPP_DIR"/HostPubWAS.sh"
      echo "HPP1078W: Unable to export WAS configuration"
   fi
   cd - > /dev/null
   #::---------------------------------------------
else
   #::---------------------------------------------
   echo "HPP1031I: Collecting PD/PSI files...WAS logs...( not v3 )"
   #::---------------------------------------------
   cp -r $hppdTmp_WAS_ROOT"/logs"  $hppdTmp_TEMPDIR"/WAS" 1>/dev/null  2>/dev/null
   #::---------------------------------------------

   #::---------------------------------------------
   echo "HPP1032I: Collecting PD/PSI files...WAS properties files...( not v3 )"
   #::---------------------------------------------
   cp -r $hppdTmp_WAS_ROOT"/properties"  $hppdTmp_TEMPDIR"/WAS" 1>/dev/null  2>/dev/null
   #::---------------------------------------------
fi
#::---------------------------------------------

#::---------------------------------------------
# now delete unwanted files - use the exclusion list
#::---------------------------------------------
echo "HPP1072I: Excluding selected files..."
cd $hppdTmp_TEMPDIR
for i in `cat $CURRENTDIR/hppd.in`
do
	find . -name $i -exec rm -r {} ";" 2> /dev/null
done
cd $CURRENTDIR
rm hppd.in
#::---------------------------------------------

#::---------------------------------------------
#:: Create the PD/PSI Jar file
#::---------------------------------------------
echo "HPP1034I: Creating PD/PSI Jar file..."
cd $CURRENTDIR
$hppdTmp_JDK_JAR_EXE cMf ./hppd.$OSTYPE.jar $hppdTmp_TEMPDIR
rm -fr $hppdTmp_TEMPDIR
#::---------------------------------------------

#::---------------------------------------------
#:: Done
#::---------------------------------------------
echo "."
echo "HPP1035I: DONE - ./hppd."$OSTYPE".jar file has been created. Please"
echo "          send this file to IBM Service when requested."
echo "."
echo "."
#::---------------------------------------------

exit 0

