#!/bin/bash
dir=`which fastmigrate-n | sed 's/fastmigrate-n//'`;
if [ -d "/usr/local/openmpi-1.5.3/bin" ]; then
   echo "openmpi 1.5.3 is already installed"
   if [ ! "$FASTMIGRATE" == "installed" ]; then
       cat >> ~/.bash_profile << end-of-insert
#### fastmigrate-n addition begin ####
export FASTMIGRATE="installed"
export PATH=.:/usr/local/openmpi-1.5.3/bin:$PATH
if [ -d "$LD_LIBRARY_PATH" ]; then
    export LD_LIBRARY_PATH=/usr/local/openmpi-1.5.3/lib
else
    export LD_LIBRARY_PATH=/usr/local/openmpi-1.5.3/lib:$LD_LIBRARY_PATH
fi
#### fastmigrate-n addition end   ####                                                                                                                 
end-of-insert
   fi
   exit;
fi
echo "You are about to install a binary version of openmpi 1.5.3 onto your computer"
echo "This will need administrator rights and you will need to give the admin password"
echo ""
echo "On systems prior to 10.7 (Lion), you may have an older openmpi version installed"
echo "fastmigrate-n needs a newer version that is located at /usr/local/openmpi-1.5.3"
echo ""
echo "If you proceed the installer will unpack the openmpi-1.5.3.tar.gz into the"
echo "directory openmpi-1.5.3 and then it will be moved into /usr/local"
echo "the migrateshell.app and the fastmigrate-n will search for the openmpi library"
echo "at /usr/local/openmpi-1.5.3 and will not function correctly if openmpi is installed"
echo "in a different location"
# go to your home directory
cd
# unpack the openmpi package
#cp $dir/openmpi-1.5.3.tar.gz openmpi_migrate-1.5.3.tar.gz
tar xfz $dir/openmpi-1.5.3.bin.tar.gz
if [ ! -d "/usr/local" ]; then
   sudo mkdir -p /usr/local
fi
sudo mv openmpi-1.5.3 /usr/local/
#rm openmpi_migrate-1.5.3.tar.gz
cat >> ~/.bash_profile << end-of-insert
#### fastmigrate-n addition begin ####
export FASTMIGRATE="installed"
export PATH=.:/usr/local/openmpi-1.5.3/bin:$PATH
if [ -d "$LD_LIBRARY_PATH" ]; then
    export LD_LIBRARY_PATH=/usr/local/openmpi-1.5.3/lib
else
    export LD_LIBRARY_PATH=/usr/local/openmpi-1.5.3/lib:$LD_LIBRARY_PATH
fi
#### fastmigrate-n addition end   ####                                                                                                                 
end-of-insert
echo "installation finished, try to run fastmigrate-n"
exit
