#!/bin/sh

OSNAME=$(uname)
VER=`cat Version`

if [ "$OSNAME" = "AIX" ]
then

	#echo '.svn' > /tmp/xcat-excludes
	#tar -X /tmp/xcat-excludes -cf /opt/freeware/src/packages/SOURCES/xCAT-server-$VER.tar xCAT-server
	#gzip -f /opt/freeware/src/packages/SOURCES/xCAT-server-$VER.tar
	#cd ./xCAT-server
	#rm -f /opt/freeware/src/packages/SRPMS/xCAT-server-$VER*rpm /opt/freeware/src/packages/RPMS/ppc/xCAT-server-$VER*rpm
	#rpm -ba xCAT-server.spec
	#rpm -Uvh /opt/freeware/src/packages/RPMS/ppc/xCAT-server-$VER*rpm

	source=/opt/freeware/src/packages
	echo '.svn' > /tmp/xcat-excludes
	tar -X /tmp/xcat-excludes -cf $source/SOURCES/xCAT-server-$VER.tar xCAT-server
	gzip -f $source/SOURCES/xCAT-server-$VER.tar
	rm -f $source/SRPMS/xCAT-server-$VER*rpm $source/RPMS/ppc/xCAT-server-$VER*rpm
	rpm -ba xCAT-server/xCAT-server.spec
	#rpm -ta $source/SOURCES/xCAT-server-$VER.tar.gz

else

	rpmbuild --version > /dev/null
	if [ $? -gt 0 ]
	then
		echo "Error: Is rpmbuild installed and working?"
		exit 1
	fi
	RPMROOT=`rpmbuild --eval '%_topdir' xCATsn/xCATsn.spec`
	if [ $? -gt 0 ]
	then
		echo "Could not determine rpmbuild's root"
		exit 1
	fi
	echo "The location for rpm building is ${RPMROOT}"

	tar --exclude .svn -czf $RPMROOT/SOURCES/xCAT-server-$VER.tar.gz xCAT-server
	rm -f $RPMROOT/SRPMS/xCAT-server-$VER*rpm $RPMROOT/RPMS/noarch/xCAT-server-$VER*rpm
	rpmbuild -ta $RPMROOT/SOURCES/xCAT-server-$VER.tar.gz
	#rpm -Uvh $RPMROOT/RPMS/noarch/xCAT-server-$VER*rpm

fi
