#!/bin/sh

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

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

        #source=$PWD
        #cd /opt/freeware/src/packages/SOURCES
        #rm -f xCAT-client-$VER; ln -s $source/xCAT-client xCAT-client-$VER
        #rm -f /opt/freeware/src/packages/SRPMS/xCAT-client*rpm /opt/freeware/src/packages/RPMS/ppc/xCAT-client*rpm
        #echo '.svn' > /tmp/xcat-excludes
        #tar -X /tmp/xcat-excludes -cf xCAT-client-$VER.tar xCAT-client-$VER
        #gzip -f /opt/freeware/src/packages/SOURCES/xCAT-client-$VER.tar
        #cd $source/xCAT-client
        #rpm -ba xCAT-client.spec

        source=/opt/freeware/src/packages
        echo '.svn' > /tmp/xcat-excludes
        tar -X /tmp/xcat-excludes -cf $source/SOURCES/xCAT-client-$VER.tar xCAT-client
        gzip -f $source/SOURCES/xCAT-client-$VER.tar
        rm -f $source/SRPMS/xCAT-client*rpm $source/RPMS/ppc/xCAT-client*rpm
        rpm -ba xCAT-client/xCAT-client.spec
        #rpm -ta $source/SOURCES/xCAT-client-$VER.tar.gz
else
	if [ -f /etc/redhat-release ]
	then
   		pkg="redhat"
	else
   		pkg="packages"
	fi

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