#!/bin/bash

apt-get install build-essential gfortran libxml2 libxml2-dev libatlas-headers libatlas-base-dev openmpi-bin openmpi-dev libibverbs-dev openssh-server python-qt4 pyqt4-dev-tools swig python-dev libhdf5-serial-dev libmedc-dev libparmetis-dev recode


wget -a download.log http://research.edf.com/fichiers/fckeditor/Commun/Innovation/logiciels/syrthes/syrthes3.4.3.zip
unzip syrthes3.4.3.zip

wget -a download.log http://research.edf.com/fichiers/fckeditor/Commun/Innovation/logiciels/code_saturne/Releases/bft-115.zip
unzip bft*.zip

wget -a download.log http://research.edf.com/fichiers/fckeditor/Commun/Innovation/logiciels/code_saturne/Releases/fvm-0153.zip
unzip fvm*.zip

wget -a download.log http://research.edf.com/fichiers/fckeditor/Commun/Innovation/logiciels/code_saturne/Releases/ecs-202.zip
unzip ecs*.zip

wget -a download.log http://research.edf.com/fichiers/fckeditor/Commun/Innovation/logiciels/code_saturne/Releases/mei-103.zip
unzip mei*.zip

wget -a download.log http://research.edf.com/fichiers/fckeditor/Commun/Innovation/logiciels/code_saturne/Releases/ncs-202.zip
unzip ncs*.zip


# Syrthes build and install
cp -r syrthes* /opt/
cd /opt/syrthes*/bin/

recode ibmpc..lat1 Ma* sy*

mv syrthes.profile syrthes.profile.org
sed "s+/home/syrthes+/opt+" syrthes.profile.org >syrthes.profile
rm syrthes.profile.org

mv Makefile.in Makefile.in.org
sed "s+/usr/bin/g77+/usr/bin/gfortran+" Makefile.in.org >Makefile.in
rm Makefile.in.org

source syrthes.profile

make install
ln -s /opt/syrthes*/bin/syrthes_create_case /usr/local/bin/
ln -s /opt/syrthes*/bin/Linux_x86_64/* /usr/local/bin/

# BFT build and install
cd bft*
./configure
make
make install
cd ..

# FVM build and install
cd fvm*
./configure --with-mpi=/usr/lib/openmpi
make
make install
cd ..

# ECS build and install
cd ecs*
./configure
make
make install
cd ..

# MEI build and install
cd mei*
./configure --with-bft=/usr/local
make
make install
cd ..

# NCS build and install
cd ncs*
./configure --with-mpi=/usr/lib/openmpi --with-prepro=/usr/local --with-mei=/usr/local --with-syrthes=/opt/syrthes3.4.3
make
make install
cd ..