#! /bin/bash

# This script may ONLY be run on Linux!
OS=`uname`
if [ ${OS} != "Linux" ]; then
	printf "The '$0' script is ONLY executable on a 'Linux' machine!\n"
	exit 255
fi

# If Fedora, retrieve the release
if [ -f /etc/fedora-release ]; then
	FEDORA_RELEASE=`cat /etc/fedora-release | awk {'print $3'}`
fi

ARCH=`uname -p`
if [ "${ARCH}" = "x86_64" ]; then
	if	[ -f /etc/fedora-release ] &&
		[ ${FEDORA_RELEASE} -ge 19 ]; then
		JNIDIR=/usr/lib/java
	elif	[ -f /etc/fedora-release ] &&
		[ ${FEDORA_RELEASE} -ge 16 ]; then
		JNIDIR=/usr/lib64/java
	else
		JNIDIR=/usr/lib/java
	fi
elif	[ ${ARCH} != "i686" ] ||
		[ ${ARCH} != "i586" ] ||
		[ ${ARCH} != "i486" ] ||
		[ ${ARCH} != "i386" ]; then
	JNIDIR=/usr/lib/java
else
	printf "The '$0' script is NOT executable on the '${ARCH}' architecture!\n"
	exit 255
fi

if [ -f /etc/fedora-release ]; then
	# Script is being run on Fedora
	ant -f build.xml -Drhel=0 -Djnidir=${JNIDIR} -Dspecfile=tomcatjss.spec rpms
elif [ -f /etc/redhat-release ]; then
	# Script is being run on RHEL
	ant -f build.xml -Drhel=1 -Djnidir=${JNIDIR} -Dspecfile=tomcatjss.spec rpms
fi

