#!/bin/bash

# Script to install MPICH2 on Linux
# by Yusong Wang, 2009


MPICH2_version=1.1

install_dir=`pwd`

check_input () {
  read
  while [ $REPLY != "yes" ] && [ $REPLY != "no" ]
  do 
     echo "Please type yes or no"
     read
  done
}

# Install MPICH2 (Internet connection required)

echo -n "Do you want to install MPICH2 at ${install_dir} (yes/no)? "
check_input
if [ $REPLY = "yes" ]
then
  wget http://www.mcs.anl.gov/research/projects/mpich2/downloads/tarballs/${MPICH2_version}/mpich2-${MPICH2_version}.tar.gz
  gzip -d mpich2-${MPICH2_version}.tar.gz
  tar -xf mpich2-${MPICH2_version}.tar
  pushd mpich2-${MPICH2_version}
  ./configure --prefix=${install_dir}/mpich2-install 2>&1 | tee c.txt
  make 2>&1 | tee log.txt
  popd
  mpi_dir=${install_dir}/mpich2-${MPICH2_version}/bin
  export PATH=$PATH:${mpi_dir}
  echo "MPICH2 binaries has been installed at ${mpi_dir}"
else
  echo "You chose not to install MPICH2. Please make sure MPI binaries are in your PATH"
  echo "Press \"Enter\" to continue."
  read
fi

