#!/bin/sh
#
# This script works for SunOS
#
TIME="`date +%H%M`"
DATE="`date +%d%h%y`"
#
# Get rid of blanks in the date
TAGVAL="zoltan_distrib_${DATE}_${TIME}"
CURDIR="`pwd`"
#
# Get rid of space when day of the month is a single digit
ACT_TAG="`echo "$TAGVAL"|sed s/' '//g`"
rm -rf Zoltan ParMETIS3_1 Trilinos Scotch
rm -f *.gz
#
#Zoltan checkout
git clone software.sandia.gov:/space/git/Trilinos
cd Trilinos/packages
git branch trilinos-release-10-4-branch origin/trilinos-release-10-4-branch
git checkout trilinos-release-10-4-branch
#
# Include ParMETIS in distribution
cvs -d software:/space/CVS-Zoltan checkout -P ParMETIS3_1
cd ParMETIS3_1; /bin/rm -rf Graphs; cd ..
cvs -d software:/space/CVS-Zoltan rtag ${ACT_TAG} ParMETIS3_1
tar czf parmetis_3.1.tar.gz ParMETIS3_1
/bin/rm -rf ParMETIS3_1
#
# Include Scotch in distribution
cvs -d software:/space/CVS-Zoltan checkout Scotch
/bin/mv Scotch/scotch*gz .
cvs -d software:/space/CVS-Zoltan rtag ${ACT_TAG} Scotch
/bin/rm -rf Scotch
#
# Remove needless files
find . -name 'CVS' -exec rm -rf {} \;
find . -name '*.sh' -exec rm -f {} \;
find . -name '.cvsignore' -exec rm -f {} \;
#
# Remove stuff we don't want to share.
cd zoltan; /bin/rm -rf docs/internal; cd ..
cd zoltan; /bin/rm -rf test/nem*; cd ..
cd zoltan; /bin/rm -rf test/th; cd ..
# KDDKDD MAY NOT ALWAYS WANT TO DELETE ALL OF TEST
cd zoltan; /bin/rm -rf test; cd ..
cd zoltan; /bin/rm -rf src/util/converters_for_JPDC_adaptive_mesh_experiments; cd ..
#
# Remove $ from Revision so that other people don't change Revision when
# checking Zoltan into their own CVS repositories.
rm -rf tmp
FLIST="`find zoltan -name '*.[ch]' -print`"
for i in ${FLIST}  ; do \
  echo $i
  sed -e 's/\$Revision/Revision/' $i > tmp; \
  /bin/mv tmp $i; \
done;
FLIST="`find zoltan -name '*.f??' -print`"
for i in ${FLIST}  ; do \
  echo $i
  sed -e 's/\$Revision/Revision/' $i > tmp; \
  /bin/mv tmp $i; \
done;
FLIST="`find zoltan -name '[mM]akefile*' -print`"
for i in ${FLIST}  ; do \
  echo $i
  sed -e 's/\$Revision/Revision/' $i > tmp; \
  /bin/mv tmp $i; \
done;
FLIST="`find zoltan -name 'Config*' -print`"
for i in ${FLIST}  ; do \
  echo $i
  sed -e 's/\$Revision/Revision/' $i > tmp; \
  /bin/mv tmp $i; \
done;
#
# Build tarball.
chmod -R ogu+r *
mv zoltan Zoltan_v3.3
tar cvf zoltan_distrib_v3.3.tar Zoltan_v3.3 parmetis*gz scotch*gz
gzip zoltan_distrib_v3.3.tar
#
# Tag repository.
git tag -a ${ACT_TAG} -m "Distribution created"
git push --tags

exit 0
