forked from poppy-project/raspoppy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-python.sh
executable file
·97 lines (78 loc) · 2.39 KB
/
setup-python.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
#!/usr/bin/env bash
install_conda()
{
cd || exit
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-armv7l.sh -O Miniconda-latest-Linux-armv7l.sh
bash Miniconda-latest-Linux-armv7l.sh -b
rm Miniconda-latest-Linux-armv7l.sh
echo "export PATH=$HOME/miniconda/bin:$PATH" >> "$HOME/.bashrc"
export PATH="$HOME/miniconda/bin:$PATH"
conda config --add channels rpi
conda config --add channels poppy-project
conda config --set show_channel_urls True
conda config --set always_yes yes --set changeps1 no
conda update conda
}
install_python_packages()
{
conda install numpy scipy jupyter matplotlib explauto
}
configure_jupyter()
{
JUPYTER_CONFIG_FILE=$HOME/.jupyter/jupyter_notebook_config.py
export JUPTER_NOTEBOOK_FOLDER=$HOME/notebooks
mkdir -p "$JUPTER_NOTEBOOK_FOLDER"
jupyter notebook --generate-config --y
cat >> "$JUPYTER_CONFIG_FILE" <<EOF
# --- Poppy configuration ---
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.notebook_dir = '$JUPTER_NOTEBOOK_FOLDER'
c.NotebookApp.tornado_settings = {'headers': {'Content-Security-Policy': "frame-ancestors 'self' *"}}
c.NotebookApp.allow_origin = '*'
c.NotebookApp.extra_static_paths = ["static/custom/custom.js"]
c.NotebookApp.token = ''
c.NotebookApp.password = ''
# --- Poppy configuration ---
EOF
JUPYTER_CUSTOM_JS_FILE=$HOME/.jupyter/custom/custom.js
mkdir -p "$HOME/.jupyter/custom"
cat > "$JUPYTER_CUSTOM_JS_FILE" <<EOF
/* Allow new tab to be openned in an iframe */
define(['base/js/namespace'], function(Jupyter){
Jupyter._target = '_self';
})
EOF
python -c """
import os
from jupyter_core.paths import jupyter_data_dir
d = jupyter_data_dir()
if not os.path.exists(d):
os.makedirs(d)
"""
pip install https://github.com/ipython-contrib/IPython-notebook-extensions/archive/master.zip
}
autostart_jupyter()
{
sudo tee /etc/systemd/system/jupyter-notebook.service > /dev/null <<EOF
[Unit]
Description=Jupyter notebook
Wants=network-online.target
After=network.target network-online.target
[Service]
PIDFile=/var/run/jupyter-notebook.pid
Environment="PATH=$PATH"
ExecStart=$HOME/miniconda/bin/jupyter notebook
User=poppy
Group=poppy
WorkingDirectory=$JUPTER_NOTEBOOK_FOLDER
Type=simple
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable jupyter-notebook.service
}
install_conda
install_python_packages
configure_jupyter
autostart_jupyter