-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall_script.sh
executable file
·195 lines (166 loc) · 5.59 KB
/
install_script.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
#!/usr/bin/env bash
# References
# http://kvz.io/blog/2013/11/21/bash-best-practices/
# http://jvns.ca/blog/2017/03/26/bash-quirks/
# default logfile name
FILENAME="jupyter-vcdat_logfile.txt"
# dev conda channels to use
DEV_CHANNELS="-c cdat/label/v8.2.1 -c conda-forge"
# user conda channels (stable)
USER_CHANNELS="-c cdat/label/v8.2.1 -c conda-forge"
# choose base packages based on OS
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
BASE_CONDA_PKGS="pip cdms2 vcs tqdm nodejs 'python=3.7' jupyterlab jupyterhub ipywidgets numpy 'mesalib=18.3.1'"
elif [[ "$OSTYPE" == "darwin"* ]]; then
BASE_CONDA_PKGS="pip cdms2 vcs tqdm nodejs 'python=3.7' jupyterlab jupyterhub ipywidgets numpy 'mesalib=17.3.9'"
fi
# dev and test packages
DEV_CONDA_PKGS="testsrunner cdat_info"
# default env name
REQUESTED_ENV_NAME="jupyter-vcdat"
# NOT VERBOSE by default
VERBOSE=0
# installation mode (USER or DEV)
INSTALL_MODE="USER"
# conda channels to use
CONDA_CHANNELS="$USER_CHANNELS"
CONDA_PACKAGES=$BASE_CONDA_PKGS
function usage() {
cat <<EOF
usage: Install vcdat jupyter-lab extension
optional arguments:
-h, --help
show this help message and exit
-f FILENAME, --FILENAME FILENAME
name of file where to log output
-v VERBOSE
Also prints output to screen
-d DEVELOPER
Installs developer version with developer tools
-n CONDA_ENV_NAME, --name CONDA_ENV_NAME
Name of the conda environment to install in (will create if not existing)
EOF
exit 0
}
# Figure out command line arguments: http://linuxcommand.org/lc3_wss0120.php
while [ "$1" != "" ]; do
case $1 in
-f | --file)
shift
FILENAME=$1
;;
-v | --VERBOSE)
VERBOSE=1
;;
-n | --name)
shift
REQUESTED_ENV_NAME=$1
;;
-d | --dev)
INSTALL_MODE="DEV"
;;
-h | --help)
usage
;;
*)
usage
exit 1
;;
esac
shift
done
echo "Installing jupyter-vcdat extension in conda env: '${REQUESTED_ENV_NAME}' (you can change this via -c option)"
# Choose conda channels and packages based on installion mode
if [ $INSTALL_MODE == "DEV" ]; then
CONDA_CHANNELS="$DEV_CHANNELS $BASE_CHANNELS"
CONDA_PACKAGES="$BASE_CONDA_PKGS $DEV_CONDA_PKGS"
fi
echo "Using following conda channels: '${CONDA_CHANNELS}'"
echo "Output will be redirected to: '$FILENAME' (you can control the FILENAME with -f option)"
# Redirect to logfile and possibly screen if verbose
if [ $VERBOSE == 1 ]; then
# Redirect stdout ( > ) into a named pipe ( >() ) running "tee"
exec > >(tee -i $FILENAME)
else
echo "Going into quiet mode, suppressing output"
echo "For verbose mode run with -v option"
# https://stackoverflow.com/questions/637827/redirect-stderr-and-stdout-in-bash
# Close STDOUT file descriptor
exec 1<&-
# Close STDERR FD
exec 2<&-
# Open STDOUT as $LOG_FILE file for read and write.
exec 1<>$FILENAME
fi
# Without this, only stdout would be captured - i.e. your
# log file would not contain any error messages.
exec 2>&1
# exit when a command fails
set -o errexit
# exit if any pipe commands fail
set -o pipefail
set -E
set -o functrace
function handle_error() {
local retval=$?
local line=${last_lineno:-$1}
echo "Failed at $line: $BASH_COMMAND"
echo "Trace: " "$@"
echo "return code: " "$?"
exit $retval
}
trap 'handle_error $LINENO ${BASH_LINENO[@]}' ERR
CONDA_EXE="$(which conda)"
# Activate requested conda environment
if [ ${CONDA_DEFAULT_ENV:-"NA"} != ${REQUESTED_ENV_NAME} ]; then
echo "Current conda does not match requested conda: ${CONDA_DEFAULT_ENV:-'NA'} vs ${REQUESTED_ENV_NAME}"
envs=$(${CONDA_EXE} env list | cut -d ' ' -f1)
found=0
for a_env in $envs; do
if [ $a_env == ${REQUESTED_ENV_NAME} ]; then
found=1
fi
done
if [ $found == 1 ]; then
echo "ACTIVATING existing env: ${REQUESTED_ENV_NAME}"
conda activate ${REQUESTED_ENV_NAME}
else
echo "The requested env ${REQUESTED_ENV_NAME} does not seem to exist we will create it."
fi
fi
if [ ${CONDA_DEFAULT_ENV:-"NA"} != ${REQUESTED_ENV_NAME} ]; then
# If requested conda environment doesn't exist, create it
echo "Creating conda env: ${REQUESTED_ENV_NAME}"
conda config --set channel_priority strict
echo "conda create -y -n ${REQUESTED_ENV_NAME} $CONDA_CHANNELS $CONDA_PACKAGES"
conda create -y -n ${REQUESTED_ENV_NAME} $CONDA_CHANNELS $CONDA_PACKAGES
CONDA_BASE=$(conda info --base)
source $CONDA_BASE/etc/profile.d/conda.sh
conda activate ${REQUESTED_ENV_NAME}
else
# Install required conda packages into existing environment
echo "Installing conda packages in environment: ${REQUESTED_ENV_NAME}"
conda config --set channel_priority strict
echo "conda install -y $CONDA_CHANNELS $CONDA_PACKAGES"
conda create -y $CONDA_CHANNELS $CONDA_PACKAGES
fi
# Install sidecar
python -m pip install sidecar || pip install sidecar
# Install dev packages if needed
if [ $INSTALL_MODE == "DEV" ]; then
python -m pip install flake8 || pip install flake8
python -m pip install selenium || pip install selenium
python -m pip install pyvirtualdisplay || pip install pyvirtualdisplay
fi
# Install extensions
jupyter labextension install @jupyter-widgets/jupyterlab-manager --no-build
jupyter labextension install @jupyter-widgets/jupyterlab-sidecar --no-build
jupyter labextension install jupyterlab-tutorial-extension --no-build
jupyter labextension install @jupyterlab/hub-extension --no-build
# Install jupyter-vcdat extension
npm install
jupyter lab build
jupyter labextension install .
# Success message
echo Jupyter VCDAT has been successfully installed!
echo "To run: conda activate ${REQUESTED_ENV_NAME} && jupyter lab"