2# This script automises installation of MoFEM developer version: Release & Debug
3# Full description of the installation process using spack can be found at:
4# https://mofem.eng.gla.ac.uk/install_spack.html
5# The script should work for both Ubuntu and macOS platforms
6# The last known working platforms are Ubuntu (18.04) and macOS (10.13, 10.14)
7# The installation may take two to three hours
10# 1. Copy install_mofem_developer.sh to the directory where MoFEM will be installed
11# 2. Run install_mofem_developer.sh from the command line
13# Note: Installation script changes .bashrc on Ubuntu or .bash_profile on Mac.
14# Please inspect the file after installation.
16echo "Start time: $(date +"%T")"
18##############################
20##############################
23# Setup installation directory
25export MOFEM_INSTALL_DIR="$PWD/mofem_install"
26mkdir -p $MOFEM_INSTALL_DIR
28# Check operating system
31 Linux*) machine=Linux;;
32 Darwin*) machine=Mac;;
33 CYGWIN*) machine=Cygwin;;
34 MINGW*) machine=MinGw;;
35 *) machine="UNKNOWN:${unameOut}"
38##############################
40##############################
42echo -e "\n****************************\nInstalling PREREQUISITES...\n****************************\n"
43echo "User password can be asked at some point. Please wait..."
45# Install appropriate prerequisite packages
46if [ ${machine} = "Linux" ]
48 echo -e "\nRunning in Linux\n"
50 && sudo apt-get install -y --no-install-recommends \
63elif [ ${machine} = "Mac" ]
65 echo -e "\nRunning in macOS\n"
68 if ! which 'brew' &>/dev/null
70 xcode-select --install
71 sudo xcodebuild -license accept
72 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
74 echo -e "\nHomebrew is already installed."
76 brew install curl git gcc
79 if ! which 'xquartz' &>/dev/null
81 echo -e "\nXQuartz is not installed yet. Installing XQuartz ...\n"
82 brew install caskroom/cask/brew-cask 2> /dev/null
83 brew cask install xquartz
85 echo -e "\nXQuartz is already installed.\n"
90echo -e "\nFinished installing Prerequisites.\n"
91echo -e "\nNo user password will be asked from now on.\n"
93echo "Current directory: $PWD"
96##############################
98##############################
100echo -e "\n****************************\nInstalling SPACK...\n****************************\n"
102# Locate home directory
106SPACK_ROOT_DIR=$MOFEM_INSTALL_DIR/spack
107SPACK_MIRROR_DIR=$MOFEM_INSTALL_DIR/mofem_mirror
109# Remove .spack directory in $HOME from previous installation (if any)
110if [ -d "$HOME/.spack" ]; then
111 mv $HOME/.spack $HOME/.spack_old
114# Retrieve Spack for MoFEM
115if [ ! -d "$SPACK_ROOT_DIR" ]; then
117 echo "Cloning spack ..."
118 git clone -b develop_v0.12 https://bitbucket.org/mofem/mofem-spack.git spack
121 # Initialise Spack environment variables:
122 . $SPACK_ROOT_DIR/share/spack/setup-env.sh
123 # Add command to configuration file .bashrc on Ubuntu or .bash_profile on Mac
124 if [ ${machine} = "Linux" ]
126 echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.bashrc
127 elif [ ${machine} = "Mac" ]
129 echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.bash_profile
133 if [ ! -d "$SPACK_MIRROR_DIR" ]; then
134 if [ ! -f "$PWD/mirror.tgz" ]; then
135 echo "Downloading mirror of spack packages for MoFEM..."
136 mkdir -p $SPACK_MIRROR_DIR && \
137 curl -s -L http://mofem.eng.gla.ac.uk/downloads/mirror_v0.9.2.tar.gz \
138 | tar xzC $SPACK_MIRROR_DIR --strip 1
141 mkdir -p $SPACK_MIRROR_DIR && \
142 tar xzf $PWD/mirror.tgz -C $SPACK_MIRROR_DIR --strip 1
147 spack mirror remove mofem_mirror 2> /dev/null
148 spack mirror add mofem_mirror $SPACK_MIRROR_DIR
150 # Install packages required by Spack
154echo -e "\nFinished installing Spack.\n"
156echo "Current directory: $PWD"
158########################################
159### MoFEM CORE LIBRARY & USER MODULES
160########################################
162echo -e "\n********************************************************\n"
163echo -e "Installing CORE LIBRARY - Release version ..."
164echo -e "\n********************************************************\n"
166# Locate MoFEM installation directory
168echo "Current directory: $PWD"
170# Clone MoFEM core library
171if [ ! -d "$PWD/mofem-cephas" ]; then
172 git clone -b develop --recurse-submodules https://bitbucket.org/likask/mofem-cephas.git mofem-cephas
174 # Checkout develop branch in user modules repo (sub-module)
175 cd mofem-cephas/mofem/users_modules
176 git fetch && git checkout develop && git pull
179 echo -e "\nMoFEM source directory is found"
182# Clone MoFEM Fracture Module and Mortar Contact Module
183cd $MOFEM_INSTALL_DIR/mofem-cephas/mofem/users_modules
184git clone -b develop https://bitbucket.org/likask/mofem_um_fracture_mechanics.git
185git clone -b develop https://bitbucket.org/mofem/mortar_contact.git
187# Installation of core library
192spack install --only dependencies mofem-cephas+slepc ^petsc+X
193spack setup mofem-cephas@develop+slepc copy_user_modules=False \
194 build_type=Release ^petsc+X
196echo -e "\n----------------------------\n"
197echo -e "CORE LIBRARY - Release version: spconfig ..."
198echo -e "\n----------------------------\n"
200./spconfig.py -DMOFEM_BUILD_TESTS=ON $MOFEM_INSTALL_DIR/mofem-cephas/mofem
202echo -e "\n----------------------------\n"
203echo -e "CORE LIBRARY - Release version: make -j 2 ..."
204echo -e "\n----------------------------\n"
208# Run the tests on core library
209echo -e "\n----------------------------\n"
210echo -e "CORE LIBRARY - Release version: ctest ..."
211echo -e "\n----------------------------\n"
217echo -e "\n----------------------------\n"
218echo -e "CORE LIBRARY - Release version: make install ..."
219echo -e "\n----------------------------\n"
223echo -e "\nFinished installing and testing the Core Library.\n"
225echo -e "\n********************************************************\n"
226echo -e "Installing USER MODULES - Release version ..."
227echo -e "\n********************************************************\n"
229# Get mofem-cephas spack hash for release version
231MOFEM_CEPHAS_HASH=`spack find -lv --start-date $TODAY | grep mofem-cephas@develop | grep Release | awk '{print $1}'`
232echo "mofem-cephas id for release: $MOFEM_CEPHAS_HASH"
234# Installation of user modules
239spack view --verbose symlink -i um_view /$MOFEM_CEPHAS_HASH
240export PATH=$PWD/um_view/bin:$PATH
241# Add PATH to .bashrc on Ubuntu or .bash_profile on Mac
242if [ ${machine} = "Linux" ]
244 echo "export PATH=$PWD/um_view/bin:\$PATH" >> ~/.bashrc
245elif [ ${machine} = "Mac" ]
247 echo "export PATH=$PWD/um_view/bin:\$PATH" >> ~/.bash_profile
250mkdir -p build_release
253spack setup mofem-users-modules@develop \
254 copy_user_modules=False build_type=Release \
257echo -e "\n----------------------------\n"
258echo -e "USER MODULE - Release version: spconfig ..."
259echo -e "\n----------------------------\n"
261./spconfig.py -DMOFEM_UM_BUILD_TESTS=ON -DFM_VERSION_MAJOR=0 -DFM_VERSION_MINOR=0 -DFM_VERSION_BUILD=0 -DMOFEM_DIR=../um_view \
262 $MOFEM_INSTALL_DIR/mofem-cephas/mofem/users_modules
264echo -e "\n----------------------------\n"
265echo -e "USER MODULE - Release version: make -j 2 ..."
266echo -e "\n----------------------------\n"
270# Run the tests on user modules
271echo -e "\n----------------------------\n"
272echo -e "USER MODULE - Release version: ctest ..."
273echo -e "\n----------------------------\n"
277# Install the user module
278echo -e "\n----------------------------\n"
279echo -e "USER MODULE - Release version: make install ..."
280echo -e "\n----------------------------\n"
284echo -e "\nFinished installing and testing the User Module - Release version.\n"
287# ************************************************************************
289# ************************************************************************
291echo -e "\n********************************************************\n"
292echo -e "Installing MoFEM - DEBUG VERSION..."
293echo -e "\n********************************************************\n"
296########################################
297### MoFEM CORE LIBRARY & USER MODULES
298########################################
300# Locate MoFEM installation directory
303# Installation of core library
307spack setup mofem-cephas@develop copy_user_modules=False \
308build_type=Debug ^petsc+X
310echo -e "\n----------------------------\n"
311echo -e "CORE LIBRARY - Debug version: spconfig ..."
312echo -e "\n----------------------------\n"
314./spconfig.py -DMOFEM_BUILD_TESTS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1 $MOFEM_INSTALL_DIR/mofem-cephas/mofem
317echo -e "\n----------------------------\n"
318echo -e "CORE LIBRARY - Debug version: make -j 2 ..."
319echo -e "\n----------------------------\n"
323# Run the tests on core library
324echo -e "\n----------------------------\n"
325echo -e "CORE LIBRARY - Debug version: ctest ..."
326echo -e "\n----------------------------\n"
331echo -e "\n----------------------------\n"
332echo -e "CORE LIBRARY - Debug version: make install ..."
333echo -e "\n----------------------------\n"
337echo -e "\nFinished installing and testing the Core Library - Debug version.\n"
339echo -e "\n********************************************************\n"
340echo -e "Installing USER MODULES - Debug version ..."
341echo -e "\n********************************************************\n"
343# Get mofem-cephas spack hash for debug version
345MOFEM_CEPHAS_HASH=`spack find -lv --start-date $TODAY | grep mofem-cephas@develop | grep Debug | awk '{print $1}'`
346echo "mofem-cephas id for debug: $MOFEM_CEPHAS_HASH"
348# Installation of user modules
354spack view --verbose symlink -i um_view_debug /$MOFEM_CEPHAS_HASH
360spack setup mofem-users-modules@develop \
361 copy_user_modules=False build_type=Debug \
364echo -e "\n----------------------------\n"
365echo -e "USER MODULE: spconfig - Debug version ..."
366echo -e "\n----------------------------\n"
368./spconfig.py -DMOFEM_UM_BUILD_TESTS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DFM_VERSION_MAJOR=0 -DFM_VERSION_MINOR=0 -DFM_VERSION_BUILD=0 -DMOFEM_DIR=../um_view_debug \
369 $MOFEM_INSTALL_DIR/mofem-cephas/mofem/users_modules
371echo -e "\n----------------------------\n"
372echo -e "USER MODULE - Debug version: make -j 2 ..."
373echo -e "\n----------------------------\n"
377# Run the tests on user modules
378echo -e "\n----------------------------\n"
379echo -e "USER MODULE - Debug version: ctest ..."
380echo -e "\n----------------------------\n"
384# Install the user module
385echo -e "\n----------------------------\n"
386echo -e "USER MODULE - Debug version: make install ..."
387echo -e "\n----------------------------\n"
391echo -e "\nFinished installing and testing the User Module - Debug version.\n"
393echo "End time: $(date +"%T")"