#! /bin/sh
# ------------------------------------------------------------------------
# Makes releases of the dbf2info test suites.
#
# For transporting the test suites to other machines.
#
# ------------------------------------------------------------------------
#
#
# Set a temporary place to put the released files.
# If the tmp directory exists, it will be renamed as -old.
# If the -old tmp exists, it will be deleted.
#
tmp=/usr132/rbd/xxtemp
#
#
# Set a place to put the tar file(s).
#
release_path=/usr132/rbd/releases
#
#
# Set whether or not to create the release tar files.
#
make_compressed_tar=1
make_gzipped_tar=1
#
#
# Set whether or not to delete the tmp directory after taring.
# This is only done if set to 1 AND one of the make_*_tar options are also 1.
#
rm_tmp_after_tar=1
#
#
# --------------------------------------------------
# You should not have to change anything below here.
# --------------------------------------------------
#
# Set up.
#
dbfhome=`pwd`
tempfile=xxdbfrel.tmp
#
# Retain old release directory if it exists.
#
if [ -d $tmp ] ;then
  if [ -d $tmp'-old' ] ;then
    rm -r $tmp'-old'
  fi
  mv $tmp $tmp'-old'
fi
#
#
#
#
for testtype in unix arc
  do
    dirname=test$testtype
    cd $dbfhome
    #
    # Copy the directory to be released to tmp
    #
    cp -rp $dirname $tmp
    #
    # Make tar?
    #
    if [ $make_compressed_tar -eq 1 -o $make_gzipped_tar -eq 1 ] ;then
      cd $tmp
      tarfile=$release_path/dbf-tests-$testtype.tar
      #
      # Delete existing tar.
      #
      if [ -f $tarfile ] ;then
        rm -f $tarfile
        if [ -f $tarfile ] ;then
          echo Could not delete existing $tarfile.
          exit
        fi
      fi
      #
      # Make the tar.
      #
      cd $tmp
      tar -cvf $tarfile . > /dev/null
      if [ ! -f $tarfile ] ;then
        echo Tar failed to create $tarfile.
        exit
      fi
      #
      # Make compressed tarfile?
      #
      if [ $make_compressed_tar -eq 1 ] ;then
        #
        # Save a copy if doing gzip also.
        #
        if [ $make_gzipped_tar -eq 1 ] ;then
          cp $tarfile $tempfile
        fi
        #
        # Delete existing compressed tarfile.
        #
        if [ -f $tarfile'.Z' ] ;then
          rm -f $tarfile'.Z'
        fi
        #
        compress $tarfile
        #
        # Rename uncompressed copy if doing gzip also.
        #
        if [ $make_gzipped_tar -eq 1 ] ;then
          mv $tempfile $tarfile
        fi
      fi
      #
      # Make gzipped tarfile?
      #
      if [ $make_gzipped_tar -eq 1 ] ;then
        #
        # Delete existing gzipped tarfile.
        #
        if [ -f $tarfile'.gz' ] ;then
          rm -f $tarfile'.gz'
        fi
        #
        gzip $tarfile
      fi
      #
      # Remove the temporary directory
      #
      cd $dbfhome
      if [ $rm_tmp_after_tar -eq 1 ] ;then
        rm -rf $tmp
      fi
    fi
  done
#
#
# Done.
#
cd $dbfhome
exit
