#!/bin/bash
#######################################################################
#
# silo-release-open - Build and install a tarball on the open network.
#
# Author: Thomas Treadway
# Date: Thu Jun 15 12:48:17 PDT 2006
#
# Usage:
#    silo-release-open version
#
# Modifications:
#    Thomas R. Treadway, Wed Oct  3 13:48:15 PDT 2007
#    Removed gps, added up
#    Added build of silex, and included szip
#
#    Thomas R. Treadway, Fri Nov  2 16:17:59 PDT 2007
#    Tunning for release 4.6
#
#    Thomas R. Treadway, Wed Nov 14 12:54:37 PST 2007
#    Corrected some of the pathc issues.
#
#    Thomas R. Treadway, Thu Dec 27 14:06:40 PST 2007
#    reformatted, added -final, -clean options.
#
#######################################################################
#
function usage() {
  printf "Usage: %s version [-lc-username <lc-username>] [-check-install | -no-install | -final | -clean] {all|hoth|sidious|sunspot|up|yana|ubgl|dawndev}" $0
  printf "\n"
  printf "Build options\n"
  printf "                  -- default, runs make install\n"
  printf -- "-check-install -- runs make check before make install\n"
  printf -- "-no-install    -- runs make only no make install step\n"
  printf -- "-final {host}  -- creates links to silo/current directory\n"
  printf "                  and other convenient symbolic links\n"
  printf -- "-clean {host}  -- removes the build directories\n"
  printf "\n"
  printf "Host select options\n"
  printf "all            -- tries to build on both BDiv, and LC host\n"
  printf "all-lc         -- tries to build on LC host only\n"
  printf "all-bdiv       -- tries to build on both BDiv host only\n"
  printf "{hostopt}      -- host, host list or host option list, such as:\n"
  printf "               hoth, hothgcc, hothicc, hothpgc, yana, yanagcc,\n"
  printf "               yanapgc, yanaicc, yanapsc\n"
  printf "               thunder, thundericc, pengra, pengraicc, pengragcc,\n"
  printf "               all, all-lc, all-bd, etc.\n"
  printf "{host}         -- host name or host name list, such as:\n"
  printf "               hoth, yana, thunder, pengra, quad, tread,\n"
  printf "               all, all-lc, all-bd\n"
  printf "\n"
  printf "Silo release installing script. Assumes a tarball exist in\n"
  printf "current directory, named something like silo-\$1.tar.gz.\n"
  printf "This script will attempt to:\n"
  printf "  1) copy tarball to B Div's /usr/gapps/silo/$VERSION and\n"
  printf "     LC's /usr/gapps/silo/$VERSION.\n"
  printf "  2) untar in /usr/gapps/silo/$VERSION/test.\n"
  printf "  3) start remote scripts on the target machines that\n"
  printf "     perform a configure, make check, followed by a make install\n"
  printf "     into directories /usr/gapps/silo/$VERSION/$ARCH.\n"
  printf "Log files are stored at ./HOSTNAME.log\n"
  printf "You may want to run this script from the LC network.\n"
}

function build() {
    ssh ${HOSTS} "$SSHSHELL" << EOF > ${ARCH}.log 2>&1 &
    $*
    unset QTDIR
    umask 002
    ls -l $TOPDIR/$VERSION/test
    rm -rf $TOPDIR/$VERSION/test/$ARCH
    mkdir $TOPDIR/$VERSION/test/$ARCH
    ls -l $TOPDIR/$VERSION/test
    cd $TOPDIR/$VERSION/test/$ARCH

    ../$TOPSRCDIR/configure --disable-hzip --disable-fpzip --enable-legacy-datatyped-pointers \
--prefix=$TOPDIR/$VERSION/$ARCH \
--disable-browser --disable-silex --without-hdf5 --without-szlib $CONFOPTS
    test $? != 0 && return
    $MAKE $MAKEOPTS
    test $? != 0 && return
    if [ "$DOINSTALL" = "yes" ] ; then
       $MAKE install
    fi
    chmod -R g+w $TOPDIR/$VERSION/$ARCH
    $MAKE clean

    ../$TOPSRCDIR/configure --disable-hzip --disable-fpzip --enable-legacy-datatyped-pointers \
--prefix=$TOPDIR/$VERSION/$ARCH --with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib \
$CONFOPTS
    test $? != 0 && return
    $MAKE $MAKEOPTS
    test $? != 0 && return
    if [ "$DOINSTALL" = "yes" ] ; then
       $MAKE install
    fi
    mv $TOPDIR/$VERSION/$ARCH/lib/libsiloh5.a $TOPDIR/$VERSION/$ARCH/lib/libsiloh5.a.saved
    mv $TOPDIR/$VERSION/$ARCH/include/silo.h $TOPDIR/$VERSION/$ARCH/include/silo.h.saved
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/test/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/test/$ARCH
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/$ARCH
    $MAKE clean

    ../$TOPSRCDIR/configure \
--prefix=$TOPDIR/$VERSION/$ARCH --with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib \
$CONFOPTS
    test $? != 0 && return
    $MAKE $MAKEOPTS
    if [ $? = 0 && "$DOCHECK" = "yes" ] ; then
       $MAKE $MAKEOPTS check TESTARGS="-k \!large"
    fi
    if [ "$DOINSTALL" = "yes" ] ; then
       $MAKE install
    fi
    mv $TOPDIR/$VERSION/$ARCH/bin $TOPDIR/$VERSION/$ARCH/bin.saved
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/test/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/test/$ARCH
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/$ARCH
    $MAKE clean

    ../$TOPSRCDIR/configure --enable-pythonmodule --enable-shared \
--prefix=$TOPDIR/$VERSION/$ARCH --with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib \
$CONFOPTS
    test $? != 0 && return
    $MAKE $MAKEOPTS
    if [ $? = 0 && "$DOCHECK" = "yes" ] ; then
       $MAKE $MAKEOPTS check TESTARGS="-k compression -k python"
    fi
    if [ "$DOINSTALL" = "yes" ] ; then
       $MAKE install
    fi
    rm -rf $TOPDIR/$VERSION/$ARCH/libso
    cp -R $TOPDIR/$VERSION/$ARCH/lib $TOPDIR/$VERSION/$ARCH/libso
    rm -f $TOPDIR/$VERSION/$ARCH/libso/{*.settings,*.la,*.a}
    rm -f $TOPDIR/$VERSION/$ARCH/libso/libsiloh5.a.saved
    mv $TOPDIR/$VERSION/$ARCH/lib/libsiloh5.a $TOPDIR/$VERSION/$ARCH/lib/libsiloxx.a
    mv $TOPDIR/$VERSION/$ARCH/lib/libsiloh5.a.saved $TOPDIR/$VERSION/$ARCH/lib/libsiloh5.a
    mv $TOPDIR/$VERSION/$ARCH/include/silo.h.saved $TOPDIR/$VERSION/$ARCH/include/silo.h
    rm -f $TOPDIR/$VERSION/$ARCH/lib/*.so
    rm -rf $TOPDIR/$VERSION/$ARCH/bin
    mv $TOPDIR/$VERSION/$ARCH/bin.saved $TOPDIR/$VERSION/$ARCH/bin
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/test/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/test/$ARCH
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/$ARCH
EOF
}
function build2() {
    ssh -v -v -v ${HOSTS} "$SSHSHELL" << FOOBAR > ${ARCH}.log 2>&1 &
    $*
    set -x
    unset QTDIR
    umask 002
    rm -rf $TOPDIR/$VERSION/test/$ARCH
    mkdir $TOPDIR/$VERSION/test/$ARCH
    cd $TOPDIR/$VERSION/test/$ARCH

    ../$TOPSRCDIR/configure --disable-hzip --disable-fpzip --enable-legacy-datatyped-pointers \
--prefix=$TOPDIR/$VERSION/$ARCH \
--disable-browser --disable-silex --without-hdf5 --without-szlib $CONFOPTS2
    test $? != 0 && return
    $MAKE $MAKEOPTS
    test $? != 0 && return
    if [ "$DOINSTALL" = "yes" ] ; then
       $MAKE install
    fi
    chmod -R g+w $TOPDIR/$VERSION/$ARCH
    $MAKE clean

    ../$TOPSRCDIR/configure --disable-hzip --disable-fpzip --enable-legacy-datatyped-pointers \
--prefix=$TOPDIR/$VERSION/$ARCH --with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib \
$CONFOPTS2
    test $? != 0 && return
    $MAKE $MAKEOPTS
    test $? != 0 && return
    if [ "$DOINSTALL" = "yes" ] ; then
       $MAKE install
    fi
    mv $TOPDIR/$VERSION/$ARCH/lib/libsiloh5.a $TOPDIR/$VERSION/$ARCH/lib/libsiloh5.a.saved
    mv $TOPDIR/$VERSION/$ARCH/include/silo.h $TOPDIR/$VERSION/$ARCH/include/silo.h.saved
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/test/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/test/$ARCH
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/$ARCH
    $MAKE clean

    ../$TOPSRCDIR/configure \
--prefix=$TOPDIR/$VERSION/$ARCH --with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib \
$CONFOPTS2
    test $? != 0 && return
    $MAKE $MAKEOPTS
    if [ $? = 0 && "$DOCHECK" = "yes" ] ; then
       $MAKE $MAKEOPTS check TESTARGS="-k \!large"
    fi
    if [ "$DOINSTALL" = "yes" ] ; then
       $MAKE install
    fi
    mv $TOPDIR/$VERSION/$ARCH/bin $TOPDIR/$VERSION/$ARCH/bin.saved
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/test/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/test/$ARCH
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/$ARCH
    $MAKE clean

    ../$TOPSRCDIR/configure --enable-pythonmodule --enable-shared \
--prefix=$TOPDIR/$VERSION/$ARCH --with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib \
$CONFOPTS2
    test $? != 0 && return
    $MAKE $MAKEOPTS
    if [ $? = 0 && "$DOCHECK" = "yes" ] ; then
       $MAKE $MAKEOPTS check TESTARGS="-k compression -k python"
    fi
    if [ "$DOINSTALL" = "yes" ] ; then
       $MAKE install
    fi
    rm -rf $TOPDIR/$VERSION/$ARCH/libso
    cp -R $TOPDIR/$VERSION/$ARCH/lib $TOPDIR/$VERSION/$ARCH/libso
    rm -f $TOPDIR/$VERSION/$ARCH/libso/{*.settings,*.la,*.a}
    rm -f $TOPDIR/$VERSION/$ARCH/libso/libsiloh5.a.saved
    mv $TOPDIR/$VERSION/$ARCH/lib/libsiloh5.a $TOPDIR/$VERSION/$ARCH/lib/libsiloxx.a
    mv $TOPDIR/$VERSION/$ARCH/lib/libsiloh5.a.saved $TOPDIR/$VERSION/$ARCH/lib/libsiloh5.a
    mv $TOPDIR/$VERSION/$ARCH/include/silo.h.saved $TOPDIR/$VERSION/$ARCH/include/silo.h
    rm -f $TOPDIR/$VERSION/$ARCH/lib/*.so
    rm -rf $TOPDIR/$VERSION/$ARCH/bin
    mv $TOPDIR/$VERSION/$ARCH/bin.saved $TOPDIR/$VERSION/$ARCH/bin
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/test/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/test/$ARCH
    chmod -R a+r,ug+w,a+X $TOPDIR/$VERSION/$ARCH
    chgrp -R visit $TOPDIR/$VERSION/$ARCH
FOOBAR
}

function sidious() {
    sidiousgcc
}

sidiousgcc() {
    HOSTS="sidious"
    ARCH="x86_64_Linux_el5xen"
    CONFOPTS="FC=g77 F77=g77 \
FFLAGS=-Wno-globals F77FLAGS=-Wno-globals FCFLAGS=-Wno-globals"
    export HOSTS ARCH CONFOPTS
    build \
    "PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/atria/bin:\
/usr/lib/jre/bin:/sbin:/usr/sbin:/opt/bin:/usr/local/apps/bin:\
/usr/security/bin" \
    "LD_LIBRARY_PATH=/usr/lib:/lib" \
    "export PATH LD_LIBRARY_PATH"
}

function hoth() {
    hothgcc
    hothpgc
    hothicc
}
function hothfinal() {
    ssh hoth "/bin/bash" << EOF >> i686_Linux_ELsmp.log 2>&1
    umask 002
    cd $TOPDIR/$VERSION/test/i686_Linux_ELsmp
    for FILE in $BININSTALLS
    do if [[ -e /misc/gapps/Linux/bin/\$FILE ]] ; then
          rm -f /misc/gapps/Linux/bin/\$FILE
       fi
    done
    unset QTDIR
    gmake bindir=/misc/gapps/Linux/bin install-exec
    for FILE in $BININSTALLS
    do chmod a+r,ug+w,a+X /misc/gapps/Linux/bin/\$FILE
       chgrp visit /misc/gapps/Linux/bin/\$FILE
    done
    for ARCHDIR in "i686_Linux_ELsmp" "i686_Linux_ELsmp_pgcc" \
        "i686_Linux_ELsmp_icc"
    do
       if [[ -e $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview ]] ; then
          rm -f $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview
       fi
       ln -s $TOPDIR/hdfview/linux/hdfview \
          $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview
       chgrp visit $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview
    done
    for ARCHDIR in "i686_Linux_ELsmp_pgcc" "i686_Linux_ELsmp_icc"
    do
       if [[ -e $TOPDIR/$VERSION/\$ARCHDIR/bin ]] ; then
          rm -rf $TOPDIR/$VERSION/\$ARCHDIR/bin
       fi
       ln -s $TOPDIR/$VERSION/i686_Linux_ELsmp/bin \
          $TOPDIR/$VERSION/\$ARCHDIR/bin
       chgrp visit $TOPDIR/$VERSION/\$ARCHDIR
    done
EOF
}
function hothclean() {
    ssh hoth "/bin/bash" << EOF >> linux_rhel3-gcc-3.2.3.log 2>&1
    for ARCHDIR in "i686_Linux_ELsmp" "i686_Linux_ELsmp_pgcc" \
        "i686_Linux_ELsmp_icc" "i686_Linux_ELsmp_pathcc"
    do if [[ -d $TOPDIR/$VERSION/test/\$ARCHDIR ]] ; then
          rm -rf $TOPDIR/$VERSION/test/\$ARCHDIR
       fi
    done
EOF
}

function hothgcc() {
    HOSTS="hoth"
    ARCH="i686_Linux_ELsmp"
    CONFOPTS="FC=g77 F77=g77 \
FFLAGS=-Wno-globals F77FLAGS=-Wno-globals FCFLAGS=-Wno-globals"
    export HOSTS ARCH CONFOPTS
    build
}
function hothpgc() {
    HOSTS="hoth"
    ARCH="i686_Linux_ELsmp_pgcc"
    CONFOPTS="CC=pgcc CXX=pgCC FC=\"pgf77 -g77libs\" F77=\"pgf77 -g77libs\" LDFLAGS=-lstdc++ \
--disable-silex"
    export HOSTS ARCH CONFOPTS
    build
}
function hothicc() {
    HOSTS="hoth"
    ARCH="i686_Linux_ELsmp_icc"
    CONFOPTS="CC=icc CXX=icc FC=ifort F77=ifort LDFLAGS=-lstdc++ --disable-silex"
    export HOSTS ARCH CONFOPTS
    build
}

function sunspot() {
  sunspotgcc
  sunspotcc
}
function sunspotfinal() {
    ssh sunspot "/bin/bash" << EOF >> sparc_SunOS_57.log 2>&1
    umask 002
    cd $TOPDIR/$VERSION/test/sparc_SunOS_57
    for FILE in $BININSTALLS
    do if [[ -e /misc/gapps/SunOS/bin/\$FILE ]] ; then
          rm -f /misc/gapps/SunOS/bin/\$FILE
       fi
    done
    PATH=/usr/bin:/bin:/usr/local/apps/bin:/usr/local/bin:/usr/ccs/bin:\
/opt/SUNWspro/bin:/usr/ucb:/etc:/usr/openwin/bin:/usr/dt/bin:/usr/java/bin
    LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
    export PATH LD_LIBRARY_PATH
    gmake bindir=/misc/gapps/SunOS/bin install-exec
    for FILE in $BININSTALLS
    do chmod a+r,ug+w,a+X /misc/gapps/SunOS/bin/\$FILE
       chgrp visit /misc/gapps/SunOS/bin/\$FILE
    done
    ln -s $TOPDIR/$VERSION/sparc_SunOS_57/bin/silex \
       $TOPDIR/$VERSION/sparc_SunOS_57_gcc/bin/silex
    chgrp visit $TOPDIR/$VERSION/sparc_SunOS_57_gcc/bin/silex
EOF
}
function sunspotclean() {
    ssh sunspot "/bin/bash" << EOF >> sunos_57.log 2>&1
    for ARCHDIR in "sparc_SunOS_57" "sparc_SunOS_57_cc"
    do rm -rf $TOPDIR/$VERSION/test/\$ARCHDIR
    done
EOF
}
function sunspotgcc() {
    HOSTS="sunspot"
    ARCH="sparc_SunOS_57_gcc"
    CONFOPTS="CC=gcc CXX=g++ FC=g77 F77=g77 \
FFLAGS=-Wno-globals F77FLAGS=-Wno-globals FCFLAGS=-Wno-globals"
    CONFOPTS2="CC=gcc CXX=g++ FC=g77 F77=g77 --disable-silex \
FFLAGS=-Wno-globals F77FLAGS=-Wno-globals FCFLAGS=-Wno-globals"
    export HOSTS ARCH CONFOPTS CONFOPTS2
    build2 \
    "PATH=/usr/bin:/bin:/usr/local/apps/bin:/usr/local/bin:/usr/ccs/bin:\
/opt/SUNWspro/bin:/usr/ucb:/etc:/usr/openwin/bin:/usr/dt/bin:/usr/java/bin" \
    "LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib" \
    "export PATH LD_LIBRARY_PATH"
}
function sunspotcc() {
    HOSTS="sunspot"
    ARCH="sparc_SunOS_57"
    CONFOPTS="CC=cc CXX=CC FC=f77 F77=f77 LDFLAGS=-L/usr/local/lib"
    CONFOPTS2="CC=cc CXX=CC FC=f77 F77=f77 \
LDFLAGS=-L/usr/local/lib --disable-silex --without-readline \
--with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/sparc-sun-solaris-cc-5.2 \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/sparc-sun-solaris-cc-5.2/include,\
/usr/gapps/silo/hdf5/$HDF5RELEASE/sparc-sun-solaris-cc-5.2/lib"
    export HOSTS ARCH CONFOPTS CONFOPTS2
    build2 \
    "PATH=/usr/bin:/bin:/usr/local/apps/bin:/usr/local/bin:/usr/ccs/bin:\
/opt/SUNWspro/bin:/usr/ucb:/etc:/usr/openwin/bin:/usr/dt/bin:/usr/java/bin" \
    "LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib" \
    "export PATH LD_LIBRARY_PATH"
}

function up() {
# not using gcc
# use gmake for parallel seems to hang
# 32-bit and 64-bit compiles
  up64
  up32
  upgcc
}
function upfinal() {
    ssh ${lcun}@up "/bin/bash" << EOF >> aix_5_64_fed.log 2>&1
    umask 002
    cd $TOPDIR/$VERSION/test/aix_5_64_fed
    for ARCHDIR in "aix_5_64" "aix_5_64_fed" "aix_5_ll"
    do
       for FILE in $BININSTALLS
       do if [[ -e /usr/gapps/bin/\$ARCHDIR/\$FILE ]] ; then
             rm -f /usr/gapps/bin/\$ARCHDIR/\$FILE
          fi
       done
       PATH=/usr/local/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/gnu/bin:\
/usr/local/scripts:/usr/apps/bin:/usr/gapps/bin
       OBJECT_MODE=64
       export PATH OBJECT_MODE
       gmake bindir=/usr/gapps/bin/$ARCHDIR install-exec
       for FILE in $BININSTALLS
       do chmod a+r,ug+w,a+X /usr/gapps/bin/\$ARCHDIR/\$FILE
          chgrp visit /usr/gapps/bin/\$ARCHDIR/\$FILE
       done
    done
    for ARCHDIR in "aix_5_ll" "aix_5_64_fed" "aix_5_ll_gcc" "aix_5_64_fed_gcc"
    do
       if [[ -e $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview ]] ; then
          rm -f $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview
       fi
       ln -s $TOPDIR/hdfview/AIX/hdfview \
          $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview
       chgrp visit $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview
    done
    for ARCHDIR in "aix_5_ll" "aix_5_ll_gcc" "aix_5_64_fed_gcc"
    do
       if [[ -e $TOPDIR/$VERSION/\$ARCHDIR/bin ]] ; then
          rm -rf $TOPDIR/$VERSION/\$ARCHDIR/bin
       fi
       ln -s $TOPDIR/$VERSION/aix_5_64_fed/bin \
          $TOPDIR/$VERSION/\$ARCHDIR/bin
       chgrp visit $TOPDIR/$VERSION/\$ARCHDIR/bin
    done
EOF
}
function upclean() {
    ssh ${lcun}@up "/bin/bash" << EOF >> aix_5_64_fed.log 2>&1
    for ARCHDIR in "aix_5_ll" "aix_5_64_fed" "aix_5_ll_gcc" "aix_5_64_fed_gcc"
    do if [[ -d $TOPDIR/$VERSION/test/\$ARCHDIR ]] ; then
          rm -rf $TOPDIR/$VERSION/test/\$ARCHDIR
       fi
    done
EOF
}
function up32() {
    HOSTS="${lcun}@up"
    ARCH="aix_5_ll"
    CONFOPTS="FC=xlf F77=xlf --disable-silex"
    CONFOPTS2="FC=xlf F77=xlf --disable-silex \
--with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,\
/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib"
    MAKEOPTS=""
    export HOSTS ARCH CONFOPTS CONFOPTS2 MAKEOPTS
    build2 \
    "PATH=/usr/local/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/gnu/bin:\
/usr/local/scripts:/usr/apps/bin:/usr/gapps/bin" \
    "OBJECT_MODE=32" \
    "export PATH OBJECT_MODE"
}
function up64() {
    HOSTS="${lcun}@up"
    ARCH="aix_5_64_fed"
    CONFOPTS="FC=xlf F77=xlf "
    CONFOPTS2="FC=xlf F77=xlf --enable-silex"
    MAKEOPTS=""
    export HOSTS ARCH CONFOPTS CONFOPTS2 MAKEOPTS
    build2 \
    "PATH=/usr/local/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/gnu/bin:\
/usr/local/scripts:/usr/apps/bin:/usr/gapps/bin" \
    "OBJECT_MODE=64" \
    "export PATH OBJECT_MODE"
}

function upgcc() {
# use gmake for parallel seems to hang
# 32-bit and 64-bit compiles
  upgcc32
  upgcc64
}
function upgcc32() {
    HOSTS="${lcun}@up"
    ARCH="aix_5_ll_gcc"
    CONFOPTS="CC=gcc CXX=g++ FC=g77 F77=g77 \
CFLAGS=\"-maix32 -mminimal-toc\" CXXFLAGS=\"-maix32 -mminimal-toc\" \
LDFLAGS=-maix32 --disable-silex"
    CONFOPTS2="CC=gcc CXX=g++ FC=g77 F77=g77 \
CFLAGS=\"-maix32 -mminimal-toc\" CXXFLAGS=\"-maix32 -mminimal-toc\" \
LDFLAGS=-maix32 --disable-silex \
--with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,\
/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib"
    export HOSTS ARCH CONFOPTS CONFOPTS2
    build2 \
    "PATH=/usr/local/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/gnu/bin:\
/usr/local/scripts:/usr/apps/bin:/usr/gapps/bin" \
    "OBJECT_MODE=32" \
    "export PATH OBJECT_MODE"
}
function upgcc64() {
    HOSTS="${lcun}@up"
    ARCH="aix_5_64_fed_gcc"
    CONFOPTS="CC=gcc CXX=g++ FC=g77 F77=g77 \
CFLAGS=\"-maix64 -mminimal-toc\" CXXFLAGS=\"-maix64 -mminimal-toc\" \
LDFLAGS=-maix64"
    CONFOPTS2="CC=gcc CXX=g++ FC=g77 F77=g77 \
CFLAGS=\"-maix64 -mminimal-toc\" CXXFLAGS=\"-maix64 -mminimal-toc\" \
LDFLAGS=-maix64 \
--with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,\
/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib"
    export HOSTS ARCH CONFOPTS CONFOPTS2
    build2 \
    "PATH=/usr/local/bin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/gnu/bin:\
/usr/local/scripts:/usr/apps/bin:/usr/gapps/bin" \
    "OBJECT_MODE=64" \
    "export PATH OBJECT_MODE"
}

function yana() {
  yanagcc
  yanaicc
  yanapgc
  yanapsc
}
function yanafinal() {
    ssh ${lcun}@yana "/bin/bash" << EOF >> chaos_4_x86_64.log 2>&1
    set -x
    umask 002
#   cd $TOPDIR/$VERSION/test/chaos_4_x86_64
#   gmake bindir=/usr/gapps/bin/chaos_4_x86_64 install-exec
#   gmake bindir=/usr/gapps/bin/chaos_4_x86_64_elan4 install-exec
#   gmake bindir=/usr/gapps/bin/chaos_4_x86_64_ib install-exec
    for ARCHDIR in "chaos_4_x86_64" "chaos_4_x86_64_ib"
    do
       for FILE in $BININSTALLS
       do
          if [[ -e /usr/gapps/bin/\$ARCHDIR/\$FILE ]] ; then
             rm -f /usr/gapps/bin/\$ARCHDIR/\$FILE
          fi
          ln -s $TOPDIR/$VERSION/chaos_4_x86_64/bin/\$FILE \
             /usr/gapps/bin/\$ARCHDIR/\$FILE
          chmod a+r,ug+w,a+X /usr/gapps/bin/\$ARCHDIR/\$FILE
          chgrp visit /usr/gapps/bin/\$ARCHDIR/\$FILE
       done
       if [[ -e /usr/gapps/bin/\$ARCHDIR/hdfview ]] ; then
          rm -f /usr/gapps/bin/\$ARCHDIR/hdfview
       fi
       ln -s $TOPDIR/hdfview/linux64amd/hdfview \
          /usr/gapps/bin/\$ARCHDIR/hdfview
       chgrp visit /usr/gapps/bin/\$ARCHDIR/hdfview
    done
    for ARCHDIR in "chaos_4_x86_64" "chaos_4_x86_64_icc" \
        "chaos_4_x86_64_pathcc" "chaos_4_x86_64_pgcc"
    do
       if [[ -e $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview ]] ; then
          rm -f $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview
       fi
       ln -s $TOPDIR/hdfview/linux64amd/hdfview \
          $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview
       chgrp visit $TOPDIR/$VERSION/\$ARCHDIR/bin/hdfview
    done
    for ARCHDIR in "chaos_4_x86_64" "chaos_4_x86_64_pathcc" \
       "chaos_4_x86_64_pgcc"
    do
       if [[ -e $TOPDIR/$VERSION/\$ARCHDIR/bin ]] ; then
          rm -rf $TOPDIR/$VERSION/\$ARCHDIR/bin
       fi
       ln -s $TOPDIR/$VERSION/chaos_4_x86_64_icc/bin \
          $TOPDIR/$VERSION/\$ARCHDIR/bin
       chgrp visit $TOPDIR/$VERSION/\$ARCHDIR/bin
    done
EOF
}
function yanaclean() {
    ssh ${lcun}@yana "/bin/bash" << EOF >> chaos_4_x86_64.log 2>&1
    for ARCHDIR in "chaos_4_x86_64" "chaos_4_x86_64_icc" \
        "chaos_4_x86_64_pathcc" "chaos_4_x86_64_pgcc"
    do if [[ -d $TOPDIR/$VERSION/test/\$ARCHDIR ]] ; then
          rm -rf $TOPDIR/$VERSION/test/\$ARCHDIR
       fi
    done
EOF
}
function yanagcc() {
    HOSTS="${lcun}@yana"
    ARCH="chaos_4_x86_64"
    CONFOPTS="CC=gcc CXX=g++ FC=g77 F77=g77 CFLAGS=-fPIC CXXFLAGS=-fPIC \
FFLAGS=-Wno-globals F77FLAGS=-Wno-globals FCFLAGS=-Wno-globals --enable-silex"
    export HOSTS ARCH CONFOPTS
    build \
    "PATH=/usr/local/intel/compiler91/bin:/usr/local/bin:/bin:/usr/bin:\
/usr/bin/X11:/usr/lib/mpi/bin:/usr/apps/bin:/usr/gapps/bin" \
    "export PATH"
}

function yanaicc() {
    HOSTS="${lcun}@yana"
    ARCH="chaos_4_x86_64_icc"
    CONFOPTS="CC=icc CXX=icc FC=ifort F77=ifort LDFLAGS=-lstdc++ \
CFLAGS=-fPIC CXXFLAGS=-fPIC"
    CONFOPTS2="CC=icc CXX=icc FC=ifort F77=ifort LDFLAGS=-lstdc++ \
CFLAGS=-fPIC CXXFLAGS=-fPIC \
--with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,\
/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib"
    export HOSTS ARCH CONFOPTS CONFOPTS2
    build2 \
    "LD_LIBRARY_PATH=/usr/local/tools/icc/lib" \
    "export LD_LIBRARY_PATH"
}
function yanapsc() {
    HOSTS="${lcun}@yana"
    ARCH="chaos_4_x86_64_pathcc"
    CONFOPTS="CC=pathcc CXX=pathCC FC=pathf90 F77=pathf90 \
CFLAGS=-fPIC CXXFLAGS=-fPIC"
    CONFOPTS2="CC=pathcc CXX=pathCC FC=pathf90 F77=pathf90 \
CFLAGS=-fPIC CXXFLAGS=-fPIC --disable-silex \
--with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,\
/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib"
    export HOSTS ARCH CONFOPTS CONFOPTS2
    build2 \
    "PATH=/usr/global/tools/RSI/bin:\
/usr/local/tools/pathscale/pathscale-2.4/bin2:/usr/local/bin:/bin:/usr/bin:\
/usr/bin/X11:/usr/lib/mpi/bin:/usr/apps/bin:/usr/gapps/bin:/usr/kerberos/bin" \
    "LM_LICENSE_FILE=/usr/local/etc/license.client" \
    "PATHSCALE_SUBSCRIPTION_DAEMON=license1ocf.llnl.gov" \
    "export PATH LM_LICENSE_FILE PATHSCALE_SUBSCRIPTION_DAEMON"
}
function yanapgc() {
    HOSTS="${lcun}@yana"
    ARCH="chaos_4_x86_64_pgcc"
    CONFOPTS="CC=pgcc CXX=pgCC FC=\"pgf77 -g77libs\" F77=\"pgf77 -g77libs\" \
CFLAGS=-fPIC CXXFLAGS=-fPIC LDFLAGS=/usr/local/tools/pgi-7.0.6/linux86-64/7.0-6/lib/pgfmain.o"
    CONFOPTS2="CC=pgcc CXX=pgCC FC=\"pgf77 -g77libs\" F77=\"pgf77 -g77libs\" \
CFLAGS=-fPIC CXXFLAGS=-fPIC  LDFLAGS=/usr/local/tools/pgi-7.0.6/linux86-64/7.0-6/lib/pgfmain.o --disable-silex \
--with-szlib=/usr/gapps/silo/szip/$SZIPRELEASE/$ARCH \
--with-hdf5=/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/include,\
/usr/gapps/silo/hdf5/$HDF5RELEASE/$ARCH/lib"
    export HOSTS ARCH CONFOPTS CONFOPTS2
    build2
}

function ubgl() {
    ubglblrts_xlc
    ubglxlc
}

function ubglblrts_xlc() {
    HOSTS="${lcun}@ubgl"
    ARCH="sles_9_ppc64"
    CONFOPTS2="CC=blrts_xlc FC=blrts_xlf CXX=blrts_xlC \
    ac_cv_type_off64_t=yes ac_cv_sizeof_off64_t=8 \
    ac_cv_type_long=yes ac_cv_sizeof_long=4 \
    ac_cv_type_long_long=yes ac_cv_sizeof_long_long=8 \
    ac_cv_type_double=yes ac_cv_sizeof_double=8 \
    CPPFLAGS=-I/usr/gapps/silo/zlib/1.2.3/sles_9_ppc64-blrts_xlc/include \
    LDFLAGS=\"-L/usr/gapps/silo/zlib/1.2.3/sles_9_ppc64-blrts_xlc/lib -lz\" \
    CFLAGS=\"-O -qlanglvl=extended -qmaxmem=64000\" \
    CXXFLAGS=\"-O -qlanglvl=extended -qmaxmem=64000\" \
    --disable-silex"
    export HOSTS ARCH CONFOPTS2
    build2
}

function ubglxlc() {
    HOSTS="${lcun}@ubgl"
    ARCH="sles_9_ppc64_xlc"
    CONFOPTS2="CC=/opt/ibmcmp/vacpp/bg/8.0/bin/xlc FC=xlf \
    CXX=/opt/ibmcmp/vacpp/bg/8.0/bin/xlC \
    CFLAGS=\"-O -qlanglvl=extended -qmaxmem=64000\" \
    CXXFLAGS=\"-O -qlanglvl=extended -qmaxmem=64000\" \
    --disable-silex"
    export HOSTS ARCH CONFOPTS2
    build2
}


function dawndev() {
    dawndevbgxlc_r
    dawndevxlc
}

function dawndevbgxlc_r() {
    HOSTS="${lcun}@dawndev"
    ARCH="sles_10_ppc64"
    CONFOPTS2="CC=bgxlc_r FC=bgxlf_r \
    CXX=bgxlC_r \
    ac_cv_type_off64_t=yes ac_cv_sizeof_off64_t=8 \
    ac_cv_type_long=yes ac_cv_sizeof_long=4 \
    ac_cv_type_long_long=yes ac_cv_sizeof_long_long=8 \
    ac_cv_type_double=yes ac_cv_sizeof_double=8 \
    CPPFLAGS=-I/usr/gapps/silo/zlib/1.2.3/sles_10_ppc64-bgxlc_r/include \
    LDFLAGS=\"-L/usr/gapps/silo/zlib/1.2.3/sles_10_ppc64-bgxlc_r/lib -lz\" \
    CFLAGS=\"-O -qlanglvl=extended -qmaxmem=64000\" \
    CXXFLAGS=\"-O -qlanglvl=extended -qmaxmem=64000\" \
    --disable-silex"
    export HOSTS ARCH CONFOPTS2
    build2
}


function dawndevxlc() {
    HOSTS="${lcun}@dawndev"
    ARCH="sles_10_ppc64_xlc"
    CONFOPTS2="CC=xlc FC=xlf \
    CXX=xlC \
    CPPFLAGS=-I/usr/gapps/silo/zlib/1.2.3/sles_10_ppc64-xlc/include \
    LDFLAGS=\"-L/usr/gapps/silo/zlib/1.2.3/sles_10_ppc64-xlc/lib -lz\" \
    CFLAGS=\"-O -qlanglvl=extended -qmaxmem=64000\" \
    CXXFLAGS=\"-O -qlanglvl=extended -qmaxmem=64000\" \
    --disable-silex"
    export HOSTS ARCH CONFOPTS CONFOPTS2
    build2
}

TOPDIR="/usr/gapps/silo"
SSHSHELL="/bin/bash"
SZIPRELEASE=2.1
HDF5RELEASE=1.8.4
QTRELEASE=3.3.8
lcun=$USER
BININSTALLS="browser silex silock silodiff silofile"
declare -i i
declare -af list
MAKE="gmake"
#MAKEOPTS="-s LIBTOOLFLAGS=--silent"   # low noise
MAKEOPTS="-j 4"
DOINSTALL="yes"
DOCHECK="no"
DOFINAL="no"
DOCLEAN="no"
DOBDIV="no"
DOLC="no"

if (( $# < 1 )) ; then
  usage
  exit 2
fi
umask 002
VERSION=$1
shift
TARFILE="silo-$VERSION.tar.gz"
TOPSRCDIR="silo-$VERSION"

if (( $# < 1 )) ; then
    list=("hoth" "sidious" "sunspot" "up" "yana" "hera" "ubgl" "dawndev")
    DOBDIV="yes";DOLC="yes"
else
 i=0
 while [[ "$*" != "" ]]
 do
  case $1 in
    all-lc*|-all-lc*)
      list[i]="up" ; i=i+1
      list[i]="yana" ; i=i+1
      list[i]="hera" ; i=i+1
      list[i]="ubgl" ; i=i+1
      list[i]="dawndev" ; i=i+1
      DOLC="yes"
      shift;;
    all-bd*|-all-bd*)
      list[i]="hoth" ; i=i+1
      list[i]="sidious" ; i=i+1
      list[i]="sunspot" ; i=i+1
      DOBDIV="yes"
      shift;;
    all|-a*)
      list[i]="hoth" ; i=i+1
      list[i]="sidious" ; i=i+1
      list[i]="sunspot" ; i=i+1
      list[i]="up" ; i=i+1
      list[i]="yana" ; i=i+1
      list[i]="hera" ; i=i+1
      list[i]="ubgl" ; i=i+1
      list[i]="dawndev" ; i=i+1
      DOBDIV="yes";DOLC="yes"
      shift;;
    sidiousgcc|-sidiousgcc)
      list[i]="sidiousgcc" ; i=i+1
      DOBDIV="yes"
      shift;;
    hothgcc|-hothgcc)
      list[i]="hothgcc" ; i=i+1
      DOBDIV="yes"
      shift;;
    hothpgc|-hothpgc)
      list[i]="hothpgc" ; i=i+1
      DOBDIV="yes"
      shift;;
    hothicc|-hothicc)
      list[i]="hothicc" ; i=i+1
      DOBDIV="yes"
      shift;;
    sidious|-sid*)
      list[i]="sidious" ; i=i+1
      DOBDIV="yes"
      shift;;
    hoth|-ho*)
      list[i]="hoth" ; i=i+1
      DOBDIV="yes"
      shift;;
    sun*gcc|-sun*gcc)
      list[i]="sunspotgcc" ; i=i+1
      DOBDIV="yes"
      shift;;
    sun*cc|-sun*cc)
      list[i]="sunspotcc" ; i=i+1
      DOBDIV="yes"
      shift;;
    sun*|-sun*)
      list[i]="sunspot" ; i=i+1
      DOBDIV="yes"
      shift;;
    upgcc32|-up*gcc32)
      list[i]="upgcc32" ; i=i+1
      DOLC="yes"
      shift;;
    up32|-up*32)
      list[i]="up32" ; i=i+1
      DOLC="yes"
      shift;;
    upgcc64|-up*gcc64)
      list[i]="upgcc64" ; i=i+1
      DOLC="yes"
      shift;;
    up64|-up*64)
      list[i]="up64" ; i=i+1
      DOLC="yes"
      shift;;
    upgcc|-upgcc)
      list[i]="upgcc" ; i=i+1
      DOLC="yes"
      shift;;
    up|-up*)
      list[i]="up" ; i=i+1
      DOLC="yes"
      shift;;
    yana*pgc|-ya*pgc)
      list[i]="yanapgc" ; i=i+1
      DOLC="yes"
      shift;;
    yana*psc|-ya*psc)
      list[i]="yanapsc" ; i=i+1
      DOLC="yes"
      shift;;
    yana*icc|-ya*icc)
      list[i]="yanaicc" ; i=i+1
      DOLC="yes"
      shift;;
    yana*gcc|-ya*gcc)
      list[i]="yanagcc" ; i=i+1
      DOLC="yes"
      shift;;
    yana*|-ya*)
      list[i]="yana" ; i=i+1
      DOLC="yes"
      shift;;
    hera*pgc)
      list[i]="herapgc" ; i=i+1
      DOLC="yes"
      shift;;
    hera*psc)
      list[i]="herapsc" ; i=i+1
      DOLC="yes"
      shift;;
    hera*icc)
      list[i]="heraicc" ; i=i+1
      DOLC="yes"
      shift;;
    hera*gcc)
      list[i]="heragcc" ; i=i+1
      DOLC="yes"
      shift;;
    hera*)
      list[i]="hera" ; i=i+1
      DOLC="yes"
      shift;;
    ubgl|-ubgl)
      list[i]="ubgl" ; i=i+1
      DOLC="yes"
      shift;;
    ubglblrts_xlc|-ubglblrts_xlc)
      list[i]="ubglblrts_xlc" ; i=i+1
      DOLC="yes"
      shift;;
    ubglxlc|-ubglxlc)
      list[i]="ubglxlc" ; i=i+1
      DOLC="yes"
      shift;;
    dawndevbgxlc_r|-dawndevbgxlc_r)
      list[i]="dawndevbgxlc_r" ; i=i+1
      DOLC="yes"
      shift;;
    dawndevxlc|-dawndevxlc)
      list[i]="dawndevxlc" ; i=i+1
      DOLC="yes"
      shift;;
    dawndev|-dawndev)
      list[i]="dawndev" ; i=i+1
      DOLC="yes"
      shift;;
    lc-use*|-lc-use*)
      lcun=$2
      shift 2;;
    check*|-check*)
      DOCHECK="yes"
      shift;;
    no*|-no*)
      DOINSTALL="no"
      shift;;
    fin*|-fin*)
      DOFINAL="yes"
      shift;;
    cle*|-cle*)
      DOCLEAN="yes"
      shift;;
    debug*|-debug*)
      set -vx
      shift;;
    trace*|-trace*)
      set -vx
      shift;;
    *)
      shift;;
  esac
 done
fi
if [[ "$DOFINAL" = "yes" ]] ; then
   if [[ "$DOBDIV" = "yes" ]] ; then
      ssh hoth "/bin/bash" << EOF
      umask 002
      if [ -d $TOPDIR/current ] ; then
         rm $TOPDIR/current
      fi
      ln -s $TOPDIR/$VERSION $TOPDIR/current
      chgrp visit $TOPDIR/current
      if [ -f $TOPDIR/$VERSION/test/$TOPSRCDIR/docs/Silo.book.pdf ] ; then
         cp $TOPDIR/$VERSION/test/$TOPSRCDIR/docs/Silo.book.pdf \
            $TOPDIR/$VERSION
         chgrp visit $TOPDIR/$VERSION/Silo.book.pdf
      fi
EOF
   fi
   if [ "$DOLC" = "yes" ] ; then
      ssh ${lcun}@yana "/bin/bash" << EOF
      umask 002
      if [ -d $TOPDIR/current ] ; then
         rm $TOPDIR/current
      fi
      ln -s $TOPDIR/$VERSION $TOPDIR/current
      chgrp visit $TOPDIR/current
      if [ -f $TOPDIR/$VERSION/test/$TOPSRCDIR/docs/Silo.book.pdf ] ; then
         cp $TOPDIR/$VERSION/test/$TOPSRCDIR/docs/Silo.book.pdf \
            $TOPDIR/$VERSION
         chgrp visit $TOPDIR/$VERSION/Silo.book.pdf
      fi
EOF
   fi
   i=0
   while (( i < ${#list[*]} ))
   do
      ${list[i]}final
      i=i+1
   done
elif [[ "$DOCLEAN" = "yes" ]] ; then
   i=0
   while (( i < ${#list[*]} ))
   do
      ${list[i]}clean
      i=i+1
   done
   if [[ "$DOBDIV" = "yes" ]] ; then
      ssh hoth "/bin/bash" << EOF
      if [ -d $TOPDIR/$VERSION/test ] ; then
         rm rf $TOPDIR/$VERSION/test
      fi
EOF
   fi 
   if [ "$DOLC" = "yes" ] ; then
      ssh ${lcun}@yana "/bin/bash" << EOF
      if [ -d $TOPDIR/$VERSION/test ] ; then
         rm rf $TOPDIR/$VERSION/test
      fi
EOF
   fi
else
   if [[ "$DOBDIV" = "yes" ]] ; then
      ssh hoth "/bin/bash" << EOF
      umask 002
      if [ ! -d $TOPDIR/$VERSION ] ; then
         mkdir $TOPDIR/$VERSION
      fi
      chgrp visit $TOPDIR/$VERSION
      chmod a+rX,u+w,o-w,g+s $TOPDIR/$VERSION
      if [ ! -d $TOPDIR/$VERSION/test ] ; then
         mkdir $TOPDIR/$VERSION/test
         chgrp visit $TOPDIR/$VERSION/test
         chmod a+rX,ug+w $TOPDIR/$VERSION/test
      fi
      sleep 5
EOF
      if [[ -e $TARFILE ]] ; then
         scp $TARFILE hoth:$TOPDIR/$VERSION
         ssh hoth "/bin/bash" << EOF
         umask 002
         cd $TOPDIR/$VERSION/test
         chmod a+r,ug+w ../$TARFILE
         chgrp visit ../$TARFILE
         tar zxf ../$TARFILE
         chgrp -R visit $TOPSRCDIR
         chmod -R a+rX,ug+w $TOPSRCDIR
EOF
      fi
   fi
   if [ "$DOLC" = "yes" ] ; then
      ssh ${lcun}@yana "/bin/bash" << EOF
      umask 002
      if [ ! -d $TOPDIR/$VERSION ] ; then
         mkdir $TOPDIR/$VERSION
      fi
      chgrp visit $TOPDIR/$VERSION
      chmod a+rX,u+w,o-w,g+s $TOPDIR/$VERSION
      if [ ! -d $TOPDIR/$VERSION/test ] ; then
         mkdir $TOPDIR/$VERSION/test
         chgrp visit $TOPDIR/$VERSION/test
         chmod a+rX,ug+w $TOPDIR/$VERSION/test
      fi
EOF
      if [ -e $TARFILE ] ; then
         scp $TARFILE ${lcun}@yana:$TOPDIR/$VERSION
         ssh ${lcun}@yana "/bin/bash" << EOF
         umask 002
         cd $TOPDIR/$VERSION/test
         chmod a+r,ug+w ../$TARFILE
         chgrp visit ../$TARFILE
         tar zxf ../$TARFILE
         chgrp -R visit $TOPSRCDIR
         chmod -R a+rX,ug+w $TOPSRCDIR
EOF
      fi
   fi
   i=0
   while (( i < ${#list[*]} ))
   do
      ${list[i]}
      i=i+1
   done
fi
