#!/bin/sh
OSNAME=$(uname)
VER=`cat Version`

if [ "$OSNAME" = "AIX" ]
then
    #source=$PWD
    #cd /opt/freeware/src/packages/SOURCES
    #rm -f xCAT-rmc-$VER; ln -s $source/xCAT-rmc xCAT-rmc-$VER
    #rm -f /opt/freeware/src/packages/SRPMS/xCAT-rmc*rpm /opt/freeware/src/packages/RPMS/ppc/xCAT-rmc*rpm
    #echo '.svn' > /tmp/xcat-excludes
    #tar -X /tmp/xcat-excludes -cf xCAT-rmc-$VER.tar xCAT-rmc-$VER
    #gzip -f /opt/freeware/src/packages/SOURCES/xCAT-rmc-$VER.tar
    #cd $source/xCAT-rmc
    #rpm -ba xCAT-rmc.spec
    #rpm -Uvh /opt/freeware/src/packages/RPMS/ppc/xCAT-rmc*rpm
    
    source=/opt/freeware/src/packages
    echo '.svn' > /tmp/xcat-excludes
    tar -X /tmp/xcat-excludes -cf $source/SOURCES/xCAT-rmc-$VER.tar xCAT-rmc
    gzip -f $source/SOURCES/xCAT-rmc-$VER.tar
    rm -f /opt/freeware/src/packages/SRPMS/xCAT-rmc*rpm /opt/freeware/src/packages/RPMS/ppc/xCAT-rmc*rpm
    rpm -ba xCAT-rmc/xCAT-rmc.spec
    #rpm -Uvh $source/RPMS/ppc/xCAT-rmc*rpm

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

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