#!/bin/sh

# mkAIXsnap
#
# This script can be used to extract, build, tar, compress and upload 
# the latest xCAT for AIX snapshot code.
#	- this will be the latest development snapshot
#	- the snapshot should be created as needed
#       - this script should run in the ../xcat-core/trunk directory
#         (ex. /u/ntest/svn/workspace/xcat/xcat-core/trunk)
#	- you will need SourceForge ssh access set up 
#	  ( get the contents of .ssh/id_rsa.pub on your local machine 
#	  and add it to .ssh/authorized_keys on shell1.sf.net in
#	   your home dir,  ex.  /home/users/n/no/no/nott )
#	- the tarball goes to:
#	  /home/groups/x/xc/xcat/htdocs/aix/devel
#	- the individual RPMs go to:
#	  /home/groups/x/xc/xcat/htdocs/aix/devel/core-snap
#	- nothing is added to the release download area
#

BLDTOP=`pwd`
RPMDIR=$BLDTOP/aix-core-snap
VER=`cat Version`

# upload to SourceForge ??
UPLOAD=0
if [ "$1" == "UPLOAD" -o "$1" == "upload" ]; then
  UPLOAD=1 
fi

if [ -d $RPMDIR ]
then
  # clean it up 
  rm -f $RPMDIR/instxcat
  rm -f $RPMDIR/*.rpm
  rm -f $RPMDIR/flist
  rm -f $RPMDIR/*.gz
else
  mkdir -p $RPMDIR
fi

#
# do an update from the trunk directory level
#
#svn update | tee $BLDTOP/coresvnup
#svn update

# create a simple install script
echo "# xCAT on AIX - install script" > $RPMDIR/instxcat

#
# build the RPMs
#
./makeperlxcatrpm
mv /opt/freeware/src/packages/RPMS/ppc/perl-xCAT-$VER-*rpm $RPMDIR/
echo "rpm -Uvh perl-xCAT-$VER-*rpm" >> $RPMDIR/instxcat

./makeclientrpm
mv /opt/freeware/src/packages/RPMS/ppc/xCAT-client-$VER-*rpm $RPMDIR/
echo "rpm -Uvh xCAT-client-$VER-*rpm" >> $RPMDIR/instxcat

./makeserverrpm
mv /opt/freeware/src/packages/RPMS/ppc/xCAT-server-$VER-*rpm $RPMDIR/
echo "rpm -Uvh --nodeps xCAT-server-$VER-*rpm" >> $RPMDIR/instxcat

./makexcatrpm
mv /opt/freeware/src/packages/RPMS/ppc/xCAT-$VER-*rpm $RPMDIR/
echo "rpm -Uvh xCAT-$VER-*rpm" >> $RPMDIR/instxcat

./makexcatsnrpm
mv /opt/freeware/src/packages/RPMS/ppc/xCATsn-$VER-*rpm $RPMDIR/

./makermcrpm
mv /opt/freeware/src/packages/RPMS/ppc/xCAT-rmc-$VER-*rpm $RPMDIR/
echo "rpm -Uvh xCAT-rmc-$VER-*rpm" >> $RPMDIR/instxcat

./makeuirpm
mv /opt/freeware/src/packages/RPMS/noarch/xCAT-UI-$VER-*rpm $RPMDIR/
#echo "rpm -Uvh xCAT-web-$VER-*rpm" >> $RPMDIR/instxcat

#
# create the tar.gz file to upload
#
chmod +x $RPMDIR/instxcat

# add to flist
echo "instxcat" > $RPMDIR/flist

# add the service node bundle files 
cp $BLDTOP/xCATaixSN.bnd $RPMDIR/
cp $BLDTOP/xCATaixSN2.bnd $RPMDIR/
cp $BLDTOP/xCATaixSSH.bnd $RPMDIR/
cp $BLDTOP/xCATaixSSL.bnd $RPMDIR/
echo "xCATaixSN.bnd" >> $RPMDIR/flist
echo "xCATaixSN2.bnd" >> $RPMDIR/flist
echo "xCATaixSSH.bnd" >> $RPMDIR/flist
echo "xCATaixSSL.bnd" >> $RPMDIR/flist

cd $RPMDIR
ls *.rpm >> flist

#TIME=`date +%Y%m%d%H%M`
tar -cvf core-aix-snap.tar -L flist
gzip core-aix-snap.tar

chgrp xcat *
chmod g+w *

#
# upload the tar file and RPMs to SourceForge
#
if [ $UPLOAD == 1 ]; then

  # clear out the old files - do this manually with winscp session!
#while ! rsync -urLv --delete aix-core-snap nott,xcat@web.sourceforge.net:/home/groups/x/xc/xcat/htdocs/aix/devel/
#do : ; done

# devel snapshot
scp *.rpm nott,xcat@web.sourceforge.net:/home/groups/x/xc/xcat/htdocs/aix/devel/core-snap
scp core-aix-snap.tar.gz nott,xcat@web.sourceforge.net:/home/groups/x/xc/xcat/htdocs/aix/devel

# release snapshot

scp *.rpm nott,xcat@web.sourceforge.net:/home/groups/x/xc/xcat/htdocs/aix/2.3/core-snap
scp core-aix-snap.tar.gz nott,xcat@web.sourceforge.net:/home/groups/x/xc/xcat/htdocs/aix/2.3


# new release
scp core-aix-2.3.tar.gz nott,xcat@web.sourceforge.net:/home/frs/project/x/xc/xcat/xcat/2.3.x_AIX/


# for dep-aix & mysql etc.
#scp ./dep-aix-2.3-200909241259.tar.gz nott,xcat@web.sourceforge.net:/home/frs/project/x/xc/xcat/xcat-dep/2.x_AIX/

fi

exit 0;