#!/bin/sh

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

if [ "$OSNAME" = "AIX" ]
then
    cd `dirname $0`/xCATsn
    echo '.svn' > /tmp/xcat-excludes
	echo 'upflag' >> /tmp/xcat-excludes

    tar -X /tmp/xcat-excludes -cf /opt/freeware/src/packages/SOURCES/license.tar LICENSE.html
    gzip -f /opt/freeware/src/packages/SOURCES/license.tar

#    cp xcat.conf /opt/freeware/src/packages/SOURCES
#    cp xCATSN /usr/src/$pkg/SOURCES

	cp xCATSN /opt/freeware/src/packages/SOURCES
    rm -f /opt/freeware/src/packages/SRPMS/xCATsn-$VER*rpm /opt/freeware/src/packages/RPMS/ppc/xCATsn-$VER*rpm
    cd -

    rpm -ba xCATsn/xCATsn.spec
    #rpm -Uvh /opt/freeware/src/packages/RPMS/ppc/xCATsn-$VER*rpm

else

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

	cd `dirname $0`/xCATsn
	tar --exclude .svn -czf /usr/src/$pkg/SOURCES/license.tar.gz LICENSE.html
	cp xcat.conf /usr/src/$pkg/SOURCES
        cp xCATSN /usr/src/$pkg/SOURCES
	rm -f /usr/src/$pkg/SRPMS/xCATsn-$VER*rpm /usr/src/$pkg/RPMS/*/xCATsn-$VER*rpm
	cd -
   if [ ! -z "$1" ]; then
	rpmbuild -ba xCATsn/xCATsn.spec --target $1
   else
	rpmbuild -ba xCATsn/xCATsn.spec
   fi
fi