v0.14.0
install_mofem_developer_spack_v0.12.sh
Go to the documentation of this file.
1 #!/bin/bash
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 # http://mofem.eng.gla.ac.uk/mofem/html/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
8 #
9 # Usage:
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
12 #
13 # Note: Installation script changes .bashrc on Ubuntu or .bash_profile on Mac.
14 # Please inspect the file after installation.
15 
16 echo "Start time: $(date +"%T")"
17 
18 ##############################
19 # INITIALISATION
20 ##############################
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 ### PREREQUISITES
40 ##############################
41 
42 echo -e "\n****************************\nInstalling PREREQUISITES...\n****************************\n"
43 echo "User password can be asked at some point. Please wait..."
44 
45 # Install appropriate prerequisite packages
46 if [ ${machine} = "Linux" ]
47 then
48  echo -e "\nRunning in Linux\n"
49  sudo apt-get update \
50  && sudo apt-get install -y --no-install-recommends \
51  autoconf \
52  build-essential \
53  ca-certificates \
54  coreutils \
55  curl \
56  environment-modules \
57  git \
58  python \
59  unzip \
60  vim \
61  gfortran
62 
63 elif [ ${machine} = "Mac" ]
64 then
65  echo -e "\nRunning in macOS\n"
66 
67  # Install Xcode
68  if ! which 'brew' &>/dev/null
69  then
70  xcode-select --install
71  sudo xcodebuild -license accept
72  /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
73  else
74  echo -e "\nHomebrew is already installed."
75  fi
76  brew install curl git gcc
77 
78  # Install XQuartz
79  if ! which 'xquartz' &>/dev/null
80  then
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
84  else
85  echo -e "\nXQuartz is already installed.\n"
86  fi
87 
88 fi
89 
90 echo -e "\nFinished installing Prerequisites.\n"
91 echo -e "\nNo user password will be asked from now on.\n"
92 
93 echo "Current directory: $PWD"
94 
95 
96 ##############################
97 ### SPACK
98 ##############################
99 
100 echo -e "\n****************************\nInstalling SPACK...\n****************************\n"
101 
102 # Locate home directory
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  echo "Cloning spack ..."
118  git clone -b develop_v0.12 https://bitbucket.org/mofem/mofem-spack.git spack
119  echo -e "Done.\n"
120 
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" ]
125  then
126  echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.bashrc
127  elif [ ${machine} = "Mac" ]
128  then
129  echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.bash_profile
130  fi
131 
132  # Download mirror
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
139  echo -e "Done.\n"
140  else
141  mkdir -p $SPACK_MIRROR_DIR && \
142  tar xzf $PWD/mirror.tgz -C $SPACK_MIRROR_DIR --strip 1
143  fi
144  fi
145 
146  # Add mirror
147  spack mirror remove mofem_mirror 2> /dev/null
148  spack mirror add mofem_mirror $SPACK_MIRROR_DIR
149 
150  # Install packages required by Spack
151  spack bootstrap
152 fi
153 
154 echo -e "\nFinished installing Spack.\n"
155 
156 echo "Current directory: $PWD"
157 
158 ########################################
159 ### MoFEM CORE LIBRARY & USER MODULES
160 ########################################
161 
162 echo -e "\n********************************************************\n"
163 echo -e "Installing CORE LIBRARY - Release version ..."
164 echo -e "\n********************************************************\n"
165 
166 # Locate MoFEM installation directory
167 cd $MOFEM_INSTALL_DIR
168 echo "Current directory: $PWD"
169 
170 # Clone MoFEM core library
171 if [ ! -d "$PWD/mofem-cephas" ]; then
172  git clone -b develop --recurse-submodules https://bitbucket.org/likask/mofem-cephas.git mofem-cephas
173 
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
177 
178 else
179  echo -e "\nMoFEM source directory is found"
180 fi
181 
182 # Clone MoFEM Fracture Module and Mortar Contact Module
183 cd $MOFEM_INSTALL_DIR/mofem-cephas/mofem/users_modules
184 git clone -b develop https://bitbucket.org/likask/mofem_um_fracture_mechanics.git
185 git clone -b develop https://bitbucket.org/mofem/mortar_contact.git
186 
187 # Installation of core library
188 cd $MOFEM_INSTALL_DIR
189 mkdir -p lib_release
190 cd lib_release
191 
192 spack install --only dependencies mofem-cephas+slepc ^petsc+X
193 spack setup mofem-cephas@develop+slepc copy_user_modules=False \
194  build_type=Release ^petsc+X
195 
196 echo -e "\n----------------------------\n"
197 echo -e "CORE LIBRARY - Release version: spconfig ..."
198 echo -e "\n----------------------------\n"
199 
200 ./spconfig.py -DMOFEM_BUILD_TESTS=ON $MOFEM_INSTALL_DIR/mofem-cephas/mofem
201 
202 echo -e "\n----------------------------\n"
203 echo -e "CORE LIBRARY - Release version: make -j 2 ..."
204 echo -e "\n----------------------------\n"
205 
206 make -j 2
207 
208 # Run the tests on core library
209 echo -e "\n----------------------------\n"
210 echo -e "CORE LIBRARY - Release version: ctest ..."
211 echo -e "\n----------------------------\n"
212 
213 spack load cmake
214 ctest -D Experimental
215 
216 # Install the library
217 echo -e "\n----------------------------\n"
218 echo -e "CORE LIBRARY - Release version: make install ..."
219 echo -e "\n----------------------------\n"
220 
221 make install
222 
223 echo -e "\nFinished installing and testing the Core Library.\n"
224 
225 echo -e "\n********************************************************\n"
226 echo -e "Installing USER MODULES - Release version ..."
227 echo -e "\n********************************************************\n"
228 
229 # Get mofem-cephas spack hash for release version
230 TODAY=`date +%F`
231 MOFEM_CEPHAS_HASH=`spack find -lv --start-date $TODAY | grep mofem-cephas@develop | grep Release | awk '{print $1}'`
232 echo "mofem-cephas id for release: $MOFEM_CEPHAS_HASH"
233 
234 # Installation of user modules
235 cd $MOFEM_INSTALL_DIR
236 
237 mkdir -p um
238 cd um/
239 spack view --verbose symlink -i um_view /$MOFEM_CEPHAS_HASH
240 export PATH=$PWD/um_view/bin:$PATH
241 # Add PATH to .bashrc on Ubuntu or .bash_profile on Mac
242 if [ ${machine} = "Linux" ]
243 then
244  echo "export PATH=$PWD/um_view/bin:\$PATH" >> ~/.bashrc
245 elif [ ${machine} = "Mac" ]
246 then
247  echo "export PATH=$PWD/um_view/bin:\$PATH" >> ~/.bash_profile
248 fi
249 
250 mkdir -p build_release
251 cd build_release/
252 
253 spack setup mofem-users-modules@develop \
254  copy_user_modules=False build_type=Release \
255  ^/$MOFEM_CEPHAS_HASH
256 
257 echo -e "\n----------------------------\n"
258 echo -e "USER MODULE - Release version: spconfig ..."
259 echo -e "\n----------------------------\n"
260 
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
263 
264 echo -e "\n----------------------------\n"
265 echo -e "USER MODULE - Release version: make -j 2 ..."
266 echo -e "\n----------------------------\n"
267 
268 make -j 2
269 
270 # Run the tests on user modules
271 echo -e "\n----------------------------\n"
272 echo -e "USER MODULE - Release version: ctest ..."
273 echo -e "\n----------------------------\n"
274 
275 ctest -D Experimental
276 
277 # Install the user module
278 echo -e "\n----------------------------\n"
279 echo -e "USER MODULE - Release version: make install ..."
280 echo -e "\n----------------------------\n"
281 
282 make install
283 
284 echo -e "\nFinished installing and testing the User Module - Release version.\n"
285 
286 
287 # ************************************************************************
288 # DEBUG VERSION
289 # ************************************************************************
290 
291 echo -e "\n********************************************************\n"
292 echo -e "Installing MoFEM - DEBUG VERSION..."
293 echo -e "\n********************************************************\n"
294 
295 
296 ########################################
297 ### MoFEM CORE LIBRARY & USER MODULES
298 ########################################
299 
300 # Locate MoFEM installation directory
301 cd $MOFEM_INSTALL_DIR
302 
303 # Installation of core library
304 mkdir -p lib_debug
305 cd lib_debug
306 
307 spack setup mofem-cephas@develop copy_user_modules=False \
308 build_type=Debug ^petsc+X
309 
310 echo -e "\n----------------------------\n"
311 echo -e "CORE LIBRARY - Debug version: spconfig ..."
312 echo -e "\n----------------------------\n"
313 
314 ./spconfig.py -DMOFEM_BUILD_TESTS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=1 $MOFEM_INSTALL_DIR/mofem-cephas/mofem
315 
316 
317 echo -e "\n----------------------------\n"
318 echo -e "CORE LIBRARY - Debug version: make -j 2 ..."
319 echo -e "\n----------------------------\n"
320 
321 make -j 2
322 
323 # Run the tests on core library
324 echo -e "\n----------------------------\n"
325 echo -e "CORE LIBRARY - Debug version: ctest ..."
326 echo -e "\n----------------------------\n"
327 
328 ctest -D Experimental
329 
330 # Install the library
331 echo -e "\n----------------------------\n"
332 echo -e "CORE LIBRARY - Debug version: make install ..."
333 echo -e "\n----------------------------\n"
334 
335 make install
336 
337 echo -e "\nFinished installing and testing the Core Library - Debug version.\n"
338 
339 echo -e "\n********************************************************\n"
340 echo -e "Installing USER MODULES - Debug version ..."
341 echo -e "\n********************************************************\n"
342 
343 # Get mofem-cephas spack hash for debug version
344 TODAY=`date +%F`
345 MOFEM_CEPHAS_HASH=`spack find -lv --start-date $TODAY | grep mofem-cephas@develop | grep Debug | awk '{print $1}'`
346 echo "mofem-cephas id for debug: $MOFEM_CEPHAS_HASH"
347 
348 # Installation of user modules
349 cd $MOFEM_INSTALL_DIR
350 
351 # mkdir um
352 cd um/
353 
354 spack view --verbose symlink -i um_view_debug /$MOFEM_CEPHAS_HASH
355 
356 mkdir -p build_debug
357 cd build_debug/
358 
359 
360 spack setup mofem-users-modules@develop \
361  copy_user_modules=False build_type=Debug \
362  ^/$MOFEM_CEPHAS_HASH
363 
364 echo -e "\n----------------------------\n"
365 echo -e "USER MODULE: spconfig - Debug version ..."
366 echo -e "\n----------------------------\n"
367 
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
370 
371 echo -e "\n----------------------------\n"
372 echo -e "USER MODULE - Debug version: make -j 2 ..."
373 echo -e "\n----------------------------\n"
374 
375 make -j 2
376 
377 # Run the tests on user modules
378 echo -e "\n----------------------------\n"
379 echo -e "USER MODULE - Debug version: ctest ..."
380 echo -e "\n----------------------------\n"
381 
382 ctest -D Experimental
383 
384 # Install the user module
385 echo -e "\n----------------------------\n"
386 echo -e "USER MODULE - Debug version: make install ..."
387 echo -e "\n----------------------------\n"
388 
389 make install
390 
391 echo -e "\nFinished installing and testing the User Module - Debug version.\n"
392 
393 echo "End time: $(date +"%T")"