#!/bin/sh
:
################################################################################
################################################################################
##                                                                            ##
## Micro Focus Support Assistance Utility                                     ##
##                                                                            ##
## @(#)mfsupport	5.0                                                   ##
##                                                                            ##
## Purpose: This utility was created to assist the Micro Focus Support        ##
##          in gleaning information from the user's                           ##
##          environment quickly.                                              ##
##                                                                            ##
##     ******************************************************************     ##
##     * Copyright 1989-2004 Micro Focus International Ltd.             *     ##
##     * All Rights Reserved.                                           *     ##
##     * This diagnostic program is provided for use by users of        *     ##
##     * Micro Focus products and may be used, modified and             *     ##
##     * distributed as part of your application provided that you      *     ##
##     * properly acknowledge the copyright of Micro Focus in this      *     ##
##     * material.                                                      *     ##
##     ******************************************************************     ##
##                                                                            ##
##                                                                            ##
## History:                                                                   ##
##                                                                            ##
## Date    Who    Remarks                                                     ##
## ------- ----   ------------------------------------------------------      ##
## 19Nov93 JEK    Original                                                    ##
## *****98 CDR    Genesis adaptions                                           ##
## *****04 JCC    General reworking
##                                                                            ##
################################################################################
################################################################################
clear
VERSION="5.0"
LINE="\n\n--------------------------------------------\n\n"
OUTFILE="mfpoll.txt"

test `uname -s` = Linux && echocmd="echo -e" || echocmd="echo"

$echocmd "Micro Focus UNIX Support Scan Utility."

if [ "$COBDIR" = "" ]
    then
    while [ "$TMP_COBDIR" = "" ] && [ "$TMP_COBDIR" != "q" ]
    do
        $echocmd "COBDIR not set.  Please enter PATH for your COBOL directory or\c"
        $echocmd " 'q' to quit."
        $echocmd ":\c"
        read TMP_COBDIR
    done
else
    TMP_COBDIR=$COBDIR
fi

if [ "$TMP_COBDIR" != "q" ]
    then
    if [ -f $TMP_COBDIR/etc/cobver ]
        then 
        $echocmd "COBOL found in $TMP_COBDIR"
        $echocmd "One moment while your environment is scanned...\n"
        $echocmd "Micro Focus UNIX Support Scan Utility v$VERSION \n\n\n"                                                                             >$OUTFILE
        $echocmd "Information current as of \c"                      >>$OUTFILE
        date                                                         >>$OUTFILE
        $echocmd "\n\nCurrent environment variables follow:\n\n"     >>$OUTFILE
        env|sort                                                     >>$OUTFILE

        # Now that we have dumped the environment, we can set COBDIR & PATH.
        COBDIR=$TMP_COBDIR
        export COBDIR
        PATH=$COBDIR/bin:$PATH
        export PATH
	currmode=64
        $echocmd $LINE                                               >>$OUTFILE
        $echocmd "Micro Focus Product information:\n\n"              >>$OUTFILE
        $echocmd "RTS information:\n"                                >>$OUTFILE
        cobrun                                                      2>>$OUTFILE
        $echocmd "\n\nCOBOL Version information:\n"                  >>$OUTFILE
	LD_LIBRARY_PATH=dummy SHLIB_PATH=dummy LIBPATH=dummy $COBDIR/bin/cob -V >>$OUTFILE 2>&1
        cat $COBDIR/etc/cobver                                       >>$OUTFILE
        $echocmd $LINE                                               >>$OUTFILE
        $echocmd "\n\nCurrent working mode: $currmode\n"             >>$OUTFILE
        $echocmd $LINE                                               >>$OUTFILE
        if [ $currmode -eq 32 ]
        then
                currmode=""
        fi
        $echocmd "\nUser's System Information:\n\n"                  >>$OUTFILE
	uname -a                                                  >>$OUTFILE
	                                                 >>$OUTFILE
	$echocmd "\n"                                                >>$OUTFILE
	$echocmd "\n\nOS Level:\n"                                   >>$OUTFILE
	uname -r                                               >>$OUTFILE
	$echocmd "\n\nOS cannot list patches!\n"                     >>$OUTFILE
	$echocmd "\n"                                                >>$OUTFILE
        $echocmd "\n\nSystem fixed disk resources:\n"                >>$OUTFILE
        df                                                           >>$OUTFILE
        $echocmd "\n"                                                >>$OUTFILE
        $echocmd "Last boot:\n"                                      >>$OUTFILE
	who -bH                                           >>$OUTFILE
        $echocmd "\nUsers logged in:\n"                              >>$OUTFILE
        who -TH                                                      >>$OUTFILE
        $echocmd "\n\nProcess information:\n\n"                      >>$OUTFILE
        ps -ef                                                       >>$OUTFILE 
        $echocmd $LINE                                               >>$OUTFILE
        $echocmd "User information:\n"                               >>$OUTFILE
        $echocmd "\nid:\n"                                           >>$OUTFILE
        id                                                           >>$OUTFILE 
        $echocmd "\nPassword file entry:\n"                          >>$OUTFILE
        grep "^$LOGNAME:" /etc/passwd                                >>$OUTFILE
        $echocmd "\n"                                                >>$OUTFILE
	$echocmd "\nLIBLIST setting and contents:\n"                 >>$OUTFILE
	$echocmd "\nLIBLIST is set to: $LIBLIST\n"                   >>$OUTFILE
if [ ".$LIBLIST" != "." -a -f "$LIBLIST" ]; then
        $echocmd "\nThe contents of file $LIBLIST are:\n"            >>$OUTFILE
	cat $LIBLIST 						     >>$OUTFILE
	$echocmd "\n"                                                >>$OUTFILE 
else
	$echocmd "\nLIBLIST is unset or refers to a file that does not exist\n"                                                                      >>$OUTFILE
	$echocmd "The contents of the current mode liblist file are:\n"                                                                              >>$OUTFILE
        cat $COBDIR/lib/liblist$currmode                             >>$OUTFILE 
fi
        $echocmd "\n"                                                >>$OUTFILE
	$echocmd "\nCOBCONFIG setting and contents:\n"               >>$OUTFILE
	$echocmd "\nCOBCONFIG is set to: $COBCONFIG\n"               >>$OUTFILE
if [ ".$COBCONFIG" != "." -a -f "$COBCONFIG" ]; then
        $echocmd "\nThe contents of file $COBCONFIG are:\n"          >>$OUTFILE
	cat $COBCONFIG 						     >>$OUTFILE
	$echocmd "\n"                                                >>$OUTFILE
else
	$echocmd "\nCOBCONFIG is unset or refers to a file that does not exist\n"                                                                    >>$OUTFILE
fi
        $echocmd "\nThe contents of COBDIR/etc/cobconfig are:\n\n"   >>$OUTFILE
        cat $COBDIR/etc/cobconfig                        2>/dev/null >>$OUTFILE 
        $echocmd "\n"                                                >>$OUTFILE
	$echocmd "\nCOBOPT setting and contents:\n"                  >>$OUTFILE
	$echocmd "\nCOBOPT is set to: $COBOPT\n"                     >>$OUTFILE
if [ ".$COBOPT" != "." -a -f "$COBOPT" ]; then
        $echocmd "\nThe contents of file $COBOPT are:\n"             >>$OUTFILE
	cat $COBOPT 						     >>$OUTFILE
	$echocmd "\n"                                                >>$OUTFILE
fi
        $echocmd "\nThe contents of COBDIR/etc/cobopt$currmode are:\n\n"                                                                             >>$OUTFILE
        cat $COBDIR/etc/cobopt$currmode                              >>$OUTFILE 
        $echocmd "\n"                                                >>$OUTFILE
        $echocmd "\nThe contents of COBDIR/dynload$currmode/cobol.dir are:\n\n"                                                                      >>$OUTFILE 
        cat $COBDIR/dynload$currmode/cobol.dir           2>/dev/null >>$OUTFILE 
        $echocmd "\n"                                                >>$OUTFILE
        $echocmd "\nThe contents of COBDIR/etc/cob$currmode.cfg are:\n\n"                                                                            >>$OUTFILE
        cat $COBDIR/etc/cob$currmode.cfg                             >>$OUTFILE 
        $echocmd "\n"                                                >>$OUTFILE
	$echocmd "\nEXTFH  setting and extfh.cfg:\n"                 >>$OUTFILE
	$echocmd "\nEXTFH  is set to: $EXTFH \n"                     >>$OUTFILE
if [ -f $COBDIR/etc/extfh.cfg ]; then
        $echocmd "\nthe contents of extfh.cfg are:\n"                >>$OUTFILE
	cat extfh.cfg					             >>$OUTFILE
	$echocmd "\n"                                                >>$OUTFILE
fi
if [ ! -z "$EXTFH" ]; then
if [ -f $EXTFH ]; then
        $echocmd "\nthe contents of $EXTFH are:\n"                   >>$OUTFILE
	cat $EXTFH				                     >>$OUTFILE
	$echocmd "\n"                                                >>$OUTFILE
fi
fi
if [ ".$ODBCINI" != "." -a -s "$ODBCINI" ]; then
        $echocmd "\nThe contents of file $ODBCINI are:\n"            >>$OUTFILE
        cat $ODBCINI                                                 >>$OUTFILE
        $echocmd "\n"                                                >>$OUTFILE
else
if [ -s "$HOME/.odbc.ini" ]; then
        $echocmd "\nThe contents of file $HOME/.odbc.ini are:\n"     >>$OUTFILE
        cat $HOME/.odbc.ini                                          >>$OUTFILE
        $echocmd "\n"                                                >>$OUTFILE
fi
fi
        $echocmd "\nThe contents of COBDIR/etc/cobopt$currmode are:\n\n"                                                                             >>$OUTFILE
        cat $COBDIR/etc/cobopt$currmode                              >>$OUTFILE 
        $echocmd "\n"                                                >>$OUTFILE

        $echocmd "\nADISCTRL and cobkeymp listing:\n\n"              >>$OUTFILE
        ls -l $COBDIR/ADISCTRL $COBDIR/cobkeymp          2>/dev/null >>$OUTFILE
        $echocmd "\n"                                                >>$OUTFILE
	$echocmd "\nVersions of system software\n\n"                 >>$OUTFILE
	$echocmd "as:\n"                                             >>$OUTFILE
	as -v 2>&1 < /dev/null                                               >>$OUTFILE                                                                            2>&1
	$echocmd "cc:\n"                                             >>$OUTFILE 
	gcc -v 2>&1 | tail -1                                       >>$OUTFILE                                                                            2>&1
	$echocmd "c++:\n"                                            >>$OUTFILE
 	if test -f /usr/bin/g++
 	then
 		g++ -v 2>&1 | tail -1                             >>$OUTFILE                                                                            2>&1
 	else
 		echo /usr/bin/g++ not found                      >>$OUTFILE
 	fi
$echocmd "ld:\n"                                             >>$OUTFILE
	ld -V 2>&1 | head -1                                               >>$OUTFILE                                                                            2>&1
        $echocmd "\n"                                                >>$OUTFILE
	$echocmd "\nShared memory Usage:\n\n"                        >>$OUTFILE
	ipcs -ma                                                     >>$OUTFILE 
        $echocmd "\n"                                                >>$OUTFILE
	$echocmd "\nResource Limits:\n\n"                            >>$OUTFILE
	ulimit -a                                                    >>$OUTFILE 
        $echocmd "\n"                                                >>$OUTFILE
        if [ -f $COBDIR/lmf/lmfgetpv ]; then
        	$echocmd "\nlmfgetpv returns:\n"                     >>$OUTFILE
                $COBDIR/lmf/lmfgetpv                                 >>$OUTFILE 
                $echocmd "\n"                                        >>$OUTFILE
        fi
        $echocmd "\nTail of LMF Log\n"                               >>$OUTFILE
	LMFDIR=$COBDIR/lmf/lmfgetpv |grep Loaded | sed "s/Loaded from //"
	if [ -f "$LMFDIR/MF-LMF.log" ]; then
        	tail -20 $LMFDIR/MF-LMF.log                          >>$OUTFILE
	fi

	grep mfcobol /etc/services >/dev/null
	if [ "$?" != "0" ]; then
	$echocmd "It would appear that the mfcobol line is missing from /etc/services\n"	                                                     >>$OUTFILE
	fi
	$echocmd "\n"                                                >>$OUTFILE

	$echocmd "\n\nFS Related Settings:\n"                        >>$OUTFILE
	$echocmd "FS is set to $FS\n"                                >>$OUTFILE
	$echocmd "FHREDIR is set to $FHREDIR\n"                      >>$OUTFILE
	$echocmd "\n"                                                >>$OUTFILE

	$echocmd "\n\nTerminfo Related Settings:\n"                  >>$OUTFILE
	$echocmd "TERM is set to $TERM\n"                            >>$OUTFILE
	$echocmd "LINES is set to $LINES\n"                          >>$OUTFILE
	$echocmd "COLUMNS is set to $COLUMNS\n"                      >>$OUTFILE
	$echocmd "TERMINFO is set to $TERMINFO\n"                    >>$OUTFILE
	$echocmd "COBTERMINFO is set to $COBTERMINFO\n"              >>$OUTFILE
        $echocmd "mfinfocmp returns:\n"                              >>$OUTFILE
	$COBDIR/bin/mfinfocmp                                        >>$OUTFILE 

        $echocmd "cobconvstrtest -a gives:\n"                        >>$OUTFILE
        $COBDIR/bin/cobconvstrtest -a                                >>$OUTFILE
        $echocmd "\n"                                                >>$OUTFILE
FOUND=no
for i in `find $HOME -type f -name '.mfcgienv' -print 2>/dev/null`
do
        $echocmd 'MFCGI Environment found: ' $i                      >>$OUTFILE
        $echocmd '--Start of CGI Environment'                        >>$OUTFILE
        cat $i                                                       >>$OUTFILE
        $echocmd '--End of CGI Environment'                          >>$OUTFILE
        $echocmd "\n"                                                >>$OUTFILE
        FOUND=yes
done

        $echocmd "\n"                                                >>$OUTFILE
        $echocmd 'cobpeekwww gives:'                                 >>$OUTFILE
        PATH=$COBDIR/bin/cgibin:$PATH cobpeekwww 127.0.0.1 2>/dev/null                                                                               >>$OUTFILE

case $FOUND in
        no)$echocmd 'NO MFCGI Environment found: '                   >>$OUTFILE ;;
esac

        $echocmd $LINE                                               >>$OUTFILE
	if [ -f $COBDIR/fixpacks/install.log ]; then
        	$echocmd "The contents of COBDIR/fixpacks/install.log are:\n\n"                                                                      >>$OUTFILE
 		cat $COBDIR/fixpacks/install.log                     >>$OUTFILE
	else
		$echocmd "No Fixpack install log found."             >>$OUTFILE
	fi
	$echocmd "\n"						     >>$OUTFILE

        $echocmd "\n\nEnd of report."                                >>$OUTFILE
        $echocmd "Polling complete.  Please forward the file '$OUTFILE' to Micro Focus \c"
        $echocmd "Support."

    else
        $echocmd "Incorrect PATH for COBOL directory.\n\nPlease determine the\c"
        $echocmd " correct directory for your Micro Focus\nCOBOL product and\c"
        $echocmd " execute utility again.\n"
    fi
fi
