forked from markovmodel/PyEMMA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_miniconda+pyemma.sh
executable file
Β·129 lines (115 loc) Β· 4.28 KB
/
install_miniconda+pyemma.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
#!/usr/bin/env bash
# This script installs Miniconda and PyEMMA. If conda is already available, we install PyEMMA in a new environment.
# By default, we use the name 'pyemma' as environment name.
# The desired output folders and env names can be set by arguments.
# Author: Martin Scherer, 2018
function usage {
echo "Usage of installation script:"
echo "bash $0 -t 'miniconda_target_directory' path to Miniconda"
echo "bash $0 -e 'conda_environment' environment name in which pyemma will be installed."
echo "bash $0 -i ignore existing miniconda installation. Get a fresh copy."
echo "bash $0 -n do not add the new path of miniconda installation to PATH (bashrc update) [off by default]."
echo "bash $0 -m minimal set of packags, eg. omit jupyter notebook installation."
}
# default values for arguments.
target=$HOME/miniconda3
env_name="pyemma"
ignore=1 # dont ignore existing miniconda installation, but just use it to install our environment.
no_add_bashrc=1 # add new target to PATH in .bashrc
minimal=1 # minimal set of packags, eg. omit jupyter notebook installation
while getopts "ht:e:inm" opt; do
case $opt in
n) no_add_bashrc=0;;
m) minimal=0;;
t) target=$OPTARG;;
e) env_name=$OPTARG;;
i) ignore=0;;
h) usage
exit 0;;
*) echo "unknown option/combination"; exit 0;;
esac
done
function add_to_bashrc {
if [ $no_add_bashrc -ne 0 ]; then
return 0
fi
# add path of target to bashrc, if not yet present.
# note: copied from miniconda installer.
BASH_RC="$HOME"/.bashrc
if [ -f "$BASH_RC" ]; then
printf "\\n"
printf "Appending source %s/bin/activate to %s\\n" "$target" "$BASH_RC"
printf "A backup will be made to: %s-miniconda3.bak\\n" "$BASH_RC"
printf "\\n"
cp "$BASH_RC" "${BASH_RC}"-miniconda3.bak
else
printf "\\n"
printf "Appending source %s/bin/activate in\\n" "$target"
printf "newly created %s\\n" "$BASH_RC"
fi
printf "\\n"
printf "For this change to become active, you have to open a new terminal.\\n"
printf "\\n"
printf "\\n" >> "$BASH_RC"
printf "# added by Miniconda3 installer\\n" >> "$BASH_RC"
printf "export PATH=\"%s/bin:\$PATH\"\\n" "$target" >> "$BASH_RC"
}
function install_miniconda {
echo "installing miniconda to ${target}..."
if [ `uname -m` = "x86_64" ]; then
arch="x86_64"
else
arch="x86"
fi
platform=`uname -s`
if [ ${platform} = "Darwin" ]; then
platform="MacOSX"
if [ $arch = "x86" ]; then
echo "ERROR: 32 bit on OSX is not supported by Anaconda, please compile the software yourself."
exit 1
fi
fi
echo "installing miniconda to $target"
f=`mktemp`
# curl should be available on Linux and OSX.
curl https://repo.continuum.io/miniconda/Miniconda3-latest-$platform-$arch.sh -o ${f}
bash ${f} -b -f -p ${target}
export PATH=${target}/bin:$PATH
hash -r
add_to_bashrc
}
function install_pyemma {
# installs pyemma in an env named pyemma
packages="pyemma numpy"
if [ ! minimal ]; then
# add optional packages.
packages="$packages notebook ipython ipywidgets"
fi
# we add numpy here to get the openblas variant (instead of MKL).
echo "creating pyemma environment..."
conda=${target}/bin/conda
if [[ -z $($conda env list | grep ${env_name}) ]]; then
echo "env '$env_name' does not exist. Create new one."
$conda create -n ${env_name} ${packages} -y -c conda-forge
source activate ${env_name}
$conda config --env --add channels conda-forge
echo "execute the following command to activate your newly created pyemma environment:"
echo "> source activate ${env_name}"
else
echo "environment with name='${env_name}' already exists. Please specify a different name by -e new_name"
exit 1
fi
}
# probe for conda, install miniconda otherwise.
if [ -x "$(command -v conda)" ] && [ $ignore -eq 1 ]; then
echo "Found conda. Will install to a new environment named ${env_name}"
install_pyemma
else
if [ -d ${target} ]; then
echo "ERROR: Destination directory for Miniconda $target already exists, please choose another one."
exit 1
else
install_miniconda
install_pyemma
fi
fi