v0.14.0
install_mofem_user_spack_v0.12.sh
Go to the documentation of this file.
1 #!/bin/bash
2 # This script automises installation of MoFEM user version with basic modules
3 # and fracture module
4 # Full description of the installation process using spack can be found at:
5 # http://mofem.eng.gla.ac.uk/mofem/html/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
9 #
10 # Usage:
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
13 #
14 # Note: Installation script changes .bashrc on Ubuntu or .bash_profile on Mac.
15 # Please inspect the file after installation.
16 
17 echo "Start time: $(date +"%T")"
18 
19 ##############################
20 # INITIALISATION
21 ##############################
22 
23 # Setup installation directory
24 pwd
25 export MOFEM_INSTALL_DIR="$PWD/mofem_install"
26 mkdir -p $MOFEM_INSTALL_DIR
27 
28 # Check operating system
29 unameOut="$(uname -s)"
30 case "${unameOut}" in
31  Linux*) machine=Linux;;
32  Darwin*) machine=Mac;;
33  CYGWIN*) machine=Cygwin;;
34  MINGW*) machine=MinGw;;
35  *) machine="UNKNOWN:${unameOut}"
36 esac
37 
38 
39 ##############################
40 ### PREREQUISITES
41 ##############################
42 
43 echo -e "\n****************************\nInstalling PREREQUISITES...\n****************************\n"
44 echo "User password can be asked at some point. Please wait..."
45 
46 # Install appropriate prerequisite packages
47 if [ ${machine} = "Linux" ]
48 then
49  echo -e "\nRunning in Linux\n"
50  sudo apt-get update \
51  && sudo apt-get install -y --no-install-recommends \
52  autoconf \
53  build-essential \
54  ca-certificates \
55  coreutils \
56  curl \
57  environment-modules \
58  git \
59  python \
60  unzip \
61  vim \
62  gfortran
63 
64 elif [ ${machine} = "Mac" ]
65 then
66  echo -e "\nRunning in macOS\n"
67 
68  # Install Xcode
69  if ! which 'brew' &>/dev/null
70  then
71  xcode-select --install
72  sudo xcodebuild -license accept
73  /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
74  else
75  echo -e "\nHomebrew installed"
76  fi
77 
78  brew install curl git gcc
79 
80  # Install XQuartz
81  if ! which 'xquartz' &>/dev/null
82  then
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
86  else
87  echo -e "\nXQuartz is already installed.\n"
88  fi
89 
90 fi
91 
92 echo -e "\nFinished installing Prerequisites.\n"
93 echo "No user password will be asked from now on."
94 
95 echo "Current directory: $PWD"
96 
97 ##############################
98 ### SPACK
99 ##############################
100 
101 echo -e "\n****************************\nInstalling SPACK...\n****************************\n"
102 
103 cd $MOFEM_INSTALL_DIR
104 echo "$PWD"
105 
106 SPACK_ROOT_DIR=$MOFEM_INSTALL_DIR/spack
107 SPACK_MIRROR_DIR=$MOFEM_INSTALL_DIR/mofem_mirror
108 
109 # Remove .spack directory in $HOME from previous installation (if any)
110 if [ -d "$HOME/.spack" ]; then
111  mv $HOME/.spack $HOME/.spack_old
112 fi
113 
114 # Retrieve Spack for MoFEM
115 if [ ! -d "$SPACK_ROOT_DIR" ]; then
116 
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
122  echo -e "Done.\n"
123  else
124  mkdir -p $SPACK_ROOT_DIR &&\
125  tar xzf $PWD/spack.tgz -C $SPACK_ROOT_DIR --strip 1
126  fi
127 
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" ]
132  then
133  echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.bashrc
134  elif [ ${machine} = "Mac" ]
135  then
136  echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.bash_profile
137  fi
138 
139  # Download mirror
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
146  echo -e "Done.\n"
147  else
148  mkdir -p $SPACK_MIRROR_DIR && \
149  tar xzf $PWD/mirror.tgz -C $SPACK_MIRROR_DIR --strip 1
150  fi
151  fi
152 
153  # Add mirror
154  spack mirror remove mofem_mirror 2> /dev/null
155  spack mirror add mofem_mirror $SPACK_MIRROR_DIR
156 
157  # Install packages required by Spack
158  spack bootstrap
159 fi
160 
161 echo -e "\nFinished installing Spack.\n"
162 
163 echo "Current directory: $PWD"
164 
165 ##############################
166 ### MoFEM USER MODULES
167 ##############################
168 
169 echo -e "\n********************************************************\n"
170 echo -e "Installing USER MODULE & FRACTURE MODULE..."
171 echo -e "\n********************************************************\n"
172 
173 # Locate MoFEM installation directory
174 cd $MOFEM_INSTALL_DIR
175 echo "Current directory: $PWD"
176 
177 # Install MoFEM packages
178 spack install -j 2 mofem-fracture-module build_type=Release ^petsc+X
179 
180 # Activate fracture module
181 spack view --verbose symlink -i um_view mofem-fracture-module
182 
183 # Test elasticity
184 cd $MOFEM_INSTALL_DIR/um_view/elasticity
185 echo "Current directory: $PWD"
186 ./elasticity \
187 -my_file LShape.h5m \
188 -my_order 2 2>&1 | tee log
189 
190 echo -e "\nFinished testing elasticity.\n"
191 
192 # Test fracture crack propagation
193 cd $MOFEM_INSTALL_DIR/um_view/fracture_mechanics
194 echo "Current directory: $PWD"
195 ./crack_propagation \
196 -my_file examples/analytical_bc/out_10.h5m \
197 -my_order 2 \
198 -my_ref 0 2>&1 | tee log
199 
200 echo -e "\nFinished testing fracture module.\n"
201 
202 # Check the output message and finalise the installation
203 if tail -n 1 log | grep -q "Crack surface area"
204 then
205  echo -e "\nInstallation SUCCESSFUL!\n"
206 
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" ]
211  then
212  echo "export PATH=$PWD/um_view/bin:\$PATH" >> ~/.bashrc
213  elif [ ${machine} = "Mac" ]
214  then
215  echo "export PATH=$PWD/um_view/bin:\$PATH" >> ~/.bash_profile
216  fi
217 
218  echo "Please check PATH in .bashrc (Ubuntu) or .bash_profile (macOS) and remove the old ones."
219 else
220  echo -e "\nInstallation FAILED!\n"
221 fi
222 
223 echo "End time: $(date +"%T")"