v0.14.0
install_mofem_user.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 # Only for debugging
18 #set -x
19 
20 echo "Start time: $(date +"%T")"
21 
22 ##############################
23 # INITIALISATION
24 ##############################
25 
26 # Setup installation directory
27 pwd
28 export MOFEM_INSTALL_DIR="$PWD/mofem_install"
29 mkdir -p $MOFEM_INSTALL_DIR
30 
31 # Check operating system
32 unameOut="$(uname -s)"
33 case "${unameOut}" in
34  Linux*) machine=Linux;;
35  Darwin*) machine=Mac;;
36  CYGWIN*) machine=Cygwin;;
37  MINGW*) machine=MinGw;;
38  *) machine="UNKNOWN:${unameOut}"
39 esac
40 
41 
42 ##############################
43 ### PREREQUISITES
44 ##############################
45 
46 echo -e "\n****************************\nInstalling PREREQUISITES...\n****************************\n"
47 echo "User password can be asked at some point. Please wait..."
48 
49 # Install appropriate prerequisite packages
50 if [ ${machine} = "Linux" ]
51 then
52  echo -e "\nRunning in Linux\n"
53  sudo apt-get update \
54  && sudo apt-get install -y --no-install-recommends \
55  autoconf \
56  build-essential \
57  ca-certificates \
58  coreutils \
59  curl \
60  environment-modules \
61  pkgconf \
62  cmake \
63  git \
64  python3 \
65  python3-distutils \
66  unzip \
67  ssh \
68  vim \
69  gfortran
70 
71 elif [ ${machine} = "Mac" ]
72 then
73  echo -e "\nRunning in macOS\n"
74 
75  # Install Xcode
76  if ! which 'brew' &>/dev/null
77  then
78  xcode-select --install
79  sudo xcodebuild -license accept
80  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
81  else
82  echo -e "\nHomebrew installed"
83  fi
84 
85  brew install \
86  curl \
87  git \
88  python \
89  gcc@9 \
90  cmake \
91  autoconf \
92  automake \
93  libtool \
94  doxygen \
95  pkg-config
96 
97  # Install XQuartz
98  if ! which 'xquartz' &>/dev/null
99  then
100  echo -e "\nXQuartz is not installed yet. Installing XQuartz ...\n"
101  brew install --cask xquartz
102  else
103  echo -e "\nXQuartz is already installed.\n"
104  fi
105 
106 fi
107 
108 echo -e "\nFinished installing Prerequisites.\n"
109 echo "No user password will be asked from now on."
110 
111 echo "Current directory: $PWD"
112 
113 ##############################
114 ### SPACK
115 ##############################
116 
117 echo -e "\n****************************\nInstalling SPACK...\n****************************\n"
118 
119 cd $MOFEM_INSTALL_DIR
120 echo "$PWD"
121 
122 SPACK_ROOT_DIR=$MOFEM_INSTALL_DIR/spack
123 
124 # Retrieve Spack for MoFEM
125 if [ ! -d "$SPACK_ROOT_DIR" ]; then
126 
127  # Remove .spack directory in $HOME from previous installation (if any)
128  if [ -d "$HOME/.spack" ]; then
129  mv $HOME/.spack $HOME/.spack_old
130  fi
131 
132  if [ ! -f "$PWD/spack.tgz" ]; then
133  echo "Downloading spack ..."
134  mkdir -p $SPACK_ROOT_DIR &&\
135  git clone -b Workshop23 https://bitbucket.org/mofem/mofem-spack.git spack
136  echo -e "Done.\n"
137  else
138  mkdir -p $SPACK_ROOT_DIR &&\
139  tar xzf $PWD/spack.tgz -C $SPACK_ROOT_DIR --strip 1
140  fi
141 
142  # Initialise Spack environment variables:
143  . $SPACK_ROOT_DIR/share/spack/setup-env.sh
144  # Add command to configuration file .bashrc on Ubuntu or .bash_profile on Mac
145  if [ ${machine} = "Linux" ]
146  then
147  echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.bashrc
148  elif [ ${machine} = "Mac" ]
149  then
150  echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.bash_profile
151  echo ". $SPACK_ROOT_DIR/share/spack/setup-env.sh" >> ~/.zshrc
152  fi
153 
154  # Install packages required by Spack
155  spack compiler find
156  spack external find
157 
158 fi
159 
160 echo -e "\nFinished installing Spack.\n"
161 
162 echo "Current directory: $PWD"
163 
164 ##############################
165 ### MoFEM USER MODULES
166 ##############################
167 
168 echo -e "\n********************************************************\n"
169 echo -e "Installing USER MODULE ..."
170 echo -e "\n********************************************************\n"
171 
172 # Locate MoFEM installation directory
173 cd $MOFEM_INSTALL_DIR
174 echo "Current directory: $PWD"
175 
176 # Install MoFEM packages
177 spack install --only dependencies mofem-cephas ^petsc+X
178 spack install --test root mofem-users-modules build_type=Release ^petsc+X
179 
180 # Activate fracture module
181 spack view --verbose symlink -i um_view mofem-users-modules
182 
183 # Export view and make view visible from any directory
184 export PATH=$PWD/um_view/bin:$PATH
185 
186 echo "End time: $(date +"%T")"