install.sh 3.48 KiB
#!/bin/bash
# =========================================
# Script d'installation
# =========================================

function erreur {
  echo "Usage : $0 [--libs --maj --compil --all]"
  echo "--libs : Installation des bibliothèques python"
  echo "--maj : Téléchargement des fichiers sources pour OTB"
  echo "--compil : Compilation d'OTB"
  echo "--all : Téléchargement des sources et des bibliothèques python puis compilation d'OTB"
  exit
}

function confirme {
  read -r -p "${1}Êtes-vous sûr de vouloir continuer ? [O/N] " response
  if [[ $response == "o" || $response = "O" || $response == "y" || $response = "Y" ]]; then
    echo -e "${ROUGE}\e[1mLauching generation in $prefix_dir\e[0m"
  else
    exit
  fi
}

set -e

#Couleur 'Rouge' pour le terminal
ROUGE='\033[0;31m'

# Dossier courant du script
CMD="$(readlink -e "${BASH_SOURCE[0]}")"
SH_DIR="$(dirname "$CMD")"
prefix_dir=$SH_DIR

if [ ! -z $CXX ]; then
  echo "Version du compilateur : $CXX"
else
  CXX=`type -p g++`
fi

CXXVersion=`${CXX} -dumpversion`
version_compilateur="5.0.0"

if [ "$(printf '%s\n' "$version_compilateur" "$CXXVersion" | sort -V | head -n1)" = "$CXXVersion" ]; then
  echo "Gcc version too old"
  echo "Actual: ${CXXVersion}"
  echo "Needed: ${version_compilateur}"
  exit
fi

# Erreur si manque ou mauvais argument
if [[ "$#" != "1" ]]; then
  erreur
fi

if [[ "$1" != "--libs" ]] && [[ "$1" != "--maj" ]] && [[ "$1" != "--compil" ]] && [[ "$1" != "--all" ]]; then
  erreur
fi

if [[ "$1" == "--libs" ]]; then
  echo "Installation des bibliothèques python3"
  sudo apt-get update
  sudo apt-get install aptitude -y
  sudo aptitude install python3-pip -y
  sudo pip3 install -r "dépendances.txt"
fi


echo $prefix_dir/OTB

if [[ "$1" != "--libs" ]]; then

  echo "Installation de la bibliothèque OTB dans : ${prefix_dir}"
  confirme

  #----------------------------------------
  # Récupération des sources
  if [[ "$1" == "--maj" ]] || [[ "$1" == "--all" ]]; then
    # Clonage du repertoire OTB
    if [ -d "OTB" ]; then
      echo "Le répertoire OTB existe déjà."
    else
      echo "Clonage OTB ..."
      mkdir -p $prefix_dir/OTB
      cd $prefix_dir/OTB
      git clone https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb.git
    fi
  fi

  #----------------------------------------
  # Compilation
  if [[ "$1" != "--compil" ]] || [[ "$1" == "--all" ]] ; then 

  	sudo aptitude install make cmake-curses-gui build-essential libtool automake git libbz2-dev python-dev libboost-dev libboost-filesystem-dev libboost-serialization-dev libboost-system-dev zlib1g-dev libcurl4-gnutls-dev swig libgdal-dev

    
    echo "Compilation d'OTB ..."
    cd $prefix_dir/

    mkdir -p build
    mkdir -p build
    cd build

    # Compilation d'OTB
    cmake -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_CXX_FLAGS:STRING=-std=c++14 -DUSE_SYSTEM_BOOST=ON -DUSE_SYSTEM_CURL=ON -DUSE_SYSTEM_ZLIB=ON -DUSE_SYSTEM_GDAL=ON -DCMAKE_BUILD_TYPE=Release -DOTB_WRAP_PYTHON3:BOOL=ON -DGDAL_SB_EXTRA_OPTIONS:STRING="--with-python" -DCMAKE_INSTALL_PREFIX=$prefix_dir/OTB/install/ -DOTB_USE_QWT=OFF -DOTB_USE_GLEW=OFF -DOTB_USE_GLFW=OFF -DOTB_USE_GLUT=OFF -DOTB_USE_OPENGL=OFF -DOTB_USE_QT=OFF -DOTB_USE_QWT=OFF $prefix_dir/OTB/otb/SuperBuild/
    make --jobs=12

    # Compilation des modules
    cd $prefix_dir/OTB/build/OTB/build

    cmake -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_CXX_FLAGS:STRING=-std=c++14 -DModule_OTBPhenology:BOOL=ON -DModule_OTBTemporalGapFilling:BOOL=ON $prefix_dir/OTB/otb
    make --jobs=12
    make install
  fi

  echo "Installation terminée."

fi