-
Notifications
You must be signed in to change notification settings - Fork 7
/
setup_miniconda.sh
executable file
·227 lines (197 loc) · 8.09 KB
/
setup_miniconda.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
#!/bin/sh -x
## setup_miniconda.sh
# http://conda.pydata.org/miniconda.html
# http://repo.continuum.io/miniconda/
DOWNLOAD_DEST="."
REPO_URL_PREFIX="https://repo.continuum.io/miniconda"
linux_x86=Miniconda3-latest-Linux-x86.sh
linux_x86_64=Miniconda3-latest-Linux-x86_64.sh
osx_x86_64=Miniconda3-latest-MacOSX-x86_64.sh
#win_x86=Miniconda3-latest-Windows-x86.exe
#win_x86_64=Miniconda3-latest-Windows-x86_64.exe
function miniconda_get_download_filename {
# miniconda_get_download_filename() -- get a miniconda installer filename
# $1 (str) -- versionstr to append (3 or "")
local verstr="${1}"
local _uname=$(uname)
local _uname_m=$(uname -m) # x86_64, i686
if [ "${_uname}" == "Darwin" ]; then
local _filename="Miniconda${verstr}-latest-MacOSX-${_uname_m}.sh"
elif [ "${_uname}" == "Linux" ]; then
if [ "${_uname_m}" == "i686" ]; then
_uname_m="x86"
fi
local _filename="Miniconda${verstr}-latest-Linux-${_uname_m}.sh"
else
echo "Err: uname '${_uname}' not implemented" >&2
return 2
fi
echo "${_filename}"
return 0
}
function miniconda_download {
# miniconda_download() -- download the latest miniconda installer
# $1 (str) -- versionstr to append (3 or "")
# $2 (str) -- destination directory in which to store downloaded files
# Returns:
# 1: -- download err
# 0: -- download OK
local verstr="${1}"
local destdir="${2:-"${DOWNLOAD_DEST}"}"
local filename=$(miniconda_get_download_filename "${verstr}")
local download_url="${REPO_URL_PREFIX}/${filename}"
local dest="${destdir}/${filename}"
echo "Downloading: ${download_url}" >&2
echo "Dest: ${dest}" >&2
# TODO:
if [ -n "${SKIP_DOWNLOAD}" ]; then
echo "${dest}";
return 1
fi
(curl -SL "${download_url}" > "${dest}") 1>&2 >&2 \
&& echo "${dest}" \
&& return 0
return 1
}
function miniconda_install {
# miniconda_install() -- run the miniconda installer for the
# $1 (str) -- path to miniconda installer .sh
# $2 (str) -- install dest (default: ~/miniconda; __WRK/-conda[27|34])
# Returns:
# n: Miniconda[3]-latest-*.sh return code
local miniconda_installer_sh="${1}"
local prefix="${2:-"${HOME}/miniconda"}"
shift
shift
sh ${miniconda_installer_sh} -b -p "${prefix}" "${@}"
}
###
function _miniconda_check_conda_env {
# miniconda_check_conda_env -- check python and conda in a conda env
# $1 (str) -- path of a conda env
# "./here"
# "${CONDA_ENVS_PATH}/envname"
local env="${1}"
if [ -z "${env}" ]; then
return 2
fi
test -d "${env}"
local python="${env}/bin/python"
test -x "${python}"
"${python}" --version
"${python}" -m site
local conda="${env}/bin/conda"
test -x "${conda}"
"${conda}" --version
"${conda}" info
local pip="${env}/bin/pip"
test -x "${pip}"
"${pip}" --version
#"${pip}" show pip
}
function miniconda_check_conda_env {
(set -x; _miniconda_check_conda_env "${@}")
}
function miniconda_setup__dotfiles_minicondas {
# miniconda_setup__dotfiles_minicondas -- install CONDA_ROOTs
# $1 (str) -- path for CONDA_ROOTs and CONDA_ENVSs (default: $__WRK)
# Returns:
# n: sum of Miniconda[3]-latest-*.sh return codes
local prefix="${1:-"${__WRK}"}"
local CONDA_ROOT__py27="${CONDA_ROOT__py27:-"${prefix}/-conda27"}"
local CONDA_ROOT__py37="${CONDA_ROOT__py37:-"${prefix}/-conda37"}"
local CONDA_ROOT__py38="${CONDA_ROOT__py38:-"${prefix}/-conda38"}"
local mc2=$(miniconda_download 2)
echo $mc2
local mc3=$(miniconda_download 3)
echo $mc3
local ret=0;
if [ -n "${CONDA_ROOT__py27}" ]; then
miniconda_install "${mc2}" "${CONDA_ROOT__py27}"
ret=$(expr $ret + $?);
fi
if [ -n "${CONDA_ROOT__py34}" ]; then
miniconda_install "${mc3}" "${CONDA_ROOT__py34}"
ret=$(expr $ret + $?);
fi
if [ -n "${CONDA_ROOT__py35}" ]; then
miniconda_install "${mc3}" "${CONDA_ROOT__py35}"
ret=$(expr $ret + $?);
fi
if [ -n "${CONDA_ROOT__py36}" ]; then
miniconda_install "${mc3}" "${CONDA_ROOT__py36}"
ret=$(expr $ret + $?);
fi
if [ -n "${CONDA_ROOT__py37}" ]; then
miniconda_install "${mc3}" "${CONDA_ROOT__py37}"
ret=$(expr $ret + $?);
fi
if [ -n "${CONDA_ROOT__py38}" ]; then
miniconda_install "${mc3}" "${CONDA_ROOT__py38}"
ret=$(expr $ret + $?);
fi
return $ret;
}
function miniconda_setup__dotfiles_env {
declare -g CONDA_ROOT__py27="${CONDA_ROOT__py27:-"${prefix}/-conda27"}"
declare -g CONDA_ENVS__py27="${CONDA_ENVS__py27:-"${prefix}/-ce27"}"
declare -g CONDA_ROOT__py34="${CONDA_ROOT__py34:-"${prefix}/-conda34"}"
declare -g CONDA_ENVS__py34="${CONDA_ENVS__py34:-"${prefix}/-ce34"}"
declare -g CONDA_ROOT__py35="${CONDA_ROOT__py35:-"${prefix}/-conda35"}"
declare -g CONDA_ENVS__py35="${CONDA_ENVS__py35:-"${prefix}/-ce35"}"
declare -g CONDA_ROOT__py36="${CONDA_ROOT__py36:-"${prefix}/-conda36"}"
declare -g CONDA_ENVS__py36="${CONDA_ENVS__py36:-"${prefix}/-ce36"}"
declare -g CONDA_ROOT__py37="${CONDA_ROOT__py37:-"${prefix}/-conda37"}"
declare -g CONDA_ENVS__py37="${CONDA_ENVS__py37:-"${prefix}/-ce37"}"
declare -g CONDA_ROOT__py38="${CONDA_ROOT__py38:-"${prefix}/-conda38"}"
declare -g CONDA_ENVS__py38="${CONDA_ENVS__py38:-"${prefix}/-ce38"}"
}
function miniconda_setup__dotfiles_condaenvs {
local prefix="${1:-"${__WRK}"}"
miniconda_setup__dotfiles_env
local envname="dotfiles"
# local baseenvname="root"
local baseenvname="base"
## create a condaenv for each python version
# create a dotfiles condaenv for each python version
CONDA_ROOT=$CONDA_ROOT__py27
CONDA_ENVS_PATH=$CONDA_ENVS__py27
"${CONDA_ROOT__py27}/bin/conda" install -y -n "${baseenvname}" conda-env python=2.7 pip readline
test -d "${CONDA_ENVS__py27}/${envname}" || "${CONDA_ROOT__py27}/bin/conda" create -y -n "${envname}"
miniconda_check_conda_env "${CONDA_ENVS__py27}/${envname}"
CONDA_ROOT=$CONDA_ROOT__py34
CONDA_ENVS_PATH=$CONDA_ENVS__py34
"${CONDA_ROOT__py34}/bin/conda" install -y -n "${baseenvname}" conda-env python=3.4 pip readline
test -d "${CONDA_ENVS__py34}/${envname}" || "${CONDA_ROOT__py34}/bin/conda" create -y -n "${envname}"
miniconda_check_conda_env "${CONDA_ENVS__py34}/${envname}"
CONDA_ROOT=$CONDA_ROOT__py35
CONDA_ENVS_PATH=$CONDA_ENVS__py35
"${CONDA_ROOT__py35}/bin/conda" install -y -n "${baseenvname}" conda-env python=3.5 pip readline
test -d "${CONDA_ENVS__py35}/${envname}" || "${CONDA_ROOT__py35}/bin/conda" create -y -n "${envname}"
miniconda_check_conda_env "${CONDA_ENVS__py35}/${envname}"
CONDA_ROOT=$CONDA_ROOT__py36
CONDA_ENVS_PATH=$CONDA_ENVS__py36
"${CONDA_ROOT__py36}/bin/conda" install -y -n "${baseenvname}" conda-env python=3.6 pip readline
test -d "${CONDA_ENVS__py36}/${envname}" || "${CONDA_ROOT__py36}/bin/conda" create -y -n "${envname}"
miniconda_check_conda_env "${CONDA_ENVS__py36}/${envname}"
CONDA_ROOT=$CONDA_ROOT__py37
CONDA_ENVS_PATH=$CONDA_ENVS__py37
"${CONDA_ROOT__py37}/bin/conda" install -y -n "${baseenvname}" conda-env python=3.7 pip readline
test -d "${CONDA_ENVS__py37}/${envname}" || "${CONDA_ROOT__py37}/bin/conda" create -y -n "${envname}"
miniconda_check_conda_env "${CONDA_ENVS__py37}/${envname}"
CONDA_ROOT=$CONDA_ROOT__py38
CONDA_ENVS_PATH=$CONDA_ENVS__py38
"${CONDA_ROOT__py38}/bin/conda" install -y -n "${baseenvname}" conda-env python=3.8 pip readline
test -d "${CONDA_ENVS__py38}/${envname}" || "${CONDA_ROOT__py37}/bin/conda" create -y -n "${envname}"
miniconda_check_conda_env "${CONDA_ENVS__py38}/${envname}"
}
function miniconda_setup_main {
## install miniconda and configure condaenvs
miniconda_setup__dotfiles_env
miniconda_setup__dotfiles_minicondas "${@}";
miniconda_setup__dotfiles_condaenvs "${@}";
}
if [ -n "${BASH_SOURCE}" ] && [ "${BASH_SOURCE}" == "${0}" ]; then
miniconda_setup_main "${@}"
exit
fi