#!/bin/sh
distro=$1
launcher=$2
pkgtype=$3

if [ -z "$distro" -o "$distro" != "deb" -a "$distro" != "rhel" ] 
then
    echo "Usage: install.sh <distro> <launcher> <pkg_type>"
    echo "Please set target distro and re-run"
    echo "Valid options: deb, rhel"
    exit -1
fi

if [ -z "$launcher" -o "$launcher" != "mpirun" -a "$launcher" != "slurm" ] 
then
    echo "Usage: install.sh <distro> <launcher> <pkg_type>"
    echo "Please set target launcher and re-run"
    echo "Valid options: mpirun, slurm"
    exit -1
fi

if [ -z "$pkgtype" -o "$pkgtype" != "basic" -a "$pkgtype" != "advanced" -a "$pkgtype" != "inam" ] 
then
    echo "Usage: install.sh <distro> <pkgtype> <pkg_type>"
    echo "Please set target pkgtype and re-run"
    echo "Valid options: basic, advanced, inam"
    exit -1
fi

if [ "$distro" == "rhel" ] 
then
    if [ "$launcher" == "slurm" ] 
    then
        rpm -Uvh mvapich2-x-$pkgtype-mofed4.0-gnu4.4.7-slurm-2.3b-1.el6.x86_64.rpm
    else
        rpm -Uvh mvapich2-x-$pkgtype-mofed4.0-gnu4.4.7-2.3b-1.el6.x86_64.rpm
    fi
    rpm -Uvh --nodeps berkeley_upc-osu_gnu4.4.7-2.3b-1.el6.x86_64.rpm
    rpm -Uvh --nodeps berkeley_upcxx-osu_gnu4.4.7-2.3b-1.el6.x86_64.rpm
    rpm -Uvh --nodeps openshmem-osu_gnu4.4.7-2.3b-1.el6.x86_64.rpm
    rpm -Uvh --nodeps osu-micro-benchmarks_gnu4.4.7-5.4-1.el6.x86_64.rpm
    rpm -Uvh --nodeps libcaf-osu_gnu4.4.7-2.3b-1.el6.x86_64.rpm
else
    if [ "$launcher" == "slurm" ] 
    then
        apt-get install mvapich2-x-$pkgtype-mofed4.0-gnu4.4.7-slurm_2.3b-1.el6_amd64.deb
    else
        apt-get install mvapich2-x-$pkgtype-mofed4.0-gnu2.3b-1.el6_amd64.deb
    fi
    apt-get install --nodeps berkeley_upc-osu_gnu2.3b-1.el6_amd64.deb
    apt-get install --nodeps berkeley_upcxx-osu_gnu2.3b-1.el6_amd64.deb
    apt-get install --nodeps openshmem-osu_gnu2.3b-1.el6_amd64.deb
    apt-get install --nodeps osu-micro-benchmarks_gnu4.4.7-5.4-1.el6.x86_64.rpm
    apt-get install --nodeps libcaf-osu_gnu2.3b-1.el6_amd64.deb
fi
