#! /bin/sh
#
# @(#)CHECKINSTALL version 3.11 created 6/19/96
# @(#)Copyright (c), 1987, 1996 StatSci, Inc.  All rights reserved.
#
# This script is used to verify that the installation of S-PLUS was
# successful. It is invoked as follows:
#
#    Splus CHECKINSTALL [clean] [sumall] [manifest] [tests] [load] [all]
#
# If given an argument of "clean", it will clean up any temporary files that
# may have been created by any previous run of "Splus CHECKINSTALL".
#
# A "sumall" argument will cause checksums to be checked for ALL files in the
# distribution instead of a default subset of the files.
#
# The arguments "manifest", "tests" and "load" are used to specify which
# portions of the verification procedure to run. If any are specified, then
# only those parts will be run. If either none or "all" are specified, then
# all of the verifications will be run.
# 

tmpdir=${TMPDIR:-/tmp}
trap 'rm -f $tmpdir/CHECKINSTALL.$$' 0

# Make sure we were run properly (i.e. through an Splus script that set $SHOME)
if [ "X$SHOME" = X ]
then
    echo '$SHOME is not set. This script should be run through the Splus script:'
    echo '   Splus CHECKINSTALL'
    exit 1
fi >&2

if [ ! -d ${SHOME}/adm/verify ]
then
    echo "No such directory: $SHOME/adm/verify"
    echo
    echo "Could not find verification testing files!"
    exit 1
fi >&2

if [ ! -r ${SHOME}/cmd/S ]
then
    echo "No such file: $SHOME/cmd/S" >&2
    echo "Please refer to the installation instructions and run the" >&2
    echo "INSTALL script, as it does not appear to have been run." >&2
    exit 1
fi

SPLUS_SCRIPT=$SHOME/cmd/S export SPLUS_SCRIPT
S_WORK=$SHOME/adm/verify/.Data.$$ export S_WORK
S_SILENT_STARTUP=yes export S_SILENT_STARTUP

cd ${SHOME}

SUMALL=""
export SUMALL
MANIFEST=""
LOOP=""
LOAD=""

while [ $# -gt 0 ]
do case "$1" in
    clean)
        cd adm/verify
        echo "Removing files from previous 'Splus CHECKINSTALL' runs..."
        find .Data.* test_funs.* loop.tests/stat.att/Targets.* \
               -type f -print -exec rm -f {} \; 2>/dev/null
        find .Data.* test_funs.* loop.tests/stat.att/Targets.* \
               -depth -type d -print -exec rmdir {} \; 2>/dev/null
        find . \( -name '*~' -o -name '*.o' -o -name '*.so' -o -name '*.sl' \
               -o -name local.Sqpe \) -print -exec rm -f {} \; 2>/dev/null
        exit 0
    ;;
    sumall) SUMALL=yes;;
    manifest) MANIFEST=yes;;
    tests) LOOP=yes;;
    load) LOAD=yes;;
    all) MANIFEST=yes; LOOP=yes; LOAD=yes;;
esac; shift; done

if [ "X$MANIFEST$LOOP$LOAD" = X ]
then # None specified...default to all.
    MANIFEST=yes; LOOP=yes; LOAD=yes
fi

rm -rf $S_WORK
mkdir $S_WORK

status=0

echo; echo '########## S-PLUS information'
echo 'S.info(file="")' | S_BYPASS_SCRIPT_CHECK=1 Splus Sqpe
echo ; echo

# Make sure all distributed files were installed.
SPLUS_MANIFEST=${SPLUS_MANIFEST-${SHOME}/adm/verify/MANIFEST}
export SPLUS_MANIFEST

[ "X$MANIFEST" = X ] || ./adm/verify/CHKMANI || status=1

cd ${SHOME}/adm/verify

# Run LOOP tests. 
[ "X$LOOP" = X ] ||
./LOOP sbug statsci stat.att thorough graphics || status=1

# Run LOAD tests.
if [ "X$LOAD" != "X" ] 
then
   echo ""
   echo ""
   echo "########## Running dynamic and static load tests"
   ./LOAD load || status=1
   ./load/LOAD.TEST || status=1
fi

# Report test status
echo
echo '======================================================================'
echo
date
echo
if [ $status -eq 0 ]
then        # Success!
    echo "The verification PASSED."
else        # Something failed.
    echo "At least one of the tests FAILED!!!"
fi
echo
echo '======================================================================'
echo

exit $status

