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

# not always the case, test script may override
ARCH=`rpm --eval %{_host_cpu} | sed 's|^i5|i4|'`
WAIVERS="/usr/share/lsb/waivers.txt"
TEST_USER="Auto LSB Test User"
TEST_ORG="Mandriva"
TEST_SYS=`cat /etc/mandriva-release`
TET_HOME="/home/tet/test_sets"
PROFILE="$TET_HOME/.profile"
BLK_DEV="$TET_HOME/nonexistb"
INIT_PATH="/etc"
KERNEL=vmlinuz-`uname -r`
HOSTNAME=`hostname`
VSX0_USER=vsx0
VSX0_PASS=1qazxsw2
VSX1_PASS=2wsxcde3
VSX2_PASS=3edcxsw2
if [ -z "$TVERSION" ];then
  TVERSION=released
fi
TPATH=ftp://ftp.freestandards.org/pub/lsb/test_suites/$TVERSION/binary/runtime
# fix this for arch
APATH=ftp://ftp.freestandards.org/pub/lsb/app-battery/$TVERSION/ia32

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
		/usr/sbin/urpmi -q $1 || exit 1
	fi
}

retrieve_rpm() {
	if rpm -q $1 | grep -q 'not installed'; then
		# seems LSB folks give files different names than the
		# rpm database knows them by
		FNAME=`echo $1 | sed 's|-lite||'`
		rpm -i $TPATH/$FNAME*.$ARCH.rpm > /dev/null 2>&1 || exit 1
	fi
}

retrieve_app_rpm() {
	if rpm -q $1 | grep -q 'not installed'; then
		rpm -i $APATH/$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
}
