#!/bin/sh
# 2/16/05 - combine common functions, use waivers

# not always the case, test script may override
ARCH=`rpm --eval %{_host_cpu} | sed 's|^i6|i3|'`
WAIVERS="/usr/share/lsb/waivers.txt"
TEST_USER="Auto LSB Test User"
TEST_ORG="Mandrakesoft"
TEST_SYS=`cat /etc/mandrakelinux-release`
TET_HOME="/home/tet/test_sets"
PROFILE="$TET_HOME/.profile"
BLK_DEV="$TET_HOME/nonexistb"
KERNEL=vmlinuz-`uname -r`
HOSTNAME=`hostname`
VSX0_PASS=lsb123
VSX1_PASS=2wsxcde3
VSX2_PASS=3edcxsw2
TVERSION=released

if [ "$1" = "no-waivers" -o "$2" = "no-waivers" ]; then
	TJREPORT=/usr/bin/tjreport
else
	TJREPORT="/usr/bin/tjreport -w $WAIVERS"
fi

install_rpm() {
	if rpm -q $1 | grep -q 'not installed'; then
		urpmi -q $1 || exit 1
	fi
}

retrieve_rpm() {
	if rpm -q $1 | grep -q 'not installed'; then
		rpm -i ftp://ftp.freestandards.org/pub/lsb/test_suites/$TVERSION/binary/runtime/$1*.$ARCH.rpm > /dev/null 2>&1 || exit 1
	fi
}

remove_conflict() {
	if rpm -q $1 | grep -q 'not installed'; then
		echo "$1 not installed..." > /dev/null
	else
		rpm -e $1 || exit 1
	fi
}

clean_file() {
	if [ -f $1 ]; then
		rm -f $1
	fi
}

report_results() {
	if [ -n "$1" ]; then
        	if $TJREPORT $1 | grep -q '(excluding waived): 0'; then
                	exit 0
        	else
                	if [ "$2" = "cron" ]; then
				$TJREPORT $JOURNAL | mail $LOGNAME
			else						
				$TJREPORT $1
			fi
        	fi
	else
		if [ "$2" = "cron" ]; then
			echo "No journal file..." | mail $LOGNAME
		else
        		echo "No journal file..."
		fi
	fi
}
