-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-notebook.sh
executable file
·62 lines (50 loc) · 1.83 KB
/
start-notebook.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
#!/bin/bash
set -e
# Since the name of the volume is escaped wrongly, we have to wrongly escape the
# usename elsewhere as well.
# https://github.com/jupyterhub/kubespawner/pull/309
REAL_JUPYTERHUB_USER=$JUPYTERHUB_USER
if [ -n "$JUPYTERHUB_USER" ]; then
JUPYTERHUB_USER=$(python /usr/local/bin/normalize-username.py $JUPYTERHUB_USER)
fi
HOME=$(eval echo "$HOME")
JUPYTERHUB_USER=$REAL_JUPYTERHUB_USER # Swich back after expanding, as Jupyterhub breaks otherwise.
mkdir -p "$HOME"
mv /home/notebook /home/oldnotebook
ln -s "$HOME" /home/notebook
# Exec the specified command or fall back on bash
if [ $# -eq 0 ]; then
cmd=bash
else
cmd=$*
fi
if [ ! -d "$HOME/.jupyter" ]; then
cp -r "/opt/.jupyter" "$HOME/.jupyter"
fi
if [ -f "/tmp/ipcontroller-client.json" ]; then
mkdir -p "$HOME/.ipython/profile_default/security/"
ls -lah "$HOME/.ipython/profile_default/security/"
cp "/tmp/ipcontroller-client.json" "$HOME/.ipython/profile_default/security/" || true
fi
if [ ! -f "$HOME/.jupyter/notebook_config.py" ]; then
cp -r "/opt/.jupyter/notebook_config.py" "$HOME/.jupyter"
fi
# If we have shared data directories mounted, make the folders available in the users home directory.
if [ -d "/mnt" ]; then
for dir in /mnt/*/; do
if [ -d "$dir" ]; then
dirname=${dir%*/} # remove the trailing "/"
dirname=${dirname##*/} # everything after the final "/"
if [ -L "$HOME/shared-$dirname" ]; then
rm -f "$HOME/shared-$dirname"
fi
ln -sf "/mnt/$dirname" "$HOME/shared-$dirname"
fi
done
fi
cd "$HOME"
if [[ ! -z "${JUPYTER_ENABLE_LAB}" ]]; then
jupyterhub-singleuser --LabApp.dev_mode=True --config "$HOME/.jupyter/notebook_config.py" --SingleUserNotebookApp.default_url="/lab"
else
jupyterhub-singleuser --LabApp.dev_mode=True --config "$HOME/.jupyter/notebook_config.py"
fi