#!/bin/sh
#-----------------------------------------------------------------------
#
# VISIT-CREATE-CHKSUMS - Create lists of the md5 checksums, sha1
#                        checksums, and file sizes for the visit
#                        distribution.
#
# Author: Eric Brugger
# Date:   August 30, 2005
#
# Usage:
#    visit-create-chksums -v <version> -d <distribution>
#
#-----------------------------------------------------------------------

dist=undefined
version=undefined

#
# The loop is executed once for each symbol on the execute line.  This means
# that $1 may be blank for later executions of the loop if any "shift 2"
# commands are executed.  The variable abc is not used in the loop.  
#
for abc
do
   case $1 in
      -d)
         dist=$2
         shift 2
         ;;
      -v)
         version=$2
         shift 2
         ;;
   esac
done

#
# Check that the distribution name and version number was provided.
#
if [ $dist = undefined ]
then
   echo "Usage: -v <version> -d <distribution>"
   exit
fi

if [ $version = undefined ]
then
   echo "Usage: -v <version> -d <distribution>"
   exit
fi

version2=`echo $version | tr "." "_"`

#
# Download the files.
#
rm -rf checksum_dir
mkdir checksum_dir
cd checksum_dir
echo "Downloading third_party..."
svn co svn+ssh://brugger@edison.nersc.gov/project/projectdirs/visit/svn/visit/tags/$version/third_party
echo "Downloading $version..."
svn co svn+ssh://brugger@edison.nersc.gov/project/projectdirs/visit/svn/visit/trunk/releases/$version

#
# Create an awk script for use with the filesize command
#
rm -f format_filesize
cat <<EOF > format_filesize
BEGIN { FS = " " }
      { printf "%-25s %s\n", \$5, \$9}
EOF

#
# Create a script to generate the file size.
#
rm -f filesize
cat <<EOF > filesize
#!/bin/sh
ls -l \$1 | sed "s/  */ /g" | gawk -f ../format_filesize
EOF
chmod 755 filesize

#
# Create the md5 checksums, the sha1 checksums, and the file sizes.
#
cmds="md5sum sha1sum sha256sum ../filesize"
for cmd in $cmds
do
   case $cmd in
      md5sum)
         property=checksums
         output=visit_md5_checksums
         ;;
      sha1sum)
         property=checksums
         output=visit_sha1_checksums
         ;;
      sha256sum)
         property=checksums
         output=visit_sha256_checksums
         ;;
      ../filesize)
         property="file sizes"
         output=visit_filesizes
         ;;
   esac

   rm -f $output

   cd $version
   echo ""                                                >  ../$output
   echo "The VisIt executable $property"                  >> ../$output
   echo ""                                                >> ../$output
   $cmd INSTALL_NOTES                                     >> ../$output
   $cmd VisIt-$version.dmg                                >> ../$output
   $cmd jvisit$version.tar.gz                             >> ../$output
   $cmd visit${version}.exe                               >> ../$output
   $cmd visit-install$version2                            >> ../$output
   $cmd visit${version}_x64.exe                           >> ../$output
   $cmd visit$version2.darwin-x86_64.tar.gz               >> ../$output
   $cmd visit$version2.linux-x86_64-ubuntu11.tar.gz       >> ../$output
   $cmd visit$version2.linux-x86_64-ubuntu11-wmesa.tar.gz >> ../$output
   $cmd visit$version2.linux-x86_64-ubuntu14.tar.gz       >> ../$output
   $cmd visit$version2.linux-x86_64-ubuntu14-wmesa.tar.gz >> ../$output
   $cmd visit$version2.linux-x86_64-rhel7.tar.gz          >> ../$output
   $cmd visit$version2.linux-x86_64-rhel7-wmesa.tar.gz    >> ../$output

   echo ""                                                >> ../$output
   echo "The VisIt source code $property"                 >> ../$output
   echo ""                                                >> ../$output
   $cmd build_visit$version2                              >> ../$output
   $cmd $dist.tar.gz                                      >> ../$output
   $cmd visitdev$version.exe                              >> ../$output
   cd ../third_party
   files=`ls`
   for file in $files
   do
      $cmd $file >> ../$output
      shift
   done
   cd ..

   shift
done
