#!/bin/bash

install_version=${1:-"4.0.3"}
package_name="ompi-${install_version}"

# Install lib
apt install -y autoconf
apt install -y libtool
apt install -y automake
apt install -y flex

# Download
cd /tmp
rm -f ${package_name}.tar.gz
wget http://tools.mindspore.cn/tools/run/ompi/${package_name}/${package_name}.tar.gz
rm -rf ${package_name}
tar -zxf ${package_name}.tar.gz

# Install
cd /tmp/${package_name}
./autogen.pl
./configure
make -j32
make install -j32
cd ..

# Set env
grep "export LD_LIBRARY_PATH=/usr/local/lib:" ~/.bashrc
if [ $? -ne 0 ]; then
    echo "" >> ~/.bashrc
    echo "# ompi env" >> ~/.bashrc
    echo "export LD_LIBRARY_PATH=/usr/local/lib:\${LD_LIBRARY_PATH}" >> ~/.bashrc
fi

# Delete package
rm -rf /tmp/${package_name}
rm -f /tmp/${package_name}.tar.gz
