forked from usgs/ps2ff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
122 lines (95 loc) · 3.11 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
#!/bin/bash
unamestr=`uname`
env_file=environment.yml
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
source $prof
echo "Path:"
echo $PATH
VENV=ps2ff
# Is the reset flag set?
reset=0
while getopts r FLAG; do
case $FLAG in
r)
reset=1
;;
esac
done
# create a matplotlibrc file with the non-interactive backend "Agg" in it.
if [ ! -d "$matplotlibdir" ]; then
mkdir -p $matplotlibdir
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..."
curl $mini_conda_url -o miniconda.sh;
echo "Install directory: $HOME/miniconda"
bash miniconda.sh -f -b -p $HOME/miniconda
# Need this to get conda into path
. $HOME/miniconda/etc/profile.d/conda.sh
else
echo "conda detected, installing $VENV environment..."
fi
echo "PATH:"
echo $PATH
echo ""
# Choose an environment file based on platform
echo ". $HOME/miniconda/etc/profile.d/conda.sh" >> $prof
# If the user has specified the -r (reset) flag, then create an
# environment based on only the named dependencies, without
# any versions of packages specified.
if [ $reset == 1 ]; then
echo "Ignoring platform, letting conda sort out dependencies..."
env_file=environment.yml
fi
# Start in conda base environment
echo "Activate base virtual environment"
conda activate base
# Remove existing shakemap environment if it exists
conda remove -y -n $VENV --all
# Create a conda virtual environment
echo "Creating the $VENV virtual environment:"
conda env create -f $env_file --force
# 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
fi
# Activate the new environment
echo "Activating the $VENV virtual environment"
conda activate $VENV
# This package
echo "Installing ps2ff..."
pip install -e .
# Install default profile
#python bin/sm_profile -c default -a
# Tell the user they have to activate this environment
echo "Type 'conda activate $VENV' to use this new virtual environment."