forked from jupyter/nbgrader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestart_demo.sh
More file actions
executable file
·117 lines (92 loc) · 3.17 KB
/
restart_demo.sh
File metadata and controls
executable file
·117 lines (92 loc) · 3.17 KB
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
#!/usr/bin/env bash
set -ex
NODE_MAJOR_VERSION=`node --version | cut -d'.' -f 1 | cut -d'v' -f 2`
test_node_version () {
MAJOR_VERSION_RE='^[0-9]+$'
# checks if a version exists
if ! [[ $1 =~ $MAJOR_VERSION_RE ]] ; then
echo "Nodejs seems not installed. This requires nodejs>=14 to continue" >&2; exit 1
fi
# checks if the version is 14 or more
if [ $1 -lt 14 ]; then
echo "Nodejs version must be 14 or more, current is $1">&2; exit 1
fi
}
test_node_version ${NODE_MAJOR_VERSION}
# Configuration variables.
root="$(realpath `dirname $0`)"
srv_root="/srv/nbgrader"
nbgrader_root="/srv/nbgrader/nbgrader"
jupyterhub_root="/srv/nbgrader/jupyterhub"
exchange_root="/usr/local/share/nbgrader/exchange"
# List of possible users, used across all demos.
possible_users=(
'instructor1'
'instructor2'
'grader-course101'
'grader-course123'
'student1'
)
# Import helper functions.
source utils.sh
install_dependencies () {
echo "Installing dependencies..."
apt install -y npm
npm install -g configurable-http-proxy
apt install -y python3-pip
pip3 install -U jupyterlab
pip3 install -U jupyterhub
}
install_nbgrader () {
local nbgrader_root="${1}"
local exchange_root="${2}"
echo "Installing nbgrader in '${nbgrader_root}'..."
# Clone nbgrader.
if [ ! -d "${nbgrader_root}" ]; then
mkdir "${nbgrader_root}"
cd "${nbgrader_root}"
git clone https://github.com/jupyter/nbgrader .
fi
# Update git repository.
cd "${nbgrader_root}"
git pull
# Install requirements and nbgrader.
pip3 install -e ".[dev,docs,tests]"
# Install global extensions, and disable them globally. We will re-enable
# specific ones for different user accounts in each demo.
jupyter labextension develop --overwrite .
jupyter labextension disable --level=sys_prefix nbgrader:assignment-list
jupyter labextension disable --level=sys_prefix nbgrader:formgrader
jupyter labextension disable --level=sys_prefix nbgrader:course-list
jupyter labextension disable --level=sys_prefix nbgrader:create-assignment
jupyter server extension disable --sys-prefix --py nbgrader
# Everybody gets the validate extension, however.
jupyter labextension enable --level=sys_prefix nbgrader:validate-assignment
jupyter server extension enable --sys-prefix nbgrader.server_extensions.validate_assignment
# Reset exchange.
rm -rf "${exchange_root}"
setup_directory "${exchange_root}" ugo+rwx
# Remove global nbgrader configuration, if it exists.
rm -f /etc/jupyter/nbgrader_config.py
}
restart_demo () {
local demo="${1}"
test ! -z "$demo"
install_dependencies
setup_directory "/etc/jupyter" ugo+r
setup_directory "${srv_root}" ugo+r
install_nbgrader "${nbgrader_root}" "${exchange_root}"
# Delete existing user accounts.
for user in ${possible_users[@]}; do
remove_user "${user}"
done
# Setup the specific demo.
echo "Setting up demo '${demo}'..."
cd "${root}/${demo}"
source setup_demo.sh
setup_demo "${jupyterhub_root}"
# Run JupyterHub.
cd "${jupyterhub_root}"
jupyterhub
}
restart_demo "${@}"