Index: trunk/test/testrun_2c.sh
===================================================================
--- trunk/test/testrun_2c.sh	(revision 1)
+++ trunk/test/testrun_2c.sh	(revision 19)
@@ -1,189 +1,102 @@
 #! /bin/sh
 
+SERVER_BUILDOPTS="--quiet  $TRUST --enable-xml-log --enable-debug --enable-network=server --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-logserver=${SH_LOCALHOST}  --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-database=mysql"; export SERVER_BUILDOPTS
 
-# The following two are the ANSI sequences for start and end embolden
-case $TERM in
-vt*|ansi*|con*|xterm*|linux*|screen*)
-  S=[1m
-  E=[m
-  ;;
-*)
-  S=
-  E=
-  ;;
-esac
+CLIENT_BUILDOPTS="--quiet  $TRUST --prefix=$PW_DIR --localstatedir=$PW_DIR --enable-network=client --disable-mail --disable-external-scripts --enable-login-watch --enable-xml-log --enable-db-reload --with-logserver=localhost --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock"; export CLIENT_BUILDOPTS
 
-PW_DIR=`pwd`
+check_mysql_log () {
+    DATE="$1"
 
-if test x$UID != x; then
-  TRUST="--with-trusted=0,2,$UID"
-else
-  TRUST="--with-trusted=0,2"
-fi
+    rm -f test_log_db
+    echo "SELECT * FROM log WHERE entry_status = 'NEW' and log_time > '"${DATE}"';" | mysql --password=samhain -u samhain samhain >test_log_db
+    #
+    egrep "START.*Yule" test_log_db >/dev/null 2>&1
+    if [ $? -ne 0 ]; then
+	[ -z "$verbose" ] || log_msg_fail "Server start";
+	return 1
+    fi
+    egrep "NEW CLIENT" test_log_db >/dev/null 2>&1
+    if [ $? -ne 0 ]; then
+	[ -z "$verbose" ] || log_msg_fail "Client connect";
+	return 1
+    fi
+    egrep "Checking.*/bin" test_log_db >/dev/null 2>&1
+    if [ $? -ne 0 ]; then
+	[ -z "$verbose" ] || log_msg_fail "Client file check";
+	return 1
+    fi
+    egrep "EXIT.*Samhain" test_log_db >/dev/null 2>&1
+    if [ $? -ne 0 ]; then
+	[ -z "$verbose" ] || log_msg_fail "Client exit";
+	return 1
+    fi
+    egrep "EXIT.*Yule.*SIGTERM" test_log_db >/dev/null 2>&1
+    if [ $? -ne 0 ]; then
+	[ -z "$verbose" ] || log_msg_fail "Server exit";
+	return 1
+    fi
+    return 0
+}
 
-echo; echo "${S}__ STARTING TEST RUN CLIENT/SERVER W/MYSQL __${E}"; echo;
-echo Working directory: $PW_DIR
-
-MAKE=`which gmake`
-if test "x$?" = x1 ; then
-    MAKE="make -s"
-else
-    MAKE=`which gmake | sed -e "s%\([a-z:]\) .*%\1%g"` 
-    if test "x$MAKE" = x; then
-	MAKE="make -s"
-    elif test "x$MAKE" = xno; then
-	MAKE="make -s"
-    else
-	if test "x$MAKE" = "xwhich:"; then
-		MAKE="make -s"
-	else
-		MAKE="gmake -s"
-		gmake -v >/dev/null 2>&1 || MAKE="make -s"
-	fi
-    fi
-fi
-
-echo MAKE is $MAKE
-echo
-
+MAXTEST=1; export MAXTEST
 
 testrun2c ()
 {
-	#
-	# test standalone compilation
-	#
-	echo "${S}Building client and server${E}"; echo;
-	#
-	if test -r "Makefile"; then
-		$MAKE distclean
+    log_start "RUN FULL CLIENT/SERVER W/MYSQL"
+    #
+    if [ -z "$doall" ]; then
+	log_skip 1 $MAXTEST 'Client/server w/mysql (or use --really-all)'
+	return 0
+    fi
+    if [ x"$1" = x ]; then
+	[ -z "$quiet" ] && log_msg_fail "Missing hostname"
+    fi
+    MYSQL=`find_path mysql`
+    if [ -z "$MYSQL" ]; then
+	log_skip 1 $MAXTEST "mysql not found";
+	return 1
+    else
+	TEST=`echo "DESCRIBE log;" | mysql --password=samhain -u samhain samhain 2>/dev/null`
+	if [ $? -ne 0 -o -z "$TEST" ]; then
+	    log_skip 1 $MAXTEST "mysql not default setup"
+	    return 1
 	fi
-        #
-        #
-	# ${TOP_SRCDIR}/configure --quiet  $TRUST --enable-login-watch --enable-xml-log --enable-debug --enable-network=client --enable-srp --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-logserver=localhost  --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock
-	#
-	${TOP_SRCDIR}/configure --prefix=$PW_DIR --localstatedir=$PW_DIR --enable-network=client --disable-mail --disable-external-scripts --enable-login-watch --enable-xml-log --enable-db-reload --with-logserver=localhost --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-timeserver=localhost --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock
-	#
-	#
-	if test x$? = x0; then
-		echo "configure completed, exit status 0"; echo;
-		$MAKE  > /dev/null
-		if test x$? = x0; then
-		    echo "$MAKE completed, exit status $?"; echo;
-		else
-		    echo "${S}ERROR:${E} make failed, exit status $?"; echo;
-		    exit
-		fi
-
+    fi
+    #
+    SH_LOCALHOST=$1; export SH_LOCALHOST
+    #
+    DATE=`date '+%Y-%m-%d %T'`
+    #
+    testrun2a_internal
+    #
+    ORIGINAL="DatabaseSeverity=none"
+    REPLACEMENT="DatabaseSeverity=info"
+    ex $RCFILE <<EOF
+:%s/$ORIGINAL/$REPLACEMENT/g
+:wq
+EOF
+    #
+    do_test_1_a
+    if [ $? -ne 0 ]; then
+	[ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client/server w/mysql";
+    else
+    #
+	check_mysql_log "${DATE}"
+	if [ $? -ne 0 ]; then
+	    [ -z "$quiet" ] && log_fail 1 ${MAXTEST} "Client/server w/mysql";
 	else
-		echo "${S}ERROR:${E} configure failed, exit status $?"; echo;
-		exit
+	    [ -z "$quiet" ] && log_ok   1 ${MAXTEST} "Client/server w/mysql";
 	fi
-
-	# save binary and build server
-	#
-	cp samhain samhain.build
-	make clean
-
-        #
-	${TOP_SRCDIR}/configure --quiet  $TRUST --enable-xml-log --enable-debug --enable-network=server --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=REQ_FROM_SERVER$PW_DIR/testrc_2 --with-data-file=REQ_FROM_SERVER$PW_DIR/.samhain_file --with-logserver=${SH_LOCALHOST}  --with-log-file=$PW_DIR/.samhain_log --with-pid-file=$PW_DIR/.samhain_lock --with-database=mysql  
-
-#  --enable-login-watch --enable-mounts-check --enable-userfiles  --enable-identity=yule --enable-suidcheck --with-gpg=/usr/local/bin/gpg --with-fp="EF6C EF54 701A 0AFD B86A  F4C3 1AAD 26C8 0F57 1F6C"
-
-	#
-        # --with-database=mysql --with-libs=-L/usr/local/mysql/lib 
-	# --with-database=postgresql
-	#
-	if test x$? = x0; then
-		echo "configure completed, exit status 0"; echo;
-		$MAKE  > /dev/null
-		if test x$? = x0; then
-		    echo "$MAKE completed, exit status $?"; echo;
-		else
-		    echo "${S}ERROR:${E} make failed, exit status $?"; echo;
-		    exit
-		fi
-
-	else
-		echo "${S}ERROR:${E} configure failed, exit status $?"; echo;
-		exit
-	fi
-	echo "${S}Initialize database${E}"; echo;
-
-	rm -f ./.samhain_file
-	rm -f ./.samhain_log
-	rm -f ./.samhain_lock
+    fi
+    #
+    if [ -n "$cleanup" ]; then
 	rm -f ./rc.${SH_LOCALHOST}
 	rm -f ./file.${SH_LOCALHOST}
-
-	cp ${SCRIPTDIR}/testrc_2.in testrc_2
-
-	# Create a password
-	SHPW=`./yule -G`
-	if test x"$SHPW" = x; then
-	    echo "password not generated -- aborting"
-	    exit 1
-	fi
-
-	# Set in client
-	echo "./samhain_setpwd samhain.build new $SHPW"
-	./samhain_setpwd samhain.build new $SHPW
-	mv samhain.build.new samhain.new
-	SHCLT=`./yule -P $SHPW | sed s%HOSTNAME%${SH_LOCALHOST}%`
- 	echo $SHCLT >> testrc_2
-
-	echo "./samhain.new -t init"
-	./samhain.new -t init
-
-	SHINI=$?
-
-	rm -f ./.samhain_log
-	rm -f ./.samhain_lock
-
-	cp    ./testrc_2              ./rc.${SH_LOCALHOST}
-	mv    ./.samhain_file         ./file.${SH_LOCALHOST}
-
-	if test x$SHINI = x0; then
-
-		echo; echo "${S}Start Server${E}: ./yule  &"; echo;
-		./yule &
-		PROC_Y=$!
-		sleep 5
-
-		echo; echo "${S}Start Client${E}: ./samhain.new -l none -p none -e info -t check";
-
-		./samhain.new -t check -p none -l none -e info 
-		if test x$? = x0; then
-		    echo "${S}check completed${E}"
-		else
-		    echo "${S}ERROR:${E} -- check -- failed, exit status $?"
-		    echo
-		    kill $PROC_Y
-		    exit
-		fi
-
-		kill $PROC_Y
-		sleep 5
-	else
-		echo "${S}ERROR:${E} -- init -- failed, exit status $SHINI"; 
-		echo;
-		exit
-	fi
-	    
+	ALTHOST=`find_hostname`
+	rm -f "./file.${ALTHOST}"
+	rm -f "./rc.${ALTHOST}"
+    fi
+    #
+    log_end "RUN FULL CLIENT/SERVER W/MYSQL"
 }
 
-    if test x$1 = x; then
-	echo
-	echo "Please provide the local hostname as argument."
-	echo
-	exit 8
-    fi
-
-    SH_LOCALHOST=$1; export SH_LOCALHOST
-
-    testrun2c
-
-
-echo; echo "${S}__ END TEST RUN CLIENT/SERVER W/MYSQL __${E}"; echo;
-
-exit
-
