From 204468d57102438bb43609ec9f0ba68470926b2e Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Tue, 21 Apr 2020 19:57:55 +0200
Subject: [PATCH] [bin][install] Fix several issues with installdumux.sh script

* Download the required cmake.opts file (requires wget)
* Make for loop work on macOS bash
* Check if folders are already created and skip if so
* Make paraview command optional (might be installed as a separate programme package and is not strcitly needed for this installation)
* Make mkdir work if DUMUX already exists
---
 bin/installdumux.sh | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/bin/installdumux.sh b/bin/installdumux.sh
index f6b368ba5f..c3f0b80545 100755
--- a/bin/installdumux.sh
+++ b/bin/installdumux.sh
@@ -6,13 +6,19 @@ echo "(0/3) Checking all prerequistes. (git gcc g++ cmake pkg-config paraview)"
 echo "*********************************************************************************************"
 
 # check some prerequistes
-for PRGRM in git gcc g++ cmake pkg-config paraview; do
+for PRGRM in wget git gcc g++ cmake pkg-config; do
     if ! [ -x "$(command -v $PRGRM)" ]; then
-        echo "Error: $PRGRM is not installed." >&2
+        echo "ERROR: $PRGRM is not installed." >&2
         exit 1
     fi
 done
 
+if ! [ -x "$(command -v paraview)" ]; then
+    echo "*********************************************************************************************"
+    echo "WARNING: paraview seems to be missing. You may not be able to view simulation results!" >&2
+    echo "*********************************************************************************************"
+fi
+
 currentver="$(gcc -dumpversion)"
 requiredver="7"
 if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" != "$requiredver" ]; then
@@ -33,7 +39,7 @@ fi
 
 
 # make a new folder containing everything
-mkdir $(pwd)/DUMUX
+mkdir -p $(pwd)/DUMUX
 cd DUMUX
 
 echo "*********************************************************************************************"
@@ -42,12 +48,21 @@ echo "**************************************************************************
 DUNE_VERSION=2.7
 DUMUX_VERSION=3.2
 # the core modules
-for MOD in common geometry grid localfunctions istl; do
-    git clone -b releases/$DUNE_VERSION  https://gitlab.dune-project.org/core/dune-$MOD.git
+for MOD in common geometry grid localfunctions istl
+do
+    if [ ! -d "dune-$MOD" ]; then
+        git clone -b releases/$DUNE_VERSION https://gitlab.dune-project.org/core/dune-$MOD.git
+    else
+        echo "Skip cloning dune-$MOD because the folder already exists."
+    fi
 done
 
 # dumux
-git clone -b releases/$DUMUX_VERSION https://git.iws.uni-stuttgart.de/dumux-repositories/dumux.git
+if [ ! -d "dumux" ]; then
+    git clone -b releases/$DUMUX_VERSION https://git.iws.uni-stuttgart.de/dumux-repositories/dumux.git
+else
+    echo "Skip cloning dumux because the folder already exists."
+fi
 
 if [ $? -ne 0 ]; then
     echo "*********************************************************************************************"
@@ -67,6 +82,7 @@ echo "(2/3) Configure and build dune modules and dumux using dunecontrol. This m
 echo "**************************************************************************************************"
 
 # run dunecontrol
+wget https://git.iws.uni-stuttgart.de/dumux-repositories/dumux/-/raw/releases/3.2/cmake.opts
 ./dune-common/bin/dunecontrol --opts=cmake.opts all
 
 if [ $? -ne 0 ]; then
-- 
GitLab