2# This script automises installation of MoFEM user version with basic modules
4# Full description of the installation process using spack can be found at:
5# https://mofem.eng.gla.ac.uk/install_spack.html
6# The script should work for both Ubuntu and macOS platforms
7# The last known working platforms are Ubuntu (18.04) and macOS (10.13, 10.14)
8# The installation may take two to three hours
11# 1. Copy install_mofem_user.sh to the directory where MoFEM will be installed
12# 2. Run install_mofem_user.sh from the command line
14# Note: Installation script changes .bashrc on Ubuntu or .bash_profile on Mac.
15# Please inspect the file after installation.
17echo "Start time: $(date +"%T")"
19##############################
21##############################
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}"
39##############################
41##############################
43echo -e "\n****************************\nInstalling PREREQUISITES...\n****************************\n"
44echo "User password can be asked at some point. Please wait..."
46# Install appropriate prerequisite packages
47if [ ${machine} = "Linux" ]
49 echo -e "\nRunning in Linux\n"
51 && sudo apt-get install -y --no-install-recommends \
64elif [ ${machine} = "Mac" ]
66 echo -e "\nRunning in macOS\n"
69 if ! which 'brew' &>/dev/null
71 xcode-select --install
72 sudo xcodebuild -license accept
73 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
75 echo -e "\nHomebrew installed"
78 brew install curl git gcc
81 if ! which 'xquartz' &>/dev/null
83 echo -e "\nXQuartz is not installed yet. Installing XQuartz ...\n"
84 brew install caskroom/cask/brew-cask 2> /dev/null
85 brew cask install xquartz
87 echo -e "\nXQuartz is already installed.\n"
92echo -e "\nFinished installing Prerequisites.\n"
93echo "No user password will be asked from now on."
95echo "Current directory: $PWD"
97##############################
99##############################
101echo -e "\n****************************\nInstalling SPACK...\n****************************\n"
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 if [ ! -f "$PWD/spack.tgz" ]; then
118 echo "Downloading spack ..."
119 mkdir -p $SPACK_ROOT_DIR &&\
120 curl -s -L https://api.github.com/repos/likask/spack/tarball/master_v0.12 \
121 | tar xzC $SPACK_ROOT_DIR --strip 1
124 mkdir -p $SPACK_ROOT_DIR &&\
125 tar xzf $PWD/spack.tgz -C $SPACK_ROOT_DIR --strip 1
128 # Initialise Spack environment variables:
129 . $SPACK_ROOT_DIR/share/spack/setup-env.sh
130 # Add command to configuration file .bashrc on Ubuntu or .bash_profile on Mac
131 if [ ${machine} = "Linux" ]
133 echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.bashrc
134 elif [ ${machine} = "Mac" ]
136 echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.bash_profile
140 if [ ! -d "$SPACK_MIRROR_DIR" ]; then
141 if [ ! -f "$PWD/mirror.tgz" ]; then
142 echo "Downloading mirror of spack packages for MoFEM..."
143 mkdir -p $SPACK_MIRROR_DIR && \
144 curl -s -L http://mofem.eng.gla.ac.uk/downloads/mirror_v0.9.2.tar.gz \
145 | tar xzC $SPACK_MIRROR_DIR --strip 1
148 mkdir -p $SPACK_MIRROR_DIR && \
149 tar xzf $PWD/mirror.tgz -C $SPACK_MIRROR_DIR --strip 1
154 spack mirror remove mofem_mirror 2> /dev/null
155 spack mirror add mofem_mirror $SPACK_MIRROR_DIR
157 # Install packages required by Spack
161echo -e "\nFinished installing Spack.\n"
163echo "Current directory: $PWD"
165##############################
166### MoFEM USER MODULES
167##############################
169echo -e "\n********************************************************\n"
170echo -e "Installing USER MODULE & FRACTURE MODULE..."
171echo -e "\n********************************************************\n"
173# Locate MoFEM installation directory
175echo "Current directory: $PWD"
177# Install MoFEM packages
178spack install -j 2 mofem-fracture-module build_type=Release ^petsc+X
180# Activate fracture module
181spack view --verbose symlink -i um_view mofem-fracture-module
184cd $MOFEM_INSTALL_DIR/um_view/elasticity
185echo "Current directory: $PWD"
188-my_order 2 2>&1 | tee log
190echo -e "\nFinished testing elasticity.\n"
192# Test fracture crack propagation
193cd $MOFEM_INSTALL_DIR/um_view/fracture_mechanics
194echo "Current directory: $PWD"
196-my_file examples/analytical_bc/out_10.h5m \
198-my_ref 0 2>&1 | tee log
200echo -e "\nFinished testing fracture module.\n"
202# Check the output message and finalise the installation
203if tail -n 1 log | grep -q "Crack surface area"
205 echo -e "\nInstallation SUCCESSFUL!\n"
207 # Export view and make view visible from any directory
208 export PATH=$PWD/um_view/bin:$PATH
209 # Add PATH to .bashrc on Ubuntu or .bash_profile on Mac
210 if [ ${machine} = "Linux" ]
212 echo "export PATH=$PWD/um_view/bin:\$PATH" >> ~/.bashrc
213 elif [ ${machine} = "Mac" ]
215 echo "export PATH=$PWD/um_view/bin:\$PATH" >> ~/.bash_profile
218 echo "Please check PATH in .bashrc (Ubuntu) or .bash_profile (macOS) and remove the old ones."
220 echo -e "\nInstallation FAILED!\n"
223echo "End time: $(date +"%T")"