echo off

rem *************************************************************
rem * CMPD - Common Management of Problem Data                  *
rem *   for Windows NT/95/98/2000.                              *
rem *   Gathers documentation for Personal Communications.      *
rem *                                                           *
rem *                                                           *
rem *************************************************************

rem *************************************************************
rem *                                                           *
rem *  Help options                                             *
rem *                                                           *
rem *************************************************************
if X%1 == X?     goto HELP
if X%1 == X/?    goto HELP
if X%1 == Xhelp  goto HELP

rem echo Parm1=%1 Parm2=%2 Parm3=%3 Parm4=%4 Parm5=%5 Parm6=%6 Parm7=%7 Parm8=%8 Parm9=%9

rem PAUSE
rem *************************************************************
rem *                                                           *
rem *  First, attempt to determine which drive is the system    *
rem *  drive.  Default to C:                                    *
rem *                                                           *
rem *************************************************************
set CMPDSysDrive=%SystemDrive%
if NOT [%CMPDSysDrive%] == [] goto SDCONT
set CMPDSysDrive=C:
:SDCONT
if [%CMPDSysDrive%] == [] goto ERROR7

rem *************************************************************
rem *                                                           *
rem *  For Windows NT, find the system directory.  If it is not *
rem *  set, that's ok - we're probably running on Windows 95/98.*
rem *  Also set erase command parm based on this info.          *
rem *                                                           *
rem *************************************************************
set CMPDWinNTSysDir=%SystemRoot%
if [%CMPDWinNTSysDir%] == [] goto SRCONT
set CMPDEraseParm=/Q
:SRCONT

rem *************************************************************
rem *                                                           *
rem *  Now, setup a working directory for CMPD on the system    *
rem *  drive.  Clean it up if necessary.                        *
rem *                                                           *
rem *************************************************************
set CMPDWorkingDir=%CMPDSysDrive%\CMPDTEMP
if [%CMPDWorkingDir%] == [] goto ERROR7
md %CMPDWorkingDir%
rem if NOT EXISTS %CMPDWorkingDir%\*.* goto CLNCONT1
if NOT [%CMPDEraseParm%] == [] goto CLNCONT2
echo **********************************************************
echo NOTE: CMPD is preparing to gather problem determination data.
echo       Please press Y to clean up CMPD's temporary working directory:
echo            %CMPDWorkingDir%
:CLNCONT2
erase %CMPDWorkingDir%\*.*  %CMPDEraseParm%
:CLNCONT1

rem *************************************************************
rem *                                                           *
rem *  Ok, first check parm #1 and use it, otherwise ERROR      *
rem *  Parm #1 - 5 digit PMR number (use 12345 if not known)    *
rem *                                                           *
rem *************************************************************
if [%1] == [] goto ERROR1
set PCSPMR=%1

rem *************************************************************
rem *                                                           *
rem *  Ok, check parm #2 and use it, otherwise ERROR            *
rem *  Parm #2 - PCOMM's SC_INSTALL directory                   *
rem *            Enter 'NA' if not applicable                   *
rem *                                                           *
rem *************************************************************
set PKZIPDIR="BAD"
if [%2] == [] goto ERROR2
set PCS_SC_INSTALL_DIR=%2
if %PCS_SC_INSTALL_DIR% == "NA" goto CONT2
set PKZIPDIR=%PCS_SC_INSTALL_DIR%
rem               PCOMM SC_INSTALL directory list
dir  "%PCS_SC_INSTALL_DIR%"\*.* /s    > %CMPDWorkingDir%\DIRINST.TXT
:CONT2
if %PKZIPDIR% == "BAD" goto ERROR5

rem *************************************************************
rem *                                                           *
rem *  Ok, check parm #3 and use it, otherwise ERROR            *
rem *  Parm #3 - PCOMM's SC_SYSTEM directory                    *
rem *            Enter 'NA' if not applicable                   *
rem *            Enter '2'  if same as SC_INSTALL               *
rem *                                                           *
rem *************************************************************
if [%3] == [] goto ERROR3
set PCS_SC_SYSTEM_DIR=%3
if %PCS_SC_SYSTEM_DIR% == "NA" goto CONT3
if %PCS_SC_SYSTEM_DIR% == "2"  set PCS_SC_SYSTEM_DIR=%2
rem               PCOMM SC_SYSTEM directory list
dir  "%PCS_SC_SYSTEM_DIR%"\*.* /s    > %CMPDWorkingDir%\DIRSYST.TXT
rem               copy all files from SC_SYSTEM directory
copy "%PCS_SC_SYSTEM_DIR%"\*.*         %CMPDWorkingDir%
:CONT3

rem *************************************************************
rem *                                                           *
rem *  Ok, check parm #4 and use it, otherwise ERROR            *
rem *  Parm #4 - PCOMM's SC_USER directory                      *
rem *            Enter 'NA' if not applicable                   *
rem *            Enter '2'  if same as SC_INSTALL               *
rem *            Enter '3'  if same as SC_SYSTEM                *
rem *                                                           *
rem *************************************************************
if [%4] == [] goto ERROR4
set PCS_SC_USER_DIR=%4
if %PCS_SC_USER_DIR% == "NA" goto CONT4
if %PCS_SC_USER_DIR% == "2"  set PCS_SC_USER_DIR=%2
if %PCS_SC_USER_DIR% == "3"  set PCS_SC_USER_DIR=%3
rem               PCOMM profile directory list
dir  "%PCS_SC_USER_DIR%"\*.* /s    > %CMPDWorkingDir%\DIRUSER.TXT
rem               copy all files from SC_USER directory
copy "%PCS_SC_USER_DIR%"\*.*         %CMPDWorkingDir%

:CONT4


rem *************************************************************
rem *                                                           *
rem *  Ok, check parm #6 and use it, otherwise ERROR            *
rem *  Parm #6 - Trace Facility's Working Directory, if applic. *
rem *            Enter 'NA' if not applicable                   *
rem *                                                           *
rem *************************************************************
if [%6] == [] goto CONT5
set ITFWORKDIR=%6
if %ITFWORKDIR% == "NA" goto CONT5
rem               Trace Facility working directory list
dir  "%ITFWORKDIR%"\*.* /s    > %CMPDWorkingDir%\ITFWDIR.TXT
rem               no need to copy working directory

:CONT5

rem *************************************************************
rem *                                                           *
rem *  Ok, check parm #7 and use it, otherwise ERROR            *
rem *  Parm #7 - Trace Facility's Format Directory, if applic.  *
rem *            Enter 'NA' if not applicable                   *
rem *            Enter '6'  if same as Working Directory        *
rem *                                                           *
rem *************************************************************
if [%7] == [] goto CONT6
set ITFFMTDIR=%7
if %ITFFMTDIR% == "6" set ITFFMTDIR=%6
if %ITFFMTDIR% == "NA" goto CONT6
rem               Trace Facility format directory list
dir  "%ITFFMTDIR%"\*.* /s    > %CMPDWorkingDir%\ITFFDIR.TXT
rem               copy all TLG files from format directory
copy "%ITFFMTDIR%"\*.tlg       %CMPDWorkingDir%

:CONT6

rem *************************************************************
rem *                                                           *
rem *  Ok, check parm #8 and use it, otherwise ERROR            *
rem *  Parm #8 - Trace Facility's Save Directory, if applic.    *
rem *            Enter 'NA' if not applicable                   *
rem *            Enter '6'  if same as Working Directory        *
rem *                                                           *
rem *************************************************************
if [%8] == [] goto CONT7
set ITFSAVEDIR=%8
if %ITFSAVEDIR% == "6" set ITFSAVEDIR=%6
if %ITFSAVEDIR% == "NA" goto CONT7
rem               Trace Facility save directory list
dir  "%ITFSAVEDIR%"\*.* /s    > %CMPDWorkingDir%\ITFSDIR.TXT
rem               copy all trc files from save directory
copy "%ITFSAVEDIR%"\*.trc       %CMPDWorkingDir%

:CONT7

rem *************************************************************
rem *                                                           *
rem *  Ok, check parm #9 and use it, otherwise ERROR            *
rem *  Parm #9 - PCOMM's Message Log Directory, if applic.      *
rem *            Enter 'NA' if not applicable                   *
rem *            Enter '3'  if same as SC_SYSTEM                *
rem *                                                           *
rem *************************************************************
if [%9] == [] goto CONT8
set PCS_MSGLOG_DIR=%9
if %PCS_MSGLOG_DIR% == "3" set PCS_MSGLOG_DIR=%3
if %PCS_MSGLOG_DIR% == "NA" goto CONT8
rem               PCOMM's message log directory list
dir  "%PCS_MSGLOG_DIR%"\*.* /s    > %CMPDWorkingDir%\MSGLDIR.TXT
rem               copy all message logs from save directory
copy "%PCS_MSGLOG_DIR%"\*.mlg       %CMPDWorkingDir%

:CONT8

rem *************************************************************
rem *                                                           *
rem *  Ok, check parm #5 and use it (removed 5, 6, 7 and 8      *
rem *  Parm #5 - Quiet mode (any value here signifies QUIET)    *
rem *                                                           *
rem *************************************************************
if [%6] == [] goto CONT9
set QUIETMODE=Y
:CONT9

rem *************************************************************
rem *                                                           *
rem * Copy APAR history file                                    *
rem *                                                           *
rem *************************************************************
rem     Windows 9X
IF NOT EXIST %WINDIR%\applic~1\ibm\person~1\apars\pcomma~1.txt GOTO APARNT
copy %WINDIR%\applic~1\ibm\person~1\apars\pcomma~1.txt %CMPDWorkingDir%
xcopy %WINDIR%\applic~1\ibm\person~1\apars\*.log %CMPDWorkingDir% /s

:APARNT
rem     Windows NT
IF NOT EXIST "%WINDIR%\All Users\Application Data\IBM\Personal Communication\APARs\pcommaparinfo.txt" GOTO APAR2000
copy "%WINDIR%\All Users\Application Data\IBM\Personal Communication\APARs\pcommaparinfo.txt" %CMPDWorkingDir%
xcopy "%WINDIR%\All Users\Application Data\IBM\Personal Communication\APARs"\*.log %CMPDWorkingDir% /s

:APAR2000
rem     Windows 2000
IF NOT EXIST "%ALLUSERSPROFILE%\Application Data\IBM\Personal Communications\APARs\pcommaparinfo.txt" GOTO APAREND
copy "%ALLUSERSPROFILE%\Application Data\IBM\Personal Communications\APARs\pcommaparinfo.txt" %CMPDWorkingDir%
xcopy "%ALLUSERSPROFILE%\Application Data\IBM\Personal Communications\APARs"\*.log %CMPDWorkingDir% /s

:APAREND



rem *************************************************************
rem *                                                           *
rem * Create the self-extracting file with pcsbundler Java class*
rem * file, and copy this file to the product SC_SYSTEM         *
rem * directory Praveen                                         *
rem *                                                           *
rem *************************************************************
IF EXIST %PCS_SC_SYSTEM_DIR%\x%PCSPMR%.zip del %PCS_SC_SYSTEM_DIR%\x%PCSPMR%.zip
set PCS_JREPATH=%PCS_SC_INSTALL_DIR%\jre
set JAVA_HOME=%PCS_JREPATH%
set PATH=%JAVA_HOME%\bin;%PATH% 
set CLASSPATH=%PCS_SC_INSTALL_DIR%
java PCSBundler %PCS_SC_SYSTEM_DIR%\x%PCSPMR%.zip %CMPDWorkingDir%
IF EXIST %PCS_SC_SYSTEM_DIR%\x%PCSPMR%.zip GOTO CONT10
set JAVA_HOME=%5
set PATH=%JAVA_HOME%\bin;%PATH%
java PCSBundler %PCS_SC_SYSTEM_DIR%\x%PCSPMR%.zip %CMPDWorkingDir%
IF NOT EXIST %PCS_SC_SYSTEM_DIR%\x%PCSPMR%.zip GOTO ERROR6
   
:CONT10


echo **********************************************************
echo.
echo.
echo File X%PCSPMR%.zip has been created and placed into your IBM
echo Personal Communications profile directory:
echo    %PCS_SC_SYSTEM_DIR%
echo If the filename does not reflect your PMR number, please rename
echo this file to your PMR number before transmitting
echo to IBM service.
echo.
rem *************************************************************
rem *                                                           *
rem * Clean up processing                                       *
rem *                                                           *
rem *************************************************************
if [%CMPDWorkingDir%] == [] GOTO ERROR8

rem If WinNT or higher, use RD with /S option to remove all sub dirs.
rem If Win9X, have to use deltree as the /S option on RD is not available 
rem on Win9X.
if [%CMPDWinNTSysDir%] == [] goto DELTTMP
rd /s /q %CMPDWorkingDir%
goto DONEDEL
:DELTTMP
deltree /y %CMPDWorkingDir%
:DONEDEL

if NOT EXIST "%PCS_SC_SYSTEM_DIR%\registry.dat" goto ALLDONE
erase "%PCS_SC_SYSTEM_DIR%\registry.dat"
goto ALLDONE

:HELP
echo ********** HELP ********************************************
echo.
echo CMPD
echo This batch file is used to collect information for IBM Service.
echo Command line parameters are:
echo    CMPD %1 %2 %3 %4 %5 %6 %7 %8 %9
echo where:  %1 the service designated PMR number.
echo         %2 PCOMM's SC_INSTALL short path name
echo         %3 PCOMM's SC_SYSTEM short path name
echo         %4 PCOMM's SC_USER short path name
echo         %5 Trace Facility's working directory if not same as SC_SYSTEM (short name)
echo         %6 Trace Facility's formatting directory if not same as SC_SYSTEM (short name)
echo         %7 Trace Facility's save directory if not same as SC_SYSTEM (short name)
echo         %8 PCOMM's Message Log directory if not same as SC_SYSTEM (short name)
echo         %9 QUIET (optional quite mode)
echo NOTES: - All parameters are required, except %5 %6 %7 %8 %9
echo        - Use PCSPD.EXE to gather registry data.
echo        - Easier to use PCSPD anyway since it sets up the parms
echo            for you.
goto ALLDONE

:ERROR1
echo ********** ERROR 1 ********************************************
echo.
echo PCSPD Error. PARM1 PMR number not specified.
echo Not all required parameters were specified for CMPD.BAT.
echo Enter CMPD /? for more information on use of this facility.
echo.
goto ALLDONE_ERROR

:ERROR2
echo ********** ERROR 2 ********************************************
echo.
echo PCSPD Error. PARM2 PCOMM's SC_INSTALL short path name not specified.
echo Not all required parameters were specified for CMPD.BAT.
echo Try the command again.
echo.
goto ALLDONE_ERROR

:ERROR3
echo ********** ERROR 3 ********************************************
echo.
echo PCSPD Error. PARM3 PCOMM's SC_SYSTEM short path name not specified.
echo.
goto ALLDONE_ERROR

:ERROR4
echo ********** ERROR 4 ********************************************
echo.
echo PCSPD Error. PARM4 PCOMM's SC_USER short path name not specified.
echo Unable to clean up the PCSPD working directory.
echo.
goto ALLDONE_ERROR

:ERROR5
echo ********** ERROR 5 ********************************************
echo.
echo PCSPD Error.
echo NA was specified for both local and server directory.  This is
echo an error.  At least one of the two must be a valid directory.
echo.
goto ALLDONE

:ERROR6
echo ********** ERROR 6 ********************************************
echo.
echo PCSPD Error.
echo The bundled file [x%PCSPMR%.zip] was not created or does
echo not exist.  Try the command again.
echo.
goto ALLDONE

:ERROR7
echo ********** ERROR 7 ********************************************
echo.
echo PCSPD Error.
echo PCSPD was unable to create new environment variables
echo because it is out of environment space.  Try adding
echo the following line to your CONFIG.SYS file by running sysedit, restart
echo the computer, and then try running Information Bundler (PCSPD.EXE) again.
echo.
echo    shell=c:\command.com /p /e:4096
echo.
goto ALLDONE

:ERROR8
echo ********** ERROR 8 ********************************************
echo.
echo PCSPD Error.
echo Unable to clean up the PCSPD working directory %CMPDWorkingDir%.
echo.
goto ALLDONE

:ALLDONE_ERROR
echo ********** Completed with error ****************************
if [%QUIETMODE%]==[Y] GOTO QUIETDONE
echo.
echo PCSPD Error.
echo PCSPD was unable to collect the required problem determination information
echo successfuly. Please see the prevous error messages and try running
echo Information Bundler (PCSPD.EXE) again.
echo.
pause
:QUIETDONE
rem * Exit program

:ALLDONE
echo ********** Completed without error ****************************
if [%QUIETMODE%]==[Y] GOTO QUIETDONE
pause
:QUIETDONE
rem * Exit program
