#!/bin/sh
#-----------------------------------------------------------------------
#
# VISIT-BUILD-OPEN - Build the visit distributions on the open network.
#
# Author: Eric Brugger
# Date:   October 27, 2000
#
# Usage:
#    visit-build-open -d <distribution>
#
#-----------------------------------------------------------------------

test=no

user=`whoami`

#
# Set the user e-mail address.
#
emailName=brugger1@llnl.gov
case $user in
   ahern)
      emailName=ahern1@llnl.gov
      ;;
   kbonnell)
      emailName=bonnell2@llnl.gov
      ;; 
   brugger)
      emailName=brugger1@llnl.gov
      ;;
   childs)
      emailName=childs3@llnl.gov
      ;;
   jennings)
      emailName=jennings4@llnl.gov
      ;;
   meredith)
      emailName=meredith6@llnl.gov
      ;;
   murguia)
      emailName=murguia1@llnl.gov
      ;;
   whitlocb)
      emailName=whitlock2@llnl.gov
      ;;
esac

#
# Parse the execute line, providing default values for error checking.
#
kickit=true
sunspot=true
hyper=true
gps=true
berg=true
pengra=true
thunder=true

dist=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
      -none)
         kickit=false
         sunspot=false
         hyper=false
         gps=false
         berg=false
         pengra=false
         thunder=false
         shift
         ;;
      -kickit)
         kickit=false
         shift
         ;;
      +kickit)
         kickit=true
         shift
         ;;
      -sunspot)
         sunspot=false
         shift
         ;;
      +sunspot)
         sunspot=true
         shift
         ;;
      -hyper)
         hyper=false
         shift
         ;;
      +hyper)
         hyper=true
         shift
         ;;
      -gps)
         gps=false
         shift
         ;;
      +gps)
         gps=true
         shift
         ;;
      -berg)
         berg=false
         shift
         ;;
      +berg)
         berg=true
         shift
         ;;
      -pengra)
         pengra=false
         shift
         ;;
      +pengra)
         pengra=true
         shift
         ;;
      -thunder)
         thunder=false
         shift
         ;;
      +thunder)
         thunder=true
         shift
         ;;
      -d)
         dist=$2
         shift 2
         ;;
   esac
done

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

#
# Check that the distribution exists.
#
distfile=$dist.tar.gz
if [ ! -f $distfile ]
then
   echo "Distribution file doesn't exist."
   exit
fi

#
# Build on kickit.
#
rm -f kickit
cat <<EOF > kickit
#!/bin/sh
if test ! -e /var/tmp/$user ; then
   mkdir /var/tmp/$user
fi
if test ! -e /var/tmp/$user/kickit ; then
   mkdir /var/tmp/$user/kickit
fi
rm -rf /var/tmp/$user/kickit/visitbuild
mkdir /var/tmp/$user/kickit/visitbuild
mv kickit_$dist.tar.gz /var/tmp/$user/kickit/visitbuild/$dist.tar.gz
cd /var/tmp/$user/kickit/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 ./configure >> ../buildlog 2>&1
make -j 4 >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.linux.tar.gz ..
cd ..
rm -f resultlog
echo "        build of visit on kickit"       > resultlog 2>&1
echo "       --------------------------"      >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail $emailName < resultlog
EOF

if [ $kickit = true ]
then
   if [ $test = no ]
   then
      scp kickit kickit:kickit_buildit
      scp $dist.tar.gz kickit:kickit_$dist.tar.gz
      ssh kickit "chmod 750 kickit_buildit;./kickit_buildit" &
   fi
fi

#
# Build on sunspot.
#
rm -f sunspot
cat <<EOF > sunspot
#!/bin/sh
if test ! -d /export/scratch/$user ; then
   mkdir /export/scratch/$user
fi
if test ! -d /export/scratch/$user/sunspot ; then
   mkdir /export/scratch/$user/sunspot
fi
rm -rf /export/scratch/$user/sunspot/visitbuild
mkdir /export/scratch/$user/sunspot/visitbuild
mv sunspot_$dist.tar.gz /export/scratch/$user/sunspot/visitbuild/$dist.tar.gz
cd /export/scratch/$user/sunspot/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 ./configure --with-config=config-site/sunspot-gcc-2952.llnl.gov.conf >> ../buildlog 2>&1
make -j 4 >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.sunos5.tar.gz ..
cd ..
rm -f resultlog
echo "        build of visit on sunspot"      > resultlog 2>&1
echo "       ---------------------------"     >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail $emailName < resultlog
EOF

if [ $sunspot = true ]
then
   if [ $test = no ]
   then
      scp sunspot sunspot:sunspot_buildit
      scp $dist.tar.gz sunspot:sunspot_$dist.tar.gz
      ssh sunspot "chmod 750 sunspot_buildit;./sunspot_buildit" &
   fi
fi

#
# Build on hyper.
#
rm -f hyper
cat <<EOF > hyper
#!/bin/sh
if test ! -d /scratch1/$user ; then
   mkdir /scratch1/$user
fi
if test ! -d /scratch1/$user/hyper ; then
   mkdir /scratch1/$user/hyper
fi
rm -rf /scratch1/$user/hyper/visitbuild
mkdir /scratch1/$user/hyper/visitbuild
mv hyper_$dist.tar.gz /scratch1/$user/hyper/visitbuild/$dist.tar.gz
cd /scratch1/$user/hyper/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 ./configure >> ../buildlog 2>&1
env PARALLEL=4 make -P >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.irix6.tar.gz ..
cd ..
rm -f resultlog
echo "        build of visit on hyper"        > resultlog 2>&1
echo "       -------------------------"       >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail $emailName < resultlog
EOF

if [ $hyper = true ]
then
   if [ $test = no ]
   then
      scp hyper hyper:hyper_buildit
      scp $dist.tar.gz hyper:hyper_$dist.tar.gz
      ssh hyper "chmod 750 hyper_buildit;./hyper_buildit" &
   fi
fi

#
# Build on gps.
#
rm -f gps
cat <<EOF > gps
#!/bin/sh
if test ! -e /nfs/tmp3/$user ; then
   mkdir /nfs/tmp3/$user
fi
if test ! -e /nfs/tmp3/$user/gps; then
   mkdir /nfs/tmp3/$user/gps
fi
rm -rf /nfs/tmp3/$user/gps/visitbuild
mkdir /nfs/tmp3/$user/gps/visitbuild
mv gps_$dist.tar.gz /nfs/tmp3/$user/gps/visitbuild/$dist.tar.gz
cd /nfs/tmp3/$user/gps/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 MAKE=gmake ./configure --enable-parallel >> ../buildlog 2>&1
gmake >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.osf1.tar.gz ..
cd ..
rm -f resultlog
echo "        build of visit on gps"          > resultlog 2>&1
echo "       -----------------------"         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail $emailName < resultlog
EOF

if [ $gps = true ]
then
   if [ $test = no ]
   then
      scp gps gps15:gps_buildit
      scp $dist.tar.gz gps15:gps_$dist.tar.gz
      ssh gps15 "chmod 750 gps_buildit;./gps_buildit" &
   fi
fi

#
# Build on berg, both serial and parallel versions.
#
rm -f berg
cat <<EOF > berg
#!/bin/sh
if test ! -e /p/glocal1/$user ; then
   mkdir /p/glocal1/$user
fi
if test ! -e /p/glocal1/$user/berg ; then
   mkdir /p/glocal1/$user/berg
fi
rm -rf /p/glocal1/$user/berg/visitbuild
mkdir /p/glocal1/$user/berg/visitbuild
mv berg_$dist.tar.gz /p/glocal1/$user/berg/visitbuild/$dist.tar.gz
cd /p/glocal1/$user/berg/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 MAKE=gmake ./configure --enable-parallel >> ../buildlog 2>&1
gmake -j 4 >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.aix.tar.gz ..
cd ..
rm -f resultlog
echo "        build of visit on berg"         > resultlog 2>&1
echo "       ------------------------"        >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail $emailName < resultlog
EOF

if [ $berg = true ]
then
   if [ $test = no ]
   then
      scp berg berg:berg_buildit
      scp $dist.tar.gz berg:berg_$dist.tar.gz
      ssh berg "chmod 750 berg_buildit;./berg_buildit" &
   fi
fi

#
# Build on pengra.
#
rm -f pengra
cat <<EOF > pengra
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/pengra ; then
   mkdir /usr/tmp/$user/pengra
fi
rm -rf /usr/tmp/$user/pengra/visitbuild
mkdir /usr/tmp/$user/pengra/visitbuild
mv pengra_$dist.tar.gz /usr/tmp/$user/pengra/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/pengra/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 ./configure --enable-parallel >> ../buildlog 2>&1
make -j 3 >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.linux.tar.gz ..
cd ..
rm -f resultlog
echo "        build of visit on pengra"       > resultlog 2>&1
echo "       --------------------------"      >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail $emailName < resultlog
EOF

if [ $pengra = true ]
then
   if [ $test = no ]
   then
      scp pengra pengra0:pengra_buildit
      scp $dist.tar.gz pengra0:pengra_$dist.tar.gz
      ssh pengra0 "chmod 750 pengra_buildit;./pengra_buildit" &
   fi
fi

#
# Build on thunder.
#
rm -f thunder
cat <<EOF > thunder
#!/bin/sh
if test ! -d /usr/tmp/$user ; then
   mkdir /usr/tmp/$user
fi
if test ! -d /usr/tmp/$user/thunder ; then
   mkdir /usr/tmp/$user/thunder
fi
rm -rf /usr/tmp/$user/thunder/visitbuild
mkdir /usr/tmp/$user/thunder/visitbuild
mv thunder_$dist.tar.gz /usr/tmp/$user/thunder/visitbuild/$dist.tar.gz
cd /usr/tmp/$user/thunder/visitbuild
gunzip -c $dist.tar.gz | tar xvf - > buildlog 2>&1
cd $dist
ver=\`cat VERSION\`
ver2=\`echo \$ver | tr "." "_"\`
env CXXFLAGS=-O2 ./configure --enable-parallel >> ../buildlog 2>&1
make -j 3 >> ../buildlog 2>&1
clearcase_bin/visit-bin-dist >> ../buildlog 2>&1
mv visit\$ver2.linux-ia64.tar.gz ..
cd ..
rm -f resultlog
echo "        build of visit on thunder"      > resultlog 2>&1
echo "       ---------------------------"     >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
ls -l                                         >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "number of database plugins = "\`ls $dist/plugins/databases/libI* | wc -l\` >> resultlog 2>&1
echo "number of operator plugins = "\`ls $dist/plugins/operators/libI* | wc -l\` >> resultlog 2>&1
echo "number of plot plugins = "\`ls $dist/plugins/plots/libI* | wc -l\` >> resultlog 2>&1
echo ""                                       >> resultlog 2>&1
echo "The database plugins:"                  >> resultlog 2>&1
ls $dist/plugins/databases/libI* | sed "s/$dist\/plugins\/databases\/libI//" | sed "s/Database.so//" >> resultlog 2>&1
mail $emailName < resultlog
EOF

if [ $thunder = true ]
then
   if [ $test = no ]
   then
      scp thunder thunder2:thunder_buildit
      scp $dist.tar.gz thunder2:thunder_$dist.tar.gz
      ssh thunder2 "chmod 750 thunder_buildit;./thunder_buildit" &
   fi
fi

#
# Clean up.
#
if [ $test = no ]
then
   rm -f kickit sunspot hyper gps berg pengra thunder
fi
