#!/bin/bash
echo "**********************************************************"
echo "*                        MAGiC                           *"
echo "*                                                        *"
echo "*                        ERICCA                          *"
echo "*                                                        *"
echo "*         Departement de genie mecanique - UQTR          *"
echo "*                                                        *"
echo "*         Installation des modules Code aster "$1"       *"
echo "*                                                        *"
echo "**********************************************************"
echo ""
echo $(date)
versionos=$(lsb_release -sr)
echo ""
echo "Code Aster installation"
if [ $1 == 15.6 ]; 
then
version=15.6
else
echo "Version "$1" non supportée"
exit
fi
echo "version" $version
echo "Checking / Installing dependencies"

tabdep=(build-essential libseccomp-dev pkg-config squashfs-tools cryptsetup git)

echo "Dependance a verifier :"${#tabdep[*]}
for i in ${!tabdep[*]};
do
nomdep=${tabdep[i]}
dpkg -s $nomdep  >> /dev/null 2>&1
if [ $? == 1 ];
then
echo $nomdep...............FAIL
sudo apt-get -y install $nomdep  
else
echo $nomdep...............ok
fi
done
export GOPATH=${HOME}/go 
export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin
echo 'export GOPATH=${HOME}/go' >> ~/.bashrc
echo 'export PATH=/usr/local/go/bin:${PATH}:${GOPATH}/bin' >> ~/.bashrc
source ~/.bashrc
cd $HOME
wget http://ericca.uqtr.ca/codeaster/go1.15.5.linux-amd64.tar.gz
tar -C ./ -xzf go1.15.5.linux-amd64.tar.gz
go version

mkdir $HOME/dev
cd $HOME/dev
git clone https://github.com/sylabs/singularity.git && cd singularity
git checkout v3.7.0
./mconfig
cd ./builddir
make
sudo make install



__DIR=`pwd`
if [ $version == 15.6 ];
then
wget http://ericca.uqtr.ca/codeaster/salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif
mkdir $HOME/containers
mv salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif $HOME/containers
cd $HOME/containers
singularity run --app install salome_meca-lgpl-2022.1.0-1-20221225-scibian-9.sif
fi


cd $__DIR
echo ""
echo $(date)
echo ""
echo "**********************************************************"
echo "*                        MAGiC                           *"
echo "*                                                        *"
echo "*                        ERICCA                          *"
echo "*                                                        *"
echo "*         Departement de genie mecanique - UQTR          *"
echo "*                                                        *"
echo "*           Installation du module Code aster            *"
echo "*                                                        *"
echo "**********************************************************"


