-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsdlSpeedometer-config
More file actions
executable file
·609 lines (512 loc) · 19.3 KB
/
sdlSpeedometer-config
File metadata and controls
executable file
·609 lines (512 loc) · 19.3 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
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
#!/bin/bash
# shellcheck disable=SC2181
if [[ "$(readlink -f "$0")" == "/usr/local/bin/"* ]]; then
SPEEDOMETER_DB=/usr/local/etc/speedometer/speedometer.db
installed=1
else
unset DISPLAY
SPEEDOMETER_DB=speedometer.db
installed=0
fi
if [ ! -f $SPEEDOMETER_DB ]; then
echo "Database $SPEEDOMETER_DB not found. Run ./sdlSpeedometer to create an initial database."
exit 1
fi
# Inherited from raspi-config https://github.com/RPi-Distro/raspi-config
# Copyright (c) 2012 Alex Bradbury <asb@asbradbury.org>
#
# See LICENSE file at github for copyright and license details
export TERM="xterm-256color"
ASK_TO_REBOOT=0
SQLFILE=$(mktemp)
do_finish() {
if [ -f "$SQLFILE" ]; then
sqlite3 $SPEEDOMETER_DB < "$SQLFILE"
fi
RET=$!
sync
if [ $ASK_TO_REBOOT -eq 1 ]; then
whiptail --yesno "Would you like to reboot now?" 20 60 2
if [ $? -eq 0 ]; then # yes
sync
reboot
fi
fi
if [ -s "$SQLFILE" ] && [ $installed -eq 1 ]; then
if systemctl status sdlSpeedometer.service &>/dev/null ; then
sudo systemctl restart sdlSpeedometer.service &>/dev/null || true
fi
fi
exit $RET
}
calc_wt_size() {
# NOTE: it's tempting to redirect stderr to /dev/null, so supress error
# output from tput. However in this case, tput detects neither stdout or
# stderr is a tty and so only gives default 80, 24 values
WT_HEIGHT=18
WT_WIDTH=$(tput cols)
if [ -z "$WT_WIDTH" ] || [ "$WT_WIDTH" -lt 60 ]; then
WT_WIDTH=80
fi
if [ "$WT_WIDTH" -gt 178 ]; then
WT_WIDTH=120
fi
# shellcheck disable=SC2004
WT_MENU_HEIGHT=$(($WT_HEIGHT-7))
}
do_set_external_app() {
if [ "$(id -u)" -ne 0 ]; then
RMGS="Please note that SdlSpeedometer has to run with root privileges to run 'openvt' programs"
fi
whiptail --msgbox "\
Enter an application and and its arguments here.\\n
A new tools icon will appear on one of the GUI screens.
To disable an application, enter 'notyet'.\\n
To run a terminal appication (nox-X), prefix the commant with 'openvt'. $RMGS
" 20 70 1
CURRENT_SUBAPP=$(sqlite3 $SPEEDOMETER_DB "SELECT task FROM subtasks WHERE Id=$1;")
CURRENT_SUBAPPARGS=$(sqlite3 $SPEEDOMETER_DB "SELECT args FROM subtasks WHERE Id=$1;")
NEW_SUBAPP=$(whiptail --inputbox "Please enter a new application to be launchd from the GUI" 20 60 "$CURRENT_SUBAPP $CURRENT_SUBAPPARGS" 3>&1 1>&2 2>&3)
if [ -n "$NEW_SUBAPP" ]; then
cmd=$(echo "$NEW_SUBAPP" | awk -F' ' '{print $1}')
arg=$(echo "$NEW_SUBAPP" | awk '{$1=""; print $0}')
if [ "$cmd" == "openvt" ]; then
icon=$(echo $arg | tr -d ' ')
else
icon=$(echo $cmd | tr -d ' ')
fi
echo "UPDATE subtasks SET task='$cmd', args='$arg', icon='$icon' WHERE Id=$1;" >> "$SQLFILE"
fi
}
do_set_serial_device() {
whiptail --msgbox "\
Enter a serial device name for the NMEA-0183 port.\\n
For a Raspberry Pi model 3 and 4 with the BerryGPS on the GPIO connector it should be /dev/ttyS0 and for \
other Raspberrys' /dev/tyAMA0. For USB NMEA converters something like /dev/ttyUSBn.\\n
If KPLEX is present in the system it is reccomended that KPLEX owns the serial device and that device name is set to 'none'.
" 20 70 1
CURRENT_SERIALDEV=$(sqlite3 $SPEEDOMETER_DB 'SELECT tty FROM config;')
NEW_SERIALDEV=$(whiptail --inputbox "Please enter a serial device or 'none' to disable serial NMEA handling" 20 60 "$CURRENT_SERIALDEV" 3>&1 1>&2 2>&3)
if [ -n "$NEW_SERIALDEV" ]; then
echo "UPDATE config SET tty = '$NEW_SERIALDEV' WHERE Id=1;" >> "$SQLFILE"
sudo systemctl stop serial-getty@"$(basename "${NEW_SERIALDEV}")".service &>/dev/null || true
sudo systemctl disable serial-getty@"$(basename "${NEW_SERIALDEV}")".service &>/dev/null || true
fi
}
do_set_serial_speed() {
whiptail --msgbox "\
Enter serial baudrate for the NMEA device. \\n
For a BerryGPS default is 9600.
" 20 70 1
CURRENT_SERIALSPEED=$(sqlite3 $SPEEDOMETER_DB 'SELECT baud FROM config;')
NEW_SERIALSPEED=$(whiptail --inputbox "Please enter a serial baudrate" 20 60 "$CURRENT_SERIALSPEED" 3>&1 1>&2 2>&3)
if [ -n "$NEW_SERIALSPEED" ]; then
echo "UPDATE config SET baud = '$NEW_SERIALSPEED' WHERE Id=1;" >> "$SQLFILE"
fi
}
do_set_nmea_server() {
whiptail --msgbox "\
Enter a hostname (or I.P number) of a TCP NMEA-0183 Server or 'none' to disable this service
" 20 70 1
CURRENT_NMEASERVER=$(sqlite3 $SPEEDOMETER_DB 'SELECT server FROM config;')
NEW_NMEASERVER=$(whiptail --inputbox "Please enter a host name" 20 60 "$CURRENT_NMEASERVER" 3>&1 1>&2 2>&3)
if [ -n "$NEW_NMEASERVER" ]; then
echo "UPDATE config SET server = '$NEW_NMEASERVER' WHERE Id=1;" >> "$SQLFILE"
fi
}
do_set_nmea_port() {
whiptail --msgbox "\
Enter the port number of the TCP NMEA-0183 Server
" 20 70 1
CURRENT_NMEAPORT=$(sqlite3 $SPEEDOMETER_DB 'SELECT port FROM config;')
NEW_NMEAPORT=$(whiptail --inputbox "Please enter a port number" 20 60 "$CURRENT_NMEAPORT" 3>&1 1>&2 2>&3)
if [ -n "$NEW_NMEAPORT" ]; then
echo "UPDATE config SET port = '$NEW_NMEAPORT' WHERE Id=1;" >> "$SQLFILE"
fi
}
do_set_vnc_port() {
whiptail --msgbox "\
Enter the port number of the VNC Server
" 20 70 1
CURRENT_VNCPORT=$(sqlite3 $SPEEDOMETER_DB 'SELECT vncport FROM config;')
NEW_VNCPORT=$(whiptail --inputbox "Please enter a port number" 20 60 "$CURRENT_VNCPORT" 3>&1 1>&2 2>&3)
if [ -n "$NEW_VNCPORT" ]; then
echo "UPDATE config SET vncport = '$NEW_VNCPORT' WHERE Id=1;" >> "$SQLFILE"
fi
}
do_set_camera_url() {
whiptail --msgbox "\
Enter the URL to an RTSP Camera
" 20 70 1
CURRENT_CAMERA_URL=$(sqlite3 $SPEEDOMETER_DB 'SELECT camurl FROM config;')
NEW_CURRENT_CAMERA_URL=$(whiptail --inputbox "Please enter the camera URL" 20 60 -- "$CURRENT_CAMERA_URL" 3>&1 1>&2 2>&3)
if [ -n "$NEW_CURRENT_CAMERA_URL" ]; then
echo "UPDATE config SET camurl = '$NEW_CURRENT_CAMERA_URL' WHERE Id=1;" >> "$SQLFILE"
fi
}
do_set_compass_offset() {
whiptail --msgbox "\
Enter the manual compass offset, Max -10 to + 10 degrees
" 20 70 1
CURRENT_COMPASSOFFSET=$(sqlite3 $SPEEDOMETER_DB 'SELECT cOffset FROM calib;')
NEW_COMPASSOFFSET=$(whiptail --inputbox "Please the compass offset" 20 60 -- "$CURRENT_COMPASSOFFSET" 3>&1 1>&2 2>&3)
if [ -n "$NEW_COMPASSOFFSET" ]; then
echo "UPDATE calib SET cOffset = '$NEW_COMPASSOFFSET' WHERE Id=1;" >> "$SQLFILE"
fi
}
do_set_compass_roll_offset() {
whiptail --msgbox "\
Enter the manual compass roll offset, Max -4 to + 4 degrees.\\nThis is for the clinometer symbol.
" 20 70 1
CURRENT_COMPASS_ROLL_OFFSET=$(sqlite3 $SPEEDOMETER_DB 'SELECT rOffset FROM calib;')
NEW_COMPASS_ROLL_OFFSET=$(whiptail --inputbox "Please the compass roll offset" 20 60 -- "$CURRENT_COMPASS_ROLL_OFFSET" 3>&1 1>&2 2>&3)
if [ -n "$NEW_COMPASS_ROLL_OFFSET" ]; then
echo "UPDATE calib SET rOffset = '$NEW_COMPASS_ROLL_OFFSET' WHERE Id=1;" >> "$SQLFILE"
fi
}
do_set_depth_warning() {
whiptail --msgbox "\
Enter the audible depth warning message level in decimal meters
" 20 70 1
CURRENT_DEPTH_WARNING=$(sqlite3 $SPEEDOMETER_DB 'SELECT depthw FROM warnings;')
NEW_DEPTH_WARNING=$(whiptail --inputbox "Please enter the depth warning in meters" 20 60 -- "$CURRENT_DEPTH_WARNING" 3>&1 1>&2 2>&3)
if [ -n "$NEW_DEPTH_WARNING" ]; then
echo "UPDATE warnings SET depthw = '$NEW_DEPTH_WARNING' WHERE Id=1;" >> "$SQLFILE"
fi
}
do_set_wessel_draft() {
whiptail --msgbox "\
Enter the wessel draft in decimal meters
" 20 70 1
CURRENT_DRAFT_WARNING=$(sqlite3 $SPEEDOMETER_DB 'SELECT draftw FROM warnings;')
NEW_DRAFT_WARNING=$(whiptail --inputbox "Please enter the the wessel draft in meters" 20 60 -- "$CURRENT_DRAFT_WARNING" 3>&1 1>&2 2>&3)
if [ -n "$NEW_DRAFT_WARNING" ]; then
echo "UPDATE warnings SET draftw = '$NEW_DRAFT_WARNING' WHERE Id=1;" >> "$SQLFILE"
fi
}
do_set_voltage_warning() {
whiptail --msgbox "\
Enter the audible low voltage level warning message
" 20 70 1
CURRENT_VOLTAGE_WARNING=$(sqlite3 $SPEEDOMETER_DB 'SELECT lowvoltw FROM warnings;')
NEW_VOLTAGE_WARNING=$(whiptail --inputbox "Please enter the low voltage warning in volt" 20 60 -- "$CURRENT_VOLTAGE_WARNING" 3>&1 1>&2 2>&3)
if [ -n "$NEW_VOLTAGE_WARNING" ]; then
echo "UPDATE warnings SET lowvoltw = '$NEW_VOLTAGE_WARNING' WHERE Id=1;" >> "$SQLFILE"
fi
}
do_set_current_warning() {
whiptail --msgbox "\
Enter the audible high current level warning message
" 20 70 1
CURRENT_CURRENT_WARNING=$(sqlite3 $SPEEDOMETER_DB 'SELECT highcurrw FROM warnings;')
NEW_CURRENT_WARNING=$(whiptail --inputbox "Please enter the high current warning in Ampere" 20 60 -- "$CURRENT_CURRENT_WARNING" 3>&1 1>&2 2>&3)
if [ -n "$NEW_CURRENT_WARNING" ]; then
echo "UPDATE warnings SET highcurrw = '$NEW_CURRENT_WARNING' WHERE Id=1;" >> "$SQLFILE"
fi
}
is_pulseaudio() {
pgrep pulseaudio > /dev/null || pgrep pipewire-pulse > /dev/null
return $?
}
do_set_audio_device() {
CURRENT_AUDIO_DEVICE=$(sqlite3 $SPEEDOMETER_DB 'SELECT audiodev FROM config;' | awk -F'[:,]' '{print $2}')
if is_pulseaudio ; then
oIFS="$IFS"
list=$(pactl list sinks | grep -e "Sink #" -e "alsa.card_name" | sed s/*//g | sed s/^[' '\\t]*//g | sed s/'Sink #'//g | sed s/'alsa.card_name = '//g | sed s/'bcm2835 '//g | sed s/\"//g | tr '\n' '/')
if [ -n "$list" ] ; then
IFS="/"
AUDIO_OUT=$(whiptail --menu "Choose the audio output. Current is $CURRENT_AUDIO_DEVICE" 20 60 10 ${list} 3>&1 1>&2 2>&3)
else
whiptail --msgbox "No internal audio devices found" 20 60 1
return 1
fi
if [ $? -eq 0 ]; then
sudo -u $USER XDG_RUNTIME_DIR=/run/user/$SUDO_UID pactl set-default-sink $AUDIO_OUT
fi
IFS="$oIFS"
else
if aplay -l | grep -q "bcm2835 ALSA"; then
AUDIO_OUT=$(whiptail --menu "Choose the audio output. Current is $CURRENT_AUDIO_DEVICE" 20 60 10 \
"0" "Auto" \
"1" "Force 3.5mm ('headphone') jack" \
"2" "Force HDMI" \
3>&1 1>&2 2>&3)
AUDIO_OUT=$1
if [ "$?" -eq 0 ] && [ -n "$AUDIO_OUT" ]; then
amixer cset numid=3 "$AUDIO_OUT"
fi
else
n=0
array=""
while [ $n -le 9 ]
do
CARD=$(LC_ALL=C aplay -l | grep "card $n" | cut -d [ -f 2 | cut -d ] -f 1)
if [ -z "$CARD" ] ; then
n=$(( n+1 ))
continue
else
if [ -z "$array" ] ; then
array=$n"/"$CARD
else
#shellcheck disable=2027
array=$array"/"$n"/"$CARD
fi
fi
n=$(( n+1 ))
done
if [ $n -eq 0 ] ; then
whiptail --msgbox "No audio devices found" 20 60 1
false
else
oIFS="$IFS"
IFS="/"
AUDIO_OUT=$(whiptail --menu "Choose the audio output. Current is $CURRENT_AUDIO_DEVICE" 20 60 10 ${array} 3>&1 1>&2 2>&3)
IFS="$oIFS"
fi
if [ "$?" -eq 0 ] && [ -n "$AUDIO_OUT" ]; then
NEW_AUDIO_DEVICE="hw:${AUDIO_OUT},0"
echo "UPDATE config SET audiodev = '$NEW_AUDIO_DEVICE' WHERE Id=1;" >> "$SQLFILE"
fi
fi
fi
}
do_hostname() {
if [ "$(id -u)" -ne 0 ]; then
whiptail --msgbox "\
Ony root can do this.
" 20 70 1
return
fi
whiptail --msgbox "\
Please note: RFCs mandate that a hostname's labels \
may contain only the ASCII letters 'a' through 'z' (case-insensitive),
the digits '0' through '9', and the hyphen.
Hostname labels cannot begin or end with a hyphen.
No other symbols, punctuation characters, or blank spaces are permitted.\
" 20 70 1
CURRENT_HOSTNAME=$(hostnamectl --static status | tr -d ' \t\n\r')
NEW_HOSTNAME=$(whiptail --inputbox "Please enter a hostname" 20 60 "$CURRENT_HOSTNAME" 3>&1 1>&2 2>&3)
if [ $? -eq 0 ]; then
hostnamectl set-hostname "$NEW_HOSTNAME"
sed -i "s/127.0.1.1.*$CURRENT_HOSTNAME/127.0.1.1\\t$NEW_HOSTNAME/g" /etc/hosts
ASK_TO_REBOOT=1
fi
}
list_wlan_interfaces() {
for dir in /sys/class/net/*/wireless; do
if [ -d "$dir" ]; then
basename "$(dirname "$dir")"
fi
done
}
get_wifi_country() {
grep country= /etc/wpa_supplicant/wpa_supplicant.conf | cut -d "=" -f 2
}
do_wifi_country() {
IFACE="$(list_wlan_interfaces | head -n 1)"
if [ -z "$IFACE" ]; then
whiptail --msgbox "No wireless interface found" 20 60
return 1
fi
if ! wpa_cli -i "$IFACE" status > /dev/null 2>&1; then
whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60
return 1
fi
oIFS="$IFS"
IFS="/"
value=$(tail -n +26 /usr/share/zoneinfo/iso3166.tab | tr '\t' '/' | tr '\n' '/')
COUNTRY=$(whiptail --menu "Select the country in which the Pi is to be used" 20 60 10 "${value}" 3>&1 1>&2 2>&3)
IFS=$oIFS
if [ $? -eq 0 ];then
wpa_cli -i "$IFACE" set country "$COUNTRY"
if ! iw reg set "$COUNTRY" 2> /dev/null; then
ASK_TO_REBOOT=1
fi
if [ -f /run/wifi-country-unset ] && hash rfkill 2> /dev/null; then
rfkill unblock wifi
fi
whiptail --msgbox "Wi-fi country set to $COUNTRY" 20 60 1
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
fi
}
do_raspi_config() {
if [ "$(id -u)" -ne 0 ]; then
whiptail --msgbox "\
Ony root can do this.
" 20 70 1
return
fi
whiptail --yesno --defaultno "\
The raspi-config tool helps you to configure your Raspberry Pi; several \
settings can be changed with this tool without having to know the correct commands to use.\\n
Enter YES to run raspi-config.
" 20 70 1
if [ $? -eq 0 ]; then # yes
/usr/bin/raspi-config
return 0
fi
}
do_wifi_ssid_passphrase() {
if [ "$(id -u)" -ne 0 ]; then
whiptail --msgbox "\
Ony root can do this.
" 20 70 1
return
fi
if pidof -s hostapd &>/dev/null; then
whiptail --msgbox "\
This system is configured as an access point that cannot be configured here.
" 20 70 1
return
fi
RET=0
IFACE_LIST="$(list_wlan_interfaces)"
IFACE="$(echo "$IFACE_LIST" | head -n 1)"
if [ -z "$IFACE" ]; then
whiptail --msgbox "No wireless interface found" 20 60
return 1
fi
if ! wpa_cli -i "$IFACE" status > /dev/null 2>&1; then
whiptail --msgbox "Could not communicate with wpa_supplicant" 20 60
return 1
fi
if [ -z "$(get_wifi_country)" ]; then
do_wifi_country
fi
SSID=""
CSSID=""
iwlist "$IFACE" scan &>/dev/null &
PID=$!
{
for ((i = 0 ; i <= 120 ; i+=6)); do
sleep 1
echo $i
kill -s 0 $PID &>/dev/null || break;
done
} | whiptail --gauge "Please wait while scanning" 6 60 0
SSID_LIST=$(wpa_cli scan_results 2>/dev/null | grep WPA | sed 's/ /_/g' | awk '{printf "%s %s OFF ", $NF, $2 }')
RES=${PIPESTATUS[0]}
while [ -z "$SSID" ]; do
if [ "$RES" -eq 0 ]; then
CSSID=$(iwconfig "$IFACE" 2> /dev/null | awk -F: '/ESSID:/ {print $2}' | awk '{printf "%s",$1}')
IP=$(ip -4 addr show "$IFACE" | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
if [ -n "$IP" ]; then IP="($IP)"; fi
# shellcheck disable=SC2086
SSID="$(whiptail --title "Add SSID" --radiolist "Current connection is $CSSID $IP\\nWhat is the SSID of your choice?" 15 60 7 ${SSID_LIST} 3>&1 1>&2 2>&3)"
else
SSID=$(whiptail --inputbox "Please enter SSID" 20 60 3>&1 1>&2 2>&3)
fi
if [ $? -ne 0 ]; then
return 0
elif [ -z "$SSID" ]; then
RES=1
whiptail --msgbox "SSID cannot be empty. Please try again." 20 60
fi
done
PASSPHRASE=""
while true; do
PASSPHRASE=$(whiptail --passwordbox "Please enter passphrase for $SSID. Leave it empty if none." 20 60 3>&1 1>&2 2>&3)
if [ $? -ne 0 ]; then
return 0
else
break
fi
done
IDS=$(wpa_cli -i "$IFACE" add_network 2>/dev/null)
if ! [ "$IDS" -eq "$IDS" ] 2> /dev/null
then
whiptail --msgbox "Failed to get network list" 20 60
return 1
fi
while [ "$IDS" -ge 0 ]; do
wpa_cli -i "$IFACE" remove_network "$IDS" &>/dev/null
IDS=$((IDS -1))
done
wpa_cli -i "$IFACE" save_config &>/dev/null
ID="$(wpa_cli -i "$IFACE" add_network 2>/dev/null)"
wpa_cli -i "$IFACE" set_network "$ID" ssid "\"$SSID\"" 2>&1 | grep -q "OK"
RET=$((RET + $?))
if [ -z "$PASSPHRASE" ]; then
wpa_cli -i "$IFACE" set_network "$ID" key_mgmt NONE 2>&1 | grep -q "OK"
RET=$((RET + $?))
else
wpa_cli -i "$IFACE" set_network "$ID" psk "\"$PASSPHRASE\"" 2>&1 | grep -q "OK"
RET=$((RET + $?))
fi
if [ $RET -eq 0 ]; then
wpa_cli -i "$IFACE" enable_network "$ID" > /dev/null 2>&1
else
wpa_cli -i "$IFACE" remove_network "$ID" > /dev/null 2>&1
whiptail --msgbox "Failed to set SSID or passphrase" 20 60
fi
wpa_cli -i "$IFACE" save_config > /dev/null 2>&1
RET=$((RET + $?))
echo "$IFACE_LIST" | while read -r IFACE; do
wpa_cli -i "$IFACE" reconfigure > /dev/null 2>&1
done
return $RET
}
do_config_menu() {
FUN=$(whiptail --title "sdlSpeedometer Configuration Tool (sdlSpeedometer-config)" --menu "Config Options" $WT_HEIGHT $WT_WIDTH $WT_MENU_HEIGHT --cancel-button Finish --ok-button Select \
"1 Hostname" "Set the visible name for this Pi on a network" \
"2 Wi-fi" "Change SSID and passphrase" \
"3 Serial device" "Enter device name for the NMEA-0183 port" \
"4 Serial speed" "Enter baud rate for the NMEA-0183 port" \
"5 NMEA Network" "Enter NMEA-0183 server name" \
"6 NMEA Net port" "Enter NMEA-0183 server port" \
"7 VNC Server port" "Enter VNC server port" \
"8 Application 1" "Enter External Application for page COG" \
"9 Application 2" "Enter External Application for page SOG" \
"10 Application 3" "Enter External Application for page DPT" \
"11 Application 4" "Enter External Application for page WND" \
"12 Application 5" "Enter External Application for page GPS" \
"13 Application 6" "Enter External Application for page PWR" \
"14 Compass offset" "Enter manual compass offset" \
"15 Compass roll offset" "Enter manual compass roll offset" \
"16 Depth warning" "Enter the audible depth level warning" \
"17 Wessel draft" "Enter the wessel draft level warning" \
"18 Voltage warning" "Enter the audible low voltage level warning" \
"19 Current warning" "Enter the audible high current level warning" \
"20 Audio Device" "Enter the audio device used for spoken warnings" \
"21 RTSP Camera" "Enter the URL for an RTSP Camera" \
"22 Configuration" "Run raspi-config" \
3>&1 1>&2 2>&3)
RET=$?
if [ $RET -eq 1 ]; then
return 1
elif [ $RET -eq 0 ]; then
case "$FUN" in
1\ *) do_hostname ;;
2\ *) do_wifi_ssid_passphrase ;;
3\ *) do_set_serial_device ;;
4\ *) do_set_serial_speed ;;
5\ *) do_set_nmea_server ;;
6\ *) do_set_nmea_port ;;
7\ *) do_set_vnc_port ;;
8\ *) do_set_external_app 1 ;;
9\ *) do_set_external_app 2 ;;
10\ *) do_set_external_app 3 ;;
11\ *) do_set_external_app 4 ;;
12\ *) do_set_external_app 5 ;;
13\ *) do_set_external_app 6 ;;
14\ *) do_set_compass_offset ;;
15\ *) do_set_compass_roll_offset ;;
16\ *) do_set_depth_warning ;;
17\ *) do_set_wessel_draft ;;
18\ *) do_set_voltage_warning ;;
19\ *) do_set_current_warning ;;
20\ *) do_set_audio_device ;;
21\ *) do_set_camera_url ;;
22\ *) do_raspi_config ;;
*) whiptail --msgbox "Programmer error: unrecognized option" 20 60 1 ;;
esac || whiptail --msgbox "There was an error running option $FUN" 20 60 1
fi
}
calc_wt_size
while true; do
do_config_menu
RET=$?
if [ $RET -eq 1 ]; then
do_finish
fi
done