Bootstrap: docker
From: ubuntu:16.04

%files
    #OpenFOAM-2.4.0.tgz /opt

%environment
    export TERM=linux
    export DEBIAN_FRONTEND=noninteractive
    export OMPI_DIR=/opt/ompi
    export PATH="$OMPI_DIR/bin:$PATH"
    export LD_LIBRARY_PATH="$OMPI_DIR/lib:$LD_LIBRARY_PATH"
    export MANPATH="$OMPI_DIR/share/man:$MANPATH"
    export FOAM_INST_DIR=/opt
    export WM_MPLIB=OPENMPI
    . /opt/OpenFOAM-2.4.0/etc/bashrc

%post -c /bin/bash
    export OMPI_VERSION=3.1.6
    export WM_NCOMPPROCS=32

    rm /etc/localtime
    echo America/Buenos_Aires > /etc/localtime
    echo "Installing required packages..."
    apt-get update && apt-get install -y && apt-get install -y build-essential cmake flex bison zlib1g-dev qt4-dev-tools libqt4-dev libqtwebkit-dev gnuplot libreadline-dev libncurses-dev libxt-dev libboost-system-dev libboost-thread-dev libgmp-dev libmpfr-dev python python-dev libcgal-dev wget openssh-client

    export OMPI_DIR=/opt/ompi
    export OMPI_URL="https://download.open-mpi.org/release/open-mpi/v${OMPI_VERSION:0:-2}/openmpi-$OMPI_VERSION.tar.bz2"
    mkdir -p /tmp/ompi
    mkdir -p /opt
    # Download
    cd /tmp/ompi && wget -O openmpi-$OMPI_VERSION.tar.bz2 $OMPI_URL && tar -xjf openmpi-$OMPI_VERSION.tar.bz2
    # Compile and install
    cd /tmp/ompi/openmpi-$OMPI_VERSION && ./configure --prefix=$OMPI_DIR && make -j$WM_NCOMPPROCS install

    # Set env variables so we can compile our application
    export PATH=$OMPI_DIR/bin:$PATH
    export LD_LIBRARY_PATH=$OMPI_DIR/lib:$LD_LIBRARY_PATH

    export FOAM_INST_DIR=/opt
    cd /opt
    wget http://downloads.sourceforge.net/foam/OpenFOAM-2.4.0.tgz
    tar -xzf OpenFOAM-2.4.0.tgz
    rm OpenFOAM-2.4.0.tgz
    sed -i -e 's/^\(cgal_version=\).*/\1cgal-system/' OpenFOAM-2.4.0/etc/config/CGAL.sh
    cd OpenFOAM-2.4.0
    find src applications -name "*.L" -type f | xargs sed -i -e 's=\(YY\_FLEX\_SUBMINOR\_VERSION\)=YY_FLEX_MINOR_VERSION < 6 \&\& \1='
    mkdir -p /opt/ThirdParty-2.4.0/platforms/linux64Gcc/cgal-system
    mkdir -p /opt/ThirdParty-2.4.0/platforms/linux64Gcc/boost-system

    ln -s /opt/ompi /opt/ThirdParty-2.4.0/platforms/linux64Gcc/openmpi-$OMPI_VERSION
    echo export FOAM_MPI=openmpi-$OMPI_VERSION > etc/config/openmpi.sh

    source /opt/OpenFOAM-2.4.0/etc/bashrc WM_MPLIB=OPENMPI

    ./Allwmake
    ./Allwmake
