#!/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-web.tar xCAT-web
    #gzip -f /opt/freeware/src/packages/SOURCES/xCAT-web.tar
    #cd ./xCAT-web
    #rm -f /opt/freeware/src/packages/SRPMS/xCAT-web*rpm /opt/freeware/src/packages/RPMS/ppc/xCAT-web*rpm
    #rpm -ba xCAT-web.spec
    #rpm -Uvh /opt/freeware/src/packages/RPMS/ppc/xCAT-web*rpm

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

else
	if [ -f /etc/redhat-release ]
	then
   		pkg="redhat"
	else
   		pkg="packages"
	fi

	set -x
	tar --exclude=.svn -czf /usr/src/$pkg/SOURCES/xCAT-web-$VER.tar.gz xCAT-web
	rm -f /usr/src/$pkg/SRPMS/xCAT-web-$VER*rpm /usr/src/$pkg/RPMS/noarch/xCAT-web-$VER*rpm
	rpmbuild -ta /usr/src/$pkg/SOURCES/xCAT-web-$VER.tar.gz
	#rpm -Uvh /usr/src/$pkg/RPMS/noarch/xCAT-web-$VER*rpm
fi