-
Notifications
You must be signed in to change notification settings - Fork 17
/
setup-poppy.sh
415 lines (359 loc) · 14.3 KB
/
setup-poppy.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#!/usr/bin/env bash
# Using a python virtual environment at $HOME/pyenv instead of $HOME/miniconda
# replace all "conda install" by "pip3 install"
creature=$1
hostname=$2
branch=${3:-"master"}
hampy_branch="master"
puppet_master_branch="$branch"
viewer_branch="robot_local"
monitor_branch="master"
snap_version="5.4.5"
export PATH="$HOME/pyenv/bin:$PATH"
# activate the python virtual env for all the script
# shellcheck source=./activate
source "$HOME/pyenv/bin/activate"
print_env()
{
env
}
install_poppy_libraries()
{
pushd /tmp || exit
echo -e "\e[33m install_poppy_libraries: hampy \e[0m"
wget --progress=dot:mega "https://github.com/poppy-project/hampy/archive/${hampy_branch}.zip" -O "hampy-${hampy_branch}.zip"
pip install hampy-${hampy_branch}.zip
echo -e "\e[33m install_poppy_libraries: pypot \e[0m"
wget --progress=dot:mega "https://github.com/poppy-project/pypot/archive/${branch}.zip" -O "pypot-$branch.zip"
pip install "pypot-$branch.zip"
echo -e "\e[33m install_poppy_libraries: $creature \e[0m"
wget --progress=dot:mega "https://github.com/poppy-project/$creature/archive/${branch}.zip" -O "$creature-$branch.zip"
unzip -q "$creature-$branch.zip"
rm -f "$creature-$branch.zip"
pushd "$creature-$branch" || exit
pip install software/
popd || exit
popd || exit
if [ -z "${POPPY_ROOT+x}" ]; then
export POPPY_ROOT="$HOME/dev"
echo "export POPPY_ROOT=$HOME/dev" >> "$HOME/.bashrc"
fi
mkdir -p "$POPPY_ROOT"
# Symlink Poppy Python packages to allow more easily to users to view and modify the code
for repo in pypot $creature ; do
# Replace - to _ (I don't like regex)
module=$(python -c "str = '$repo'; print(str.replace('-','_'))")
module_path=$(python -c "import $module, os; print(os.path.dirname($module.__file__))")
ln -s "$module_path" "$POPPY_ROOT"
done
}
setup_puppet_master()
{
echo -e "\e[33m setup_puppet_master \e[0m"
if [ -z "${POPPY_ROOT+x}" ]; then
export POPPY_ROOT="$HOME/dev"
mkdir -p "$POPPY_ROOT"
fi
pushd "$POPPY_ROOT" || exit
wget --progress=dot:mega "https://github.com/poppy-project/puppet-master/archive/${puppet_master_branch}.zip" -O puppet-master.zip
unzip -q puppet-master.zip
rm -f puppet-master.zip
mv "puppet-master-${puppet_master_branch}" puppet-master
pushd puppet-master || exit
pip install flask pyyaml requests
python bootstrap.py "$hostname" "$creature" "--branch" "${branch}"
popd || exit
download_documentation
download_viewer
download_monitor
download_snap
download_scratch
popd || exit
}
# Called from setup_puppet_master()
download_monitor()
{
echo -e "\e[33m setup_puppet_master: download_monitor \e[0m"
wget --progress=dot:mega "https://github.com/poppy-project/poppy-monitor/archive/${monitor_branch}.zip" -O monitor.zip
unzip -q monitor.zip
rm -f monitor.zip
mv "poppy-monitor-${monitor_branch}" poppy-monitor
}
# Called from setup_puppet_master()
download_viewer()
{
echo -e "\e[33m setup_puppet_master: download_viewer \e[0m"
wget --progress=dot:mega "https://github.com/poppy-project/poppy-simu/archive/${viewer_branch}.zip" -O viewer.zip
unzip -q viewer.zip
rm -f viewer.zip
mv "poppy-simu-${viewer_branch}" poppy-viewer
}
# Called from setup_puppet_master()
download_snap()
{
echo -e "\e[33m setup_puppet_master: download_snap \e[0m"
wget --progress=dot:mega "https://github.com/jmoenig/Snap/archive/v${snap_version}.zip" -O snap.zip
unzip -q snap.zip
rm -f snap.zip
mv "Snap-${snap_version}" snap
#pypot_root=$(python -c "import pypot, os; print(os.path.dirname(pypot.__file__))")
pypot_root="$POPPY_ROOT/pypot"
# Delete snap default examples
rm -rf snap/Examples/EXAMPLES
# Snap projects are dynamically modified and copied on a local folder for access rights issues
# This snap_local_folder is defined depending the OS in pypot.server.snap.get_snap_user_projects_directory()
snap_local_folder="$HOME/.local/share/pypot"
mkdir -p "$snap_local_folder"
# Link pypot Snap projets to Snap! Examples folder
for project in "$pypot_root/server/snap_projects"/*.xml; do
# Local file doesn"t exist yet if SnapRobotServer has not been started
filename=$(basename "$project")
cp "$project" "$snap_local_folder/"
ln -s "$snap_local_folder/$filename" snap/Examples/
echo -e "$filename\t$filename" >> snap/Examples/EXAMPLES
done
ln -s "$snap_local_folder/pypot-snap-blocks.xml" snap/libraries/poppy.xml
echo -e "poppy.xml\tPoppy robots" >> snap/libraries/LIBRARIES
}
# Called from setup_puppet_master()
download_scratch()
{
echo -e "\e[33m setup_puppet_master: download_scratch \e[0m"
wget --progress=dot:mega "https://github.com/poppy-project/scratch-poppy/releases/latest/download/scratch-application.zip" -O scratch.zip
unzip -q scratch.zip
rm -f scratch.zip
mv "scratch-application" "scratch"
cat scratch/build-version.txt
}
# Called from setup_puppet_master()
download_documentation()
{
echo -e "\e[33m setup_puppet_master: download_documentation \e[0m"
version=$(curl --silent https://github.com/poppy-project/poppy-docs/releases/latest | sed 's#.*tag/\(.*\)\".*#\1#')
wget --progress=dot:mega "https://github.com/poppy-project/poppy-docs/releases/download/${version}/_book.zip" -O _book.zip
unzip -q _book.zip
rm -rf _book.zip
mv _book poppy-docs
ln -s "$(realpath .)/poppy-docs/en/assembly-guides/ergo-jr" poppy-docs/en/assembly-guides/poppy-ergo-jr
ln -s "$(realpath .)/poppy-docs/fr/assembly-guides/ergo-jr" poppy-docs/fr/assembly-guides/poppy-ergo-jr
rm -r "poppy-docs/es" "poppy-docs/de" "poppy-docs/nl"
}
setup_documents()
{
echo -e "\e[33m setup_documents \e[0m"
if [ -z "${JUPYTER_FOLDER+x}" ]; then
JUPYTER_FOLDER="$HOME/Jupyter_root"
mkdir -p "$JUPYTER_FOLDER"
fi
mkdir -p "$JUPYTER_FOLDER/My Documents"
pushd "$JUPYTER_FOLDER/My Documents" || exit
echo -e "create symlink"
ln -s "$POPPY_ROOT" Poppy\ Source-code
#ln -s "$POPPY_ROOT/poppy-docs/La Documentation.pdf" La\ Documentation.pdf
#ln -s "$POPPY_ROOT/poppy-docs/The Documentation.pdf" The\ Documentation.pdf
mkdir -p "$POPPY_ROOT/puppet-master/moves"
sed -i 's/self.moves_path=""/self.moves_path="moves\/"/' "$POPPY_ROOT/pypot/server/rest.py"
sed -i 's/#os.makedirs(self.moves_path/os.makedirs(self.moves_path/g' "$POPPY_ROOT/pypot/server/rest.py"
ln -s "$POPPY_ROOT/puppet-master/moves" Moves\ recorded
name=$(python -c "str = '$creature'; print(str.replace('-','_'))")
ln -s "$POPPY_ROOT/$name/primitives" Robot\ primitives
pushd Robot\ primitives || exit
ln -s "$POPPY_ROOT/$name/$name.py" _shortcut_to_Robot_init.py
popd || exit
mkdir -p "$POPPY_ROOT/puppet-master/pictures"
sed -i 's/cv2.imwrite(\"{}.png\"/cv2.imwrite(\"pictures\/{}.png\"/' "$POPPY_ROOT/pypot/server/snap.py"
sed -i 's/#os.makedirs(\"pictures_path\"/os.makedirs(\"pictures\"/' "$POPPY_ROOT/pypot/server/snap.py"
ln -s "$POPPY_ROOT/puppet-master/pictures" My\ Pictures
echo -e "symlink done"
get_snap_project "Snap project"
get_notebooks "Python notebooks"
popd || exit
}
# Called from setup_documents()
get_snap_project()
{
echo -e "\e[33m setup_documents: get_snap_project \e[0m"
mkdir -p "$1"
pushd "$1" || exit
ln -s "$POPPY_ROOT/snap/help/SnapManual.pdf" Snap\ Documentation.pdf
ln -s "$POPPY_ROOT/snap/Examples" Snap\ codes
mkdir -p Snap\ activities
if [ "$creature" == "poppy-ergo-jr" ]; then
pushd Snap\ activities || exit
wget --progress=dot:mega https://hal.inria.fr/hal-01384649/document -O Livret\ pédagogique.pdf
#TODO make online repo with all activities and download here
popd || exit
fi
popd || exit
}
# Called from setup_documents()
get_notebooks()
{
echo -e "\e[33m setup_documents: get_notebooks \e[0m"
mkdir -p "$1"
pushd "$1" || exit
if [ "$creature" == "poppy-humanoid" ]; then
repo=https://raw.githubusercontent.com/poppy-project/$creature/$branch
curl -o "Motion demonstration.ipynb" "$repo/software/samples/notebooks/Demo%20Interface.ipynb"
curl -o "Discover your Poppy Humanoid.ipynb" "$repo/software/samples/notebooks/Discover%20your%20Poppy%20Humanoid.ipynb"
curl -o "Record, save and play moves on Poppy Humanoid.ipynb" "$repo/software/samples/notebooks/Record%2C%20Save%20and%20Play%20Moves%20on%20Poppy%20Humanoid.ipynb"
elif [ "$creature" == "poppy-torso" ]; then
repo=https://raw.githubusercontent.com/poppy-project/$creature/$branch/software/samples/notebooks
curl -o "Discover your Poppy Torso.ipynb" "$repo/Discover%20your%20Poppy%20Torso.ipynb"
curl -o "Record, save and play moves on Poppy Torso.ipynb" "$repo/Record%2C%20Save%20and%20Play%20Moves%20on%20Poppy%20Torso.ipynb"
mkdir -p images
pushd images || exit
wget "$repo/images/poppy_torso.jpg" -O poppy_torso.jpg
wget "$repo/images/poppy_torso_motors.png" -O poppy_torso_motors.png
popd || exit
elif [ "$creature" == "poppy-ergo-jr" ]; then
repo=https://raw.githubusercontent.com/poppy-project/$creature/$branch/software/samples/notebooks
curl -o "Discover your Poppy Ergo Jr.ipynb" "$repo/Discover%20your%20Poppy%20Ergo%20Jr.ipynb"
curl -o "Record, save and play moves on Poppy Ergo Jr.ipynb" "$repo/Record%2C%20Save%20and%20Play%20Moves%20on%20Poppy%20Ergo%20Jr.ipynb"
fi
repo=https://raw.githubusercontent.com/poppy-project/pypot/$branch/samples/notebooks
curl -o "Benchmark your Poppy robot.ipynb" "$repo/Benchmark%20your%20Poppy%20robot.ipynb"
curl -o "Another language.ipynb" "$repo/Another%20language.ipynb"
# Download community notebooks
wget --progress=dot:mega https://github.com/poppy-project/community-notebooks/archive/master.zip -O notebooks.zip
unzip -q notebooks.zip
rm -f notebooks.zip
mv community-notebooks-master community-notebooks
popd || exit
}
setup_services()
{
autostartup_webinterface
autostartup_documentation
autostartup_viewer
}
# Called from setup_service()
autostartup_webinterface()
{
echo -e "\e[33m autostartup_webinterface \e[0m"
cd || exit
if [ -z "${POPPY_ROOT+x}" ]; then
export POPPY_ROOT="$HOME/dev"
mkdir -p "$POPPY_ROOT"
fi
sudo tee /etc/systemd/system/puppet-master.service > /dev/null <<EOF
[Unit]
Description=Puppet Master service
Wants=network-online.target
After=network.target network-online.target
[Service]
PIDFile=/run/puppet-master.pid
Environment="PATH=$PATH"
ExecStart=$HOME/pyenv/bin/python bouteillederouge.py
User=poppy
Group=poppy
WorkingDirectory=$POPPY_ROOT/puppet-master
Type=simple
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable puppet-master.service
}
# Called from setup_service()
autostartup_documentation()
{
echo -e "\e[33m autostartup_documentation \e[0m"
cd || exit
if [ -z "${POPPY_ROOT+x}" ]; then
export POPPY_ROOT="$HOME/dev"
mkdir -p "$POPPY_ROOT"
fi
sudo tee /etc/systemd/system/poppy-docs.service > /dev/null <<EOF
[Unit]
Description=poppy docs service
Wants=network-online.target
After=network.target network-online.target
[Service]
PIDFile=/run/poppy-docs.pid
ExecStart=$HOME/pyenv/bin/python -u -m http.server 4000
User=poppy
Group=poppy
WorkingDirectory=$POPPY_ROOT/poppy-docs/
Type=simple
StandardOutput=append:/tmp/poppy-docs.log
StandardError=append:/tmp/poppy-docs.log
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable poppy-docs.service
}
# Called from setup_service()
autostartup_viewer()
{
echo -e "\e[33m autostartup_viewer \e[0m"
cd || exit
if [ -z "${POPPY_ROOT+x}" ]; then
export POPPY_ROOT="$HOME/dev"
mkdir -p "$POPPY_ROOT"
fi
sudo tee /etc/systemd/system/poppy-viewer.service > /dev/null <<EOF
[Unit]
Description=poppy viewer service
Wants=network-online.target
After=network.target network-online.target
[Service]
PIDFile=/run/poppy-viewer.pid
ExecStart=$HOME/pyenv/bin/python -u -m http.server 8000
User=poppy
Group=poppy
WorkingDirectory=$POPPY_ROOT/poppy-viewer/
Type=simple
StandardOutput=append:/tmp/poppy-viewer.log
StandardError=append:/tmp/poppy-viewer.log
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable poppy-viewer.service
}
redirect_port80_webinterface()
{
echo -e "\e[33m redirect_port80_webinterface \e[0m"
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 2280
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
sudo apt-get install -y iptables-persistent
sudo bash -c 'iptables-save > /etc/iptables/rules.v4'
sudo bash -c 'ip6tables-save > /etc/iptables/rules.v6'
}
setup_update()
{
echo -e "\e[33m setup_update \e[0m"
cd || exit
wget "https://raw.githubusercontent.com/poppy-project/raspoppy/$branch/poppy-update.sh" -O "$HOME/.poppy-update.sh"
cat > poppy-update << EOF
#!/$HOME/pyenv/bin/python
import os
import yaml
from subprocess import call
with open(os.path.expanduser('~/.poppy_config.yaml')) as f:
config = yaml.load(f, Loader=yaml.SafeLoader)
with open(config['poppyLog']['update'], 'w') as f:
call(['bash', os.path.expanduser('~/.poppy-update.sh'),
config['info']['updateURL'],
config['poppyLog']['update'],
config['poppyLog']['update'].replace('.log','-pid.lock')],
stdout=f, stderr=f)
EOF
chmod +x poppy-update
mv poppy-update "$HOME/pyenv/bin/"
}
set_logo()
{
echo -e "\e[33m set_logo \e[0m"
wget https://raw.githubusercontent.com/poppy-project/raspoppy/master/poppy_logo -O "$HOME/.poppy_logo"
# Remove old occurrences of poppy_logo in .bashrc
sed -i /poppy_logo/d "$HOME/.bashrc"
echo cat "$HOME/.poppy_logo" >> "$HOME/.bashrc"
}
install_poppy_libraries
setup_puppet_master
setup_documents
setup_services
redirect_port80_webinterface
setup_update
set_logo