-
Notifications
You must be signed in to change notification settings - Fork 25
/
rasqberry-config
executable file
·350 lines (326 loc) · 13.6 KB
/
rasqberry-config
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
#!/bin/sh
# Derived from raspi-config https://github.com/RPi-Distro/raspi-config
# This script is the main menu for all functionalities of the RasQberry.
# Below you will find the different Whiptail menus (GUI).
# Each underlying method can be found in the imported files below.
# Load environment variables
. /home/pi/RasQberry/env-config.sh
# Load external methods
. /home/pi/RasQberry/config/setup.sh
. /home/pi/RasQberry/config/demos.sh
. /home/pi/RasQberry/config/qoffee-maker.sh
. /home/pi/RasQberry/config/getinfo.sh
USER=${SUDO_USER:-$(who -m | awk '{ print $1 }')}
############# CHECK GENERAL INFORMATION ABOUT PI #############
is_pi () {
ARCH=$(dpkg --print-architecture)
if [ "$ARCH" = "armhf" ] || [ "$ARCH" = "arm64" ] ; then
return 0
else
return 1
fi
}
if is_pi ; then
CMDLINE=/boot/cmdline.txt
else
CMDLINE=/proc/cmdline
fi
# Everything else needs to be run as root
if [ "$(id -u)" -ne 0 ]; then
printf "Script must be run as root. Try 'sudo rasqberry-config'\n"
exit 1
fi
if [ -n "${OPT_MEMORY_SPLIT:-}" ]; then
set -e # Fail when a command errors
set_memory_split "${OPT_MEMORY_SPLIT}"
exit 0
fi
do_rasqberry_about() {
whiptail --msgbox "\
This tool provides a straight-forward way of doing initial \
installation and configuration of the RasQberry system.
To setup RasQberry, go through the steps in 'RasQberry Setup' one by one. \
Some of them require a reboot.
Select either Qiskit version 0.20 or version 0.23 to be installed.
'Config & Demos' installs and configures several quantum demos.
'Quantum Demos' offers several Quantum demos - suitable for a \
TFT touchscreen display or a SenseHAT 8x8 LED matrix. " 20 70 1
}
############# GRAPHICAL WHIPTAIL MENUS #############
## 3rd LEVEL MENUS ##
do_rasqberry_install_qiskit() {
FUN=$(whiptail --title "RasQberry Configuration Tool (rasqberry-config)" --menu "Install Qiskit" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --cancel-button Back --ok-button Select \
"Q00 Qiskit" "Install Qiskit (latest version)" \
"Q41 Qiskit 0.42" "Install Qiskit v0.42" \
"Q41 Qiskit 0.41" "Install Qiskit v0.41" \
"Q39 Qiskit 0.39" "Install Qiskit v0.39" \
"Q37 Qiskit 0.37" "Install Qiskit v0.37" \
"Q36 Qiskit 0.36" "Install Qiskit v0.36" \
"Q34 Qiskit 0.34" "Install Qiskit v0.34" \
"Q30 Qiskit 0.30" "Install Qiskit v0.30" \
"Q29 Qiskit 0.29" "Install Qiskit v0.29" \
"Q28 Qiskit 0.28" "Install Qiskit v0.28" \
"Q27 Qiskit 0.27" "Install Qiskit v0.27" \
"Q25 Qiskit 0.25" "Install Qiskit v0.25" \
"Q24 Qiskit 0.24" "Install Qiskit v0.24" \
"Q23 Qiskit 0.23" "Install Qiskit v0.23" \
"Q20 Qiskit 0.20" "Install Qiskit v0.20" \
"Q19 Qiskit 0.19 " "Install Qiskit v0.19" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
Q19\ *) do_rasqberry_install_general 019 ;;
Q20\ *) do_rasqberry_install_general 020 ;;
Q23\ *) do_rasqberry_install_general 023 ;;
Q24\ *) do_rasqberry_install_general 024 ;;
Q25\ *) do_rasqberry_install_general 025 ;;
Q27\ *) do_rasqberry_install_general 027 ;;
Q28\ *) do_rasqberry_install_general 028 ;;
Q29\ *) do_rasqberry_install_general 029 ;;
Q30\ *) do_rasqberry_install_general 030 ;;
Q34\ *) do_rasqberry_install_general 034 ;;
Q36\ *) do_rasqberry_install_general 036 ;;
Q37\ *) do_rasqberry_install_general 037 ;;
Q39\ *) do_rasqberry_install_general 039 ;;
Q41\ *) do_rasqberry_install_general 041 ;;
Q42\ *) do_rasqberry_install_general 042 ;;
Q00\ *) do_rasqberry_install_general _latest ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
fi
}
do_rasqberry_change_environment_file() {
FUN=$(whiptail --title "RasQberry Configuration Tool (rasqberry-config)" --menu "Change environment file" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --cancel-button Back --ok-button Select \
"I IBM-Q API Token " "Change your IBM-Q API Token" \
"Q N_QUBITS " "Change the number of qubits" \
"L LED_COUNT " "Change the number of LED Pixels" \
"P LED_PIN " "Change the GPIO Pin connected to pixels" \
"O Other " "Change other environment variables" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
I\ *) do_menu_update_environment_file IBM_Q_API_TOKEN ;;
Q\ *) do_menu_update_environment_file N_QUBIT ;;
L\ *) do_menu_update_environment_file LED_COUNT ;;
P\ *) do_menu_update_environment_file LED_PIN ;;
O\ *) nano /home/pi/RasQberry/rasqberry_environment.env ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
fi
}
## 2nd LEVEL MENUS ##
do_rasqberry_setup() {
FUN=$(whiptail --title "RasQberry Configuration Tool (rasqberry-config)" --menu "RasQberry setup and configuration" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --cancel-button Back --ok-button Select \
"IC Initial Config " "Basic configurations (PATH, LOCALE, Python Packages, etc)" \
"SU System Update " "Update the system and create swapfile" \
"IR Install Requirements" "Install Qiskit and other requirements" \
"DV Configure Desktop and VNC " "Configure Desktop Layout and enable VNC displays" \
"CD Config & Demos " "Configure Qiskit and install Quantum Demos" \
"D Docker" "Install & Enable Docker" \
"BL Button+LED" "Configure Control-Button + LEDs" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
IC\ *) do_rq_initial_config ;;
SU\ *) do_rasqberry_update ;;
IR\ *) do_rasqberry_install_requirements ;;
DV\ *) do_rasqberry_enable_desktop_vnc ;;
CD\ *) do_rasqberry_config_demos ;;
D\ *) do_rq_enable_docker ;;
BL\ *) do_rq_configure_button ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
fi
}
do_rasqberry_demos() {
FUN=$(whiptail --title "RasQberry Configuration Tool (rasqberry-config)" --menu "RasQberry setup and configuration" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --cancel-button Back --ok-button Select \
"BS Bloch-Sphere" "Install/Start/Stop the Bloch-Sphere Demo (rec.: enable autostart)" \
"FR Fractals" "Install/Start the Fractals Demo" \
"FRA Fractals Autostart" "Activate the Fractals Autostart" \
"RL RasQ-LED" "Start RasQ-LED demo" \
"CL Clear LED" "Clear LED Lights" \
"QM Qoffee-Maker" "Local Build/Start Qoffee-Maker demo" \
"QMd Qoffee-Maker" "Download/Start Qoffee-Maker image" \
"AP Configure API" "Enter you IBM Q API Token" \
"RT5 Raspberry-Tie 5" "Install/Start/Stop the Raspberry-Tie Demo" \
"RT16 Raspberry-Tie 16 " "Raspberry-Tie 16 Qubit Demo" \
"QR Qrasp " "Install/Start/Stop the Qrasp Demo" \
"CS Clear SenseHAT" "Clear SenseHAT Display" \
"DF Disable Fractal Autostart" "Disable Autostart of Fractal Demo" \
"DB Disable Bloch Autostart " "Disable Autostart of Bloch Demo" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
BS\ *) do_rasqberry_run_bloch ;;
FR\ *) do_rasqberry_run_fractals ;;
FRA\ *) do_rasqberry_activate_fractal_autostart ;;
RL\ *) do_RasQ_LED ;;
CL\ *) do_led_lights_off ;;
QM\ *) do_rasqberry_Qoffee_local ;;
QMd\ *) do_rasqberry_Qoffee_download ;;
AP\ *) do_rasqberry_configure_APITOKEN ;;
RT5\ *) do_rasqberry_run_rasptie_no_network ;;
RT16\ *) do_rasqberry_run_rasptie16_no_network ;;
QR\ *) do_rasqberry_run_qrasp ;;
CS\ *) do_sensehat_display_off ;;
DF\ *) do_rasqberry_deactivate_fractal_autostart ;;
DB\ *) do_rasqberry_deactivate_bloch_autostart ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
fi
}
do_hd_demos() {
FUN=$(whiptail --title "RasQberry Configuration Tool (rasqberry-config)" --menu "HD Demos" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --cancel-button Back --ok-button Select \
"QT Qiskit Tutorials - internal browser" "Start jupyter notebook with Qiskit-Tutorials" \
"FwQ Fun-with-Quantum - internal browser" "Start jupyter notebook with Fun-with-Quantum" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
QT\ *) do_clone_qiskit_start_jupyter ;;
FwQ\ *) do_clone_fwq_start_jupyter ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
fi
}
do_advanced_config() {
FUN=$(whiptail --title "RasQberry Configuration Tool (rasqberry-config)" --menu "Advanced Config" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --cancel-button Back --ok-button Select \
"Q Install Qiskit " "Install Qiskit (several versions)" \
"AH Install AutoHotspot" "Install an automated Wifi Hotspot" \
"B Switch Branches " "Switch to a different branch of RasQberry" \
"E Change environment-file" "Change the contents of the environment-file" \
"RR Reinstall Requirements" "Rerun the requirements installation" \
"CS Change Splash Screen " "Change the splash screen IBM<->Standard" \
"QMst stop Qoffee-Maker " "stop all Qoffee-Maker containers" \
"QMrb Qoffee-Maker rebuild " "force rebuild of Qoffee-Maker images" \
"4Da Enable 4'' Display " "Setup the 4inch Display - Part 1" \
"4Db Enable 4'' Display " "Setup the 4inch Display - Part 2" \
"KV Install Kivy" "Install needed packages for Kivy interface" \
"LE Enable LED Light" "Setup LED Ring above Kryostat" \
"LT Toggle LED Light" "Start/Stop LED above Kryostat" \
"SH Config SenseHAT " "Configure SenseHAT with qrasp autostart" \
"Msg Toggle Messages " "Toggle info message boxes on/off" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 0
elif [ $RET -eq 0 ]; then
case "$FUN" in
Q\ *) do_rasqberry_install_qiskit ;;
AH\ *) do_rasqberry_install_autohotspot ;;
B\ *) do_rasqberry_switch_branch ;;
E\ *) do_rasqberry_change_environment_file ;;
RR\ *) do_rasqberry_rerun_requirements ;;
CS\ *) do_change_splash_screen ;;
QMst\ *) do_rasqberry_Qoffee_stop ;;
QMrb\ *) do_rasqberry_Qoffee_rebuild ;;
4Da\ *) do_rasqberry_enable_touch41 ;;
4Db\ *) do_rasqberry_enable_touch42 ;;
KV\ *) do_install_kivy ;;
LE\ *) do_rasqberry_enable_LED ;;
LT\ *) do_rasqberry_toggle_LED ;;
SH\ *) do_rq_setup_SenseHAT ;;
Msg\ *) do_toggle_messages ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
fi
}
## 1st LEVEL MENU ##
#
# Command line options for non-interactive use
#
for i in "$@"
do
case $i in
--memory-split=*)
OPT_MEMORY_SPLIT=$(echo "$i" | sed 's/[-a-zA-Z0-9]*=//')
printf "Not currently supported\n"
exit 1
;;
--expand-rootfs)
INTERACTIVE=False
do_expand_rootfs
printf "Please reboot\n"
exit 0
;;
--apply-os-config)
INTERACTIVE=False
do_apply_os_config
exit $?
;;
nonint)
INTERACTIVE=False
"$@"
exit $?
;;
*)
# unknown option
;;
esac
done
#
# Interactive use loop
#
if [ "$INTERACTIVE" = true ]; then
[ -e "$CONFIG" ] || touch "$CONFIG"
calc_wt_size
while [ "$USER" = "root" ] || [ -z "$USER" ]; do
if ! USER=$(whiptail --inputbox "raspi-config could not determine the default user.\\n\\nWhat user should these settings apply to?" 20 60 pi 3>&1 1>&2 2>&3); then
return 0
fi
done
while true; do
if is_pi ; then
FUN=$(whiptail --title "RasQberry Configuration Tool (rasqberry-config)" --backtitle "$(cat /proc/device-tree/model)" --menu "Setup Options" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --cancel-button Finish --ok-button Select \
"OI One-Click Install" "Run options SU, IC, IR, DV, CD, D and BL in one go" \
"OD One-Click Demo Install" "Run options BS and QM in one go" \
"S RasQberry Setup" "Step-by-step RasQberry initial setup and configuration" \
"D Quantum Demos" "Install and run Quantum Demos" \
"H HD Demos" "Install and run HD Demos" \
"A Advanced Config" "Advanced Config" \
"9 About rasqberry-config " "Information about this configuration tool" \
3>&1 1>&2 2>&3)
else
FUN=$(whiptail --title "RasQberry Configuration Tool (rasqberry-config)" --menu "Setup Options" "$WT_HEIGHT" "$WT_WIDTH" "$WT_MENU_HEIGHT" --cancel-button Finish --ok-button Select \
"9 About" "Information about this configuration tool" \
3>&1 1>&2 2>&3)
fi
RET=$?
if [ $RET -eq 1 ]; then
do_finish
elif [ $RET -eq 0 ]; then
if is_pi ; then
case "$FUN" in
OI\ *) do_rq_one_click_install ;;
OD\ *) do_rq_one_click_demo_install ;;
S\ *) do_rasqberry_setup ;;
D\ *) do_rasqberry_demos ;;
H\ *) do_hd_demos ;;
A\ *) do_advanced_config ;;
9\ *) do_rasqberry_about ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
else
case "$FUN" in
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
fi
else
exit 1
fi
done
fi