#!/bin/sh
# Testing Script for the PEC proyect
# Marcelo Lorenzati 2008
clear
if [ $1 ]; then
    nTest=$1
else 
    printf "TEST for the PEC proyect\n"
    printf "TEST: Type the test number\n"
    read nTest
fi
Myfile='pec_plugin_'$nTest'.conf'
if [ -f $Myfile ]; then
    printf "\nTEST: The test file $Myfile exist"
    printf "\nTEST: Stopping broker\n"     
    killall -9 sfcbd
    sleep 1 
    printf "\nTEST: Repos to the broker\n"
    sfcbrepos -f
    printf "\nTEST: Re-execute broker\n"   
    sfcbd &
    sleep 3
    if ! ( kill -0 $! 2> /dev/null ) ; then
    printf "\nTEST: Cannot execute broker\n"
    exit 1
    fi
    printf "\nTEST: Copying configuration file to client folder\n"
    cp $Myfile ../client/pec_plugin.conf || error_return "TEST: Cannot copy configuration file"
    cd ../client && ./pecloader.pl || error_return "TEST: Cannot execute the CIM loader SCHEMA script."
    cd ../test
    if  [ $nTest -le 37 ] ; then
        printf "\nTEST: Concluded succesfully, analyse results\n"
        exit 0
    else
        case `expr $nTest \+ 0` in
#           38) ./pectest
#               killall -9 sfcbd;;
            44) cp check_abort /usr/local/nagios/libexec;;
            * ) echo "TEST: Not programmed yet";;
        esac
    fi
else
    printf "\nTEST: The test file $Myfile do not exist\n"
    exit 1
fi
