forked from usgs/shakemap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·249 lines (206 loc) · 6.07 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/bin/bash
unamestr=`uname`
if [ "$unamestr" == 'Linux' ]; then
prof=~/.bashrc
mini_conda_url=https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
matplotlibdir=~/.config/matplotlib
elif [ "$unamestr" == 'FreeBSD' ] || [ "$unamestr" == 'Darwin' ]; then
prof=~/.bash_profile
mini_conda_url=https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
matplotlibdir=~/.matplotlib
else
echo "Unsupported environment. Exiting."
exit
fi
CC_PKG=c-compiler
source $prof
# Name of virtual environment
VENV=shakemap
developer=0
py_ver=3.8
while getopts p:d FLAG; do
case $FLAG in
p)
py_ver=$OPTARG
;;
d)
echo "Installing developer packages."
developer=1
;;
esac
done
if [ $py_ver == '3.8' ] && [ "$unamestr" == 'Linux' ]; then
echo "WARNING: ShakeMap on Python v3.8 on some versions of Linux "
echo "may fail in unexpected ways. We are enforcing the use "
echo "of Python v3.7 until this warning disappears."
echo ""
py_ver=3.7
fi
echo "Using python version $py_ver"
echo ""
# create a matplotlibrc file with the non-interactive backend "Agg" in it.
if [ ! -d "$matplotlibdir" ]; then
mkdir -p $matplotlibdir
# if mkdir fails, bow out gracefully
if [ $? -ne 0 ];then
echo "Failed to create matplotlib configuration file. Exiting."
exit 1
fi
fi
matplotlibrc=$matplotlibdir/matplotlibrc
if [ ! -e "$matplotlibrc" ]; then
echo "backend : Agg" > "$matplotlibrc"
echo "NOTE: A non-interactive matplotlib backend (Agg) has been set for this user."
elif grep -Fxq "backend : Agg" $matplotlibrc ; then
:
elif [ ! grep -Fxq "backend" $matplotlibrc ]; then
echo "backend : Agg" >> $matplotlibrc
echo "NOTE: A non-interactive matplotlib backend (Agg) has been set for this user."
else
sed -i '' 's/backend.*/backend : Agg/' $matplotlibrc
echo "###############"
echo "NOTE: $matplotlibrc has been changed to set 'backend : Agg'"
echo "###############"
fi
# Is conda installed?
conda --version
if [ $? -ne 0 ]; then
echo "No conda detected, installing miniconda..."
command -v curl >/dev/null 2>&1 || { echo >&2 "Script requires curl but it's not installed. Aborting."; exit 1; }
curl -L $mini_conda_url -o miniconda.sh;
# if curl fails, bow out gracefully
if [ $? -ne 0 ];then
echo "Failed to download miniconda installer shell script. Exiting."
exit 1
fi
echo "Install directory: $HOME/miniconda"
bash miniconda.sh -f -b -p $HOME/miniconda
# if miniconda.sh fails, bow out gracefully
if [ $? -ne 0 ];then
echo "Failed to run miniconda installer shell script. Exiting."
exit 1
fi
. $HOME/miniconda/etc/profile.d/conda.sh
# remove the shell script
rm miniconda.sh
else
echo "conda detected, installing $VENV environment..."
fi
echo "Installing packages from conda-forge"
# Choose an environment file based on platform
# only add this line if it does not already exist
grep "/etc/profile.d/conda.sh" $prof
if [ $? -ne 0 ]; then
echo ". $_CONDA_ROOT/etc/profile.d/conda.sh" >> $prof
fi
# Start in conda base environment
echo "Activate base virtual environment"
eval "$(conda shell.bash hook)"
conda activate base
# Remove existing shakemap environment if it exists
conda remove -y -n $VENV --all
# Extra packages to install with dev option
dev_list=(
"autopep8"
"flake8"
"pyflakes"
"rope"
"yapf"
"sphinx"
"sphinx-argparse"
)
# Required package list:
package_list=(
"python=$py_ver"
"$CC_PKG"
"cartopy>=0.18"
"cython"
"defusedxml"
"descartes"
"docutils"
"configobj"
"fiona"
"gdal"
"h5py"
"impactutils"
"ipython"
"libcomcat"
"lockfile"
"mapio"
"matplotlib-base"
"numpy"
"obspy"
"openmp"
"pandas"
"ps2ff"
"psutil"
"pyproj"
"pytest"
"pytest-cov"
"python-daemon"
"pytest-faulthandler"
"pytest-azurepipelines"
"scikit-image"
"scipy"
"shapely"
"simplekml"
"strec"
"versioneer"
"vcrpy"
)
if [ $developer == 1 ]; then
package_list=( "${package_list[@]}" "${dev_list[@]}" )
echo ${package_list[*]}
fi
# Create a conda virtual environment
conda config --add channels 'conda-forge'
conda config --add channels 'defaults'
conda config --set channel_priority flexible
echo "Creating the $VENV virtual environment:"
conda create -y -n $VENV ${package_list[*]}
# Bail out at this point if the conda create command fails.
# Clean up zip files we've downloaded
if [ $? -ne 0 ]; then
echo "Failed to create conda environment. Resolve any conflicts, then try again."
exit 1
fi
# Activate the new environment
echo "Activating the $VENV virtual environment"
conda activate $VENV
# if conda activate fails, bow out gracefully
if [ $? -ne 0 ];then
echo "Failed to activate ${VENV} conda environment. Exiting."
exit 1
fi
# upgrade pip, mostly so pip doesn't complain about not being new...
pip install --upgrade pip
# if pip upgrade fails, complain but try to keep going
if [ $? -ne 0 ];then
echo "Failed to upgrade pip, trying to continue..."
exit 1
fi
# The presence of a __pycache__ folder in bin/ can cause the pip
# install to fail... just to be safe, we'll delete it here.
if [ -d bin/__pycache__ ]; then
rm -rf bin/__pycache__
fi
if [ $developer == 1 ]; then
pip install sphinx-argparse
fi
# Install OQ from github to get NGA East since it isn't in a release yet.
echo "Installing OpenQuake from github..."
pip install --upgrade git+https://github.com/gem/oq-engine
if [ $? -ne 0 ];then
echo "Failed to pip install OpenQuake. Exiting."
exit 1
fi
# This package
echo "Installing ${VENV}..."
pip install --no-deps -e .
# if pip install fails, bow out gracefully
if [ $? -ne 0 ];then
echo "Failed to pip install this package. Exiting."
exit 1
fi
# Tell the user they have to activate this environment
echo "Type 'conda activate $VENV' to use this new virtual environment."