debian-config-submenu 37.3 KB
Newer Older
Igor Pecovnik's avatar
Igor Pecovnik committed
1
2
3
4
5
6
7
8
9
#!/bin/bash
#
# Copyright (c) 2017 Igor Pecovnik, igor.pecovnik@gma**.com
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.


10

11
12
13
check_if_installed (){
#------------------------------------------------------------------------------------------------------------------------------------------
# check dpkg status of $1 -- currently only 'not installed at all' case catched
14
#
15
16
17
18
19
20
21
22
23
	local DPKG_Status="$(dpkg -s "$1" 2>/dev/null | awk -F": " '/^Status/ {print $2}')"
	if [[ "X${DPKG_Status}" = "X" || "${DPKG_Status}" = *deinstall* ]]; then
		return 1
	else
		return 0
	fi
}


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
#-----------------------------------------------------------------------------------------------------------------------------------------#
# check hostapd configuration. Return error or empty if o.k.
#
check_hostapd ()
{
systemctl daemon-reload
hostapd_error=""
[[ -n $1 && -n $2 ]] && dialog --title " $1 " --backtitle "$BACKTITLE" --no-collapse --colors --infobox "$2" 5 $((${#2}-3))
service hostapd stop
rm -f /var/run/hostapd/*
sleep 1
service hostapd start
sleep 6
if [[ "$(hostapd_cli ping 2> /dev/null| grep PONG)" == "PONG" ]]; then
		hostapd_error=""
	else
		hostapd_error=$(hostapd /etc/hostapd.conf)
		sleep 6
		[[ -n $(echo $hostapd_error | grep "channel") ]] && hostapd_error="channel_restriction"
		[[ -n $(echo $hostapd_error | grep "does not support" | grep "hw_mode") ]] && hostapd_error="hw_mode"
		[[ -n $(echo $hostapd_error | grep "not found from the channel list" | grep "802.11g") ]] && hostapd_error="wrong_channel"
		[[ -n $(echo $hostapd_error | grep "VHT") ]] && hostapd_error="unsupported_vht"
		[[ -n $(echo $hostapd_error | grep " HT capability") ]] && hostapd_error="unsupported_ht"
fi
}


Igor Pecovnik's avatar
Igor Pecovnik committed
51
52
53
#-----------------------------------------------------------------------------------------------------------------------------------------#
# check all possible wireless modes
#
54
55
function check_advanced_modes ()
{
56
57
58
59
60
61
62
63
64
65
66
67
68
69
sed '/### IEEE 802.11n/,/^### IEEE 802.11n/ s/^# *//' -i /etc/hostapd.conf
check_hostapd "Probing" "\n802.11n \Z1(150-300Mbps)\Z0"
# check HT capability
check_ht_capab
if [[ -z "$hostapd_error" ]]; then
	sed '/### IEEE 802.11a\>/,/^### IEEE 802.11a\>/ s/^# *//' -i /etc/hostapd.conf
	sed -i "s/^channel=.*/channel=40/" /etc/hostapd.conf
	check_hostapd "Probing" "\n802.11a \Z1(5Ghz)\Z0"
	if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
	if [[ "$hostapd_error" == "channel_restriction" ]]; then
		# revering configuration
		sed -i "s/^channel=.*/channel=5/" /etc/hostapd.conf
		sed '/## IEEE 802.11a\>/,/^## IEEE 802.11a\>/ s/.*/#&/' -i /etc/hostapd.conf
		check_hostapd "Reverting" "\nWireless \Z1802.11a (5Ghz)\Z0 is not supported"
Igor Pecovnik's avatar
Igor Pecovnik committed
70
	else
71
72
73
74
75
76
77
78
79
		sed '/### IEEE 802.11ac\>/,/^### IEEE 802.11ac\>/ s/^# *//' -i /etc/hostapd.conf
		# check VHT capability
		check_vht_capab
		if [[ "$hostapd_error" == "unsupported_vht" || "$hostapd_error" == "channel_restriction" ]]; then
			# revering configuration
			sed '/## IEEE 802.11ac\>/,/^## IEEE 802.11ac\>/ s/.*/#&/' -i /etc/hostapd.conf
			check_hostapd "Reverting" "\nWireless 802.11ac \Z1(433Mbps x n @ 5Ghz)\Z0 is not supported"
			if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
		fi
Igor Pecovnik's avatar
Igor Pecovnik committed
80
	fi
81
82
else
	sed '/## IEEE 802.11n/,/^## IEEE 802.11n/ s/.*/#&/' -i /etc/hostapd.conf
Igor Pecovnik's avatar
Igor Pecovnik committed
83
fi
84
85
86
}


Igor Pecovnik's avatar
Igor Pecovnik committed
87
88
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
89
# create interface configuration section
Igor Pecovnik's avatar
Igor Pecovnik committed
90
#
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
91
function create_if_config() {
Igor Pecovnik's avatar
RC1    
Igor Pecovnik committed
92
		address=$(ip -4 addr show dev $1 | awk '/inet/ {print $2}' | cut -d'/' -f1)
93
		netmask=$(ip -4 addr show dev $1 | awk '/inet/ {print $2}' | cut -d'/' -f2)
Igor Pecovnik's avatar
RC1    
Igor Pecovnik committed
94
95
96
		gateway=$(route -n | grep 'UG[ \t]' | awk '{print $2}' | sed -n '1p')
		echo -e "# armbian-config created"
		echo -e "source /etc/network/interfaces.d/*\n"
Igor Pecovnik's avatar
Igor Pecovnik committed
97
98
		if [[ "$3" == "fixed" ]]; then
			echo -e "# Local loopback\nauto lo\niface lo init loopback\n"
99
			echo -e "# Interface $2\nauto $2\nallow-hotplug $2"
Igor Pecovnik's avatar
RC1    
Igor Pecovnik committed
100
			echo -e "iface $2 inet static\n\taddress $address\n\tnetmask $netmask\n\tgateway $gateway\n\tdns-nameservers 8.8.8.8"
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
101
102
		fi
} #
Igor Pecovnik's avatar
Igor Pecovnik committed
103
104
105
106


#-----------------------------------------------------------------------------------------------------------------------------------------#
#
Igor Pecovnik's avatar
Igor Pecovnik committed
107
108
109
110
111
112
113
114
115
116
# reaload network related services. some are "just in case"
#
function reload-nety() {
	systemctl daemon-reload
	if [[ "$1" == "reload" ]]; then WHATODO="Reloading services"; else WHATODO="Stopping services"; fi
	(service network-manager stop; echo 10; sleep 1; service hostapd stop; echo 20; sleep 1; service dnsmasq stop; echo 30; sleep 1;\
	[[ "$1" == "reload" ]] && service dnsmasq start && echo 60 && sleep 1 && service hostapd start && echo 80 && sleep 1;\
	service network-manager start; echo 90; sleep 5;) | dialog --backtitle "$BACKTITLE" --title " $WHATODO " --gauge "" 6 70 0
	systemctl restart systemd-resolved.service
}
Igor Pecovnik's avatar
Igor Pecovnik committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136


#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# Check if something is running on port $1 and display info
#
check_port ()
{
[[ -n $(netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ".'$1'"') ]] && dialog --backtitle "$BACKTITLE" --title "Checking service" \
--msgbox "\nIt looks good.\n\nThere is $2 service on port $1" 9 52
}


#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show disclaimer
#
function beta_disclaimer ()
{
exec 3>&1
Igor Pecovnik's avatar
Igor Pecovnik committed
137
138
ACKNOWLEDGEMENT=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse --title " Warning " \
--clear \--radiolist "\n$1.\n \n" 12 56 7 "Yes, I understand" "" off	 2>&1 1>&3)
Igor Pecovnik's avatar
Igor Pecovnik committed
139
140
141
142
exec 3>&-
}


Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
143
144
145
146
147
148
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show box
#
function show_box ()
{
149
dialog --colors --backtitle "$BACKTITLE" --no-collapse --title " $1 " --clear --msgbox "\n$2\n \n" $3 56
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
150
151
152
}


Igor Pecovnik's avatar
Igor Pecovnik committed
153
154
155
156
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# check wifi high throughput
#
157
158
function check_ht_capab ()
{
Igor Pecovnik's avatar
Igor Pecovnik committed
159
declare -a arr=("[HT40+][LDPC][SHORT-GI-20][SHORT-GI-40][TX-STBC][RX-STBC1][DSSS_CCK-40][SMPS-STATIC]" \
160
"[HT40-][SHORT-GI-40][SHORT-GI-40][DSSS_CCK-40]" "[SHORT-GI-20][SHORT-GI-40][HT40+]" "[DSSS_CK-40][HT20+]" "")
161
local j=0
162
163
for i in "${arr[@]}"
do
164
165
	j=$((j+(100/${#arr[@]})))
	echo $j | dialog --title " Probing HT " --colors --gauge "\nSeeking for optimal \Z1high throughput\Z0 settings." 8 50 0
166
	sed -i "s/^ht_capab=.*/ht_capab=$i/" /etc/hostapd.conf
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
	check_hostapd
	if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
	if [[ "$hostapd_error" == "" ]]; then break; fi
done
}


#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# check wifi high throughput
#
function check_vht_capab ()
{
declare -a arr=("[MAX-MPDU-11454][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-A-MPDU-LEN-EXP3]" "[MAX-MPDU-11454][SHORT-GI-80][RX-STBC-1][MAX-A-MPDU-LEN-EXP3]" "")
local j=0
for i in "${arr[@]}"
do
	j=$((j+(100/${#arr[@]})))
	echo $j | dialog --title " Probing VHT " --colors --gauge "\nSeeking for optimal \Z1very high throughput\Z0 settings." 8 54 0
	sed -i "s/^vht_capab=.*/vht_capab=$i/" /etc/hostapd.conf
	check_hostapd
	if [[ "$hostapd_error" == "channel_restriction" ]]; then check_channels; fi
	if [[ "$hostapd_error" == "" ]]; then break; fi
190
191
192
done
}

Igor Pecovnik's avatar
Igor Pecovnik committed
193
194
195
196
197

#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# check 5Ghz channels
#
198
199
200
201
202
203
function check_channels ()
{
declare -a arr=("36" "40")
for i in "${arr[@]}"
do
	sed -i "s/^channel=.*/channel=$i/" /etc/hostapd.conf
204
205
	check_hostapd "Probing" "\nChannel:\Z1 ${i}\Z0"
	if [[ "$hostapd_error" != "channel_restriction" ]]; then break; fi
206
207
208
done
}

209

Igor Pecovnik's avatar
Igor Pecovnik committed
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
#-----------------------------------------------------------------------------------------------------------------------------------------#
#
# show description for MOTD files
#
function description
{
	case $1 in
		*header*)
			echo "Big board logo and kernel info"
		;;
		*sysinfo*)
			echo "Sysinfo - load, ip, memory, uptime, ..."
		;;
		*tips*)
			echo "Shows tip of the day"
		;;
		*updates*)
			echo "Display number of avaliable updates"
		;;
		*armbian-config*)
			echo "Show command for system configuration"
		;;
		*autoreboot-warn*)
			echo "Show warning when reboot is needed"
		;;
235
236
237
238
239
240
		*uk.armbian.com*)
			echo "United Kingdom"
		;;
		*.armbian.com*)
			echo "Estonia"
		;;
Igor Pecovnik's avatar
Igor Pecovnik committed
241
242
243
244
245
246
247
		*)
		echo ""
		;;
	esac
}


248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit ip address witing network manager
#
function nm_ip_editor ()
{
exec 3>&1
	dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
	\n " 12 38 0 \
	"Address:"				1 1 "$address"				1 15 15 0 \
	"Netmask:"			2 1 "$netmask"	2 15 15 0 \
	"Gateway:"			3 1 "$gateway"			3 15 15 0 \
	2>&1 1>&3 | {
		read -r address;read -r netmask;read -r gateway
		if [[ $? = 0 ]]; then
				localuuid=$(LC_ALL=C nmcli -f UUID,DEVICE connection show | grep $1 | awk '{print $1}')
263
264
265
266
				nmcli con mod $localuuid ipv4.method manual ipv4.addresses "$address/$netmask" >/dev/null 2>&1
				nmcli con mod $localuuid ipv4.method manual ipv4.gateway  "$gateway" >/dev/null 2>&1
				nmcli con mod $localuuid ipv4.dns "8.8.8.8,$gateway" >/dev/null 2>&1
				nmcli con down $localuuid >/dev/null 2>&1
267
				sleep 2
268
				nmcli con up $localuuid >/dev/null 2>&1
269
270
271
272
273
274
275
276
		fi
		}
}


#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit ip address
#
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
function systemd_ip_editor ()
{
local filename="/etc/systemd/network/10-$1.network"
if [[ -f $filename ]]; then
sed -i '/Network/,$d' $filename
exec 3>&1
	dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
	\n " 12 38 0 \
	"Address:"				1 1 "$address"				1 15 15 0 \
	"Netmask:"			2 1 "$netmask"	2 15 15 0 \
	"Gateway:"			3 1 "$gateway"			3 15 15 0 \
	2>&1 1>&3 | {
		read -r address;read -r netmask;read -r gateway
		if [[ $? = 0 ]]; then
				echo -e "[Network]" >>$filename
				echo -e "Address=$address" >> $filename
				echo -e "Gateway=$gateway" >> $filename
				echo -e "DNS=8.8.8.8" >> $filename
		fi
		}
fi
}


Igor Pecovnik's avatar
Igor Pecovnik committed
301
302
303
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit ip address
#
Igor Pecovnik's avatar
RC1    
Igor Pecovnik committed
304
305
306
307
308
309
310
311
312
313
314
function ip_editor ()
{
	exec 3>&1
	dialog --title " Static IP configuration" --backtitle "$BACKTITLE" --form "\nAdapter: $1
	\n " 12 38 0 \
	"Address:"				1 1 "$address"				1 15 15 0 \
	"Netmask:"			2 1 "$netmask"	2 15 15 0 \
	"Gateway:"			3 1 "$gateway"			3 15 15 0 \
	2>&1 1>&3 | {
		read -r address;read -r netmask;read -r gateway
		if [[ $? = 0 ]]; then
315
316
				echo -e "# armbian-config created\nsource /etc/network/interfaces.d/*\n" >$3
				echo -e "# Local loopback\nauto lo\niface lo inet loopback\n" >> $3
317
				echo -e "# Interface $2\nauto $2\nallow-hotplug $2\niface $2 inet static\
318
				\n\taddress $address\n\tnetmask $netmask\n\tgateway $gateway\n\tdns-nameservers 8.8.8.8" >> $3
Igor Pecovnik's avatar
RC1    
Igor Pecovnik committed
319
320
321
322
323
		fi
		}
}


Igor Pecovnik's avatar
Igor Pecovnik committed
324
325
326
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit hostapd parameters
#
327
function wlan_edit_basic ()
Igor Pecovnik's avatar
Igor Pecovnik committed
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
{
	source /etc/hostapd.conf
	exec 3>&1
	dialog --title "AP configuration" --backtitle "$BACKTITLE" --form "\nWPA2 enabled, \
	advanced config: edit /etc/hostapd.conf\n " 12 58 0 \
	"SSID:"				1 1 "$ssid"				1 31 22 0 \
	"Password:"			2 1 "$wpa_passphrase"	2 31 22 0 \
	"Channel:"			3 1 "$channel"			3 31 3 0 \
	2>&1 1>&3 | {
		read -r ssid;read -r wpa_passphrase;read -r channel
		if [[ $? = 0 ]]; then
				sed -i "s/^ssid=.*/ssid=$ssid/" /etc/hostapd.conf
				sed -i "s/^wpa_passphrase=.*/wpa_passphrase=$wpa_passphrase/" /etc/hostapd.conf
				sed -i "s/^channel=.*/channel=$channel/" /etc/hostapd.conf
				wpa_psk=$(wpa_passphrase $ssid $wpa_passphrase | grep '^[[:blank:]]*[^[:blank:]#;]' | grep psk | cut -d= -f2-)
				sed -i "s/^wpa_psk=.*/wpa_psk=$wpa_psk/" /etc/hostapd.conf
		fi
		}
}

Igor Pecovnik's avatar
Igor Pecovnik committed
348

349
350
351
352
353
#-----------------------------------------------------------------------------------------------------------------------------------------#
# edit hostapd parameters
#
function wlan_edit ()
{
Igor Pecovnik's avatar
Igor Pecovnik committed
354
355
356
357
358
359
360
361
362
363
364
	# select default interfaces if there is more than one
	select_default_interface
	dialog --title " Configuration edit " --colors --backtitle "$BACKTITLE" --help-button --help-label "Cancel" --yes-label "Basic" \
	--no-label "Advanced" --yesno "\n\Z1Basic:\Z0    Change SSID, password and channel\n\n\Z1Advanced:\Z0 Edit /etc/hostapd.conf file" 9 70
	if [[ $? = 0 ]]; then
		wlan_edit_basic
	elif [[ $? = 1 ]]; then
		dialog --backtitle "$BACKTITLE" --title " Edit hostapd configuration /etc/hostapd.conf" --no-collapse \
		--ok-label "Save" --editbox /etc/hostapd.conf 30 0 2> /etc/hostapd.conf.out
		[[ $? = 0 ]] && mv /etc/hostapd.conf.out /etc/hostapd.conf && service hostapd restart
	fi
365
366
}

Igor Pecovnik's avatar
Igor Pecovnik committed
367
368
369
370
371
372
373
374

#-----------------------------------------------------------------------------------------------------------------------------------------#
# naming exceptions for packages
#
function exceptions ()
{
	TARGET_FAMILY=$LINUXFAMILY
	UBOOT_BRANCH=$TARGET_BRANCH # uboot naming is different
Igor Pecovnik's avatar
Igor Pecovnik committed
375
376

	if [[ $TARGET_BRANCH == "default" ]]; then TARGET_BRANCH=""; else TARGET_BRANCH="-"$TARGET_BRANCH; fi
377
378
379
380
381
	# pine64
	if [[ $TARGET_FAMILY == pine64 ]]; then
		TARGET_FAMILY="sunxi64"
	fi
	# allwinner legacy kernels
Igor Pecovnik's avatar
Igor Pecovnik committed
382
383
384
385
386
387
	if [[ $TARGET_FAMILY == sun*i ]]; then
		TARGET_FAMILY="sunxi"
		if [[ $UBOOT_BRANCH == "default" ]]; then
			TARGET_FAMILY=$(cat /proc/cpuinfo | grep "Hardware" | sed 's/^.*Allwinner //' | awk '{print $1;}')
		fi
	fi
Igor Pecovnik's avatar
Igor Pecovnik committed
388
389
390
391
392
393
394
395
}


#-----------------------------------------------------------------------------------------------------------------------------------------#
# here we add wifi exceptions
#
function wlan_exceptions ()
{
396
	reboot_module=false
Igor Pecovnik's avatar
Igor Pecovnik committed
397
398
399
400
	[[ -n "$(lsmod | grep -w dhd)" && $1 = "on" ]] && \
	echo 'options dhd op_mode=2' >/etc/modprobe.d/ap6212.conf && rmmod dhd && modprobe dhd
	[[ -n "$(lsmod | grep -w dhd)" && $1 = "off" ]] && \
	rm /etc/modprobe.d/ap6212.conf && rmmod dhd && modprobe dhd
401
402
403
404
405
406
	# Cubietruck
	[[ -n "$(lsmod | grep -w ap6210)" && $1 = "on" ]] && \
	echo 'options ap6210 op_mode=2' >/etc/modprobe.d/ap6210.conf && reboot_module=true
	[[ -n "$(lsmod | grep -w ap6210)" && $1 = "off" ]] && \
	rm /etc/modprobe.d/ap6210.conf && reboot_module=true

Igor Pecovnik's avatar
Igor Pecovnik committed
407
408
}

409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#-----------------------------------------------------------------------------------------------------------------------------------------#
# here add shaddy wifi adaptors
#
function check_and_warn ()
{
local shaddy=false
# blacklist
[[ "$LINUXFAMILY" == "sun8i" && $BOARD == "orangepizero" ]] && shaddy=true
[[ -n "$(lsmod | grep mt7601u)" ]] && shaddy=true
[[ -n "$(lsmod | grep r8188eu)" ]] && shaddy=true
# blacklist
if [[ "$shaddy" == "true" ]]; then
dialog --title " Warning " --ok-label " Accept and proceed " --msgbox '\nOne of your wireless drivers are on a black list due to poor quality.\n\nAP mode might not be possible!' 9 73
fi
}

Igor Pecovnik's avatar
Igor Pecovnik committed
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444

#-----------------------------------------------------------------------------------------------------------------------------------------#
# check if board has alternative kernels
#
function aval_kernel ()
{
	IFS=$'\r\n'
	GLOBIGNORE='*'
	AVAL_KERNEL=($(apt-cache search --names-only '^linux-'$(lsb_release	 -cs)'-root.*.'$BOARD'*' \
	| grep -w "$BOARD " | sed 's/.*(\(.*\))/\1/' | awk '{print $1}' | grep -v "$BRANCH" ))
	local LIST=()
	for i in "${AVAL_KERNEL[@]}"
	do
			LIST+=( "${i[0]//[[:blank:]]/}" "" )
	done
	LIST_LENGHT=$((${#LIST[@]}/2));
	if [ "$LIST_LENGHT" -eq 1 ]; then
			TARGET_BRANCH=${AVAL_KERNEL[0]}
	else
			exec 3>&1
445
			TARGET_BRANCH=$(dialog --cancel-label "Cancel" --backtitle "$BACKTITLE" --no-collapse \
Igor Pecovnik's avatar
Igor Pecovnik committed
446
			--title "Upgrade from $BRANCH to:" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
447
			exitstatus=$?;
Igor Pecovnik's avatar
Igor Pecovnik committed
448
449
450
451
452
			exec 3>&-
	fi
}


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
#-----------------------------------------------------------------------------------------------------------------------------------------#
# check if board has alternative kernels
#
function aval_cubox ()
{
	LIST=("imx6dl-hummingboard.dtb" "HB Solo/DualLite" "imx6dl-hummingboard-emmc-som-v15.dtb" "HB Solo/DualLite v1.5 with eMMC" "imx6dl-hummingboard-som-v15.dtb" "HB Solo/DualLite v1.5" \
	"imx6dl-hummingboard2.dtb" "HB2 Solo/DualLite" "imx6dl-hummingboard2-emmc-som-v15.dtb" "HB2 Solo/DualLite v1.5 with eMMC" "imx6dl-hummingboard2-som-v15.dtb" "HB2 Solo/DualLite v1.5" \
	"imx6q-hummingboard.dtb" "HB Dual/Quad" "imx6q-hummingboard-emmc-som-v15.dtb" "HB Dual/Quad v1.5 with eMMC" "imx6q-hummingboard-som-v15.dtb" "HB Dual/Quad v1.5" \
	"imx6q-hummingboard2.dtb" "HB2 Dual/Quad" "imx6q-hummingboard2-emmc-som-v15.dtb" "HB2 Dual/Quad v1.5 with eMMC" "imx6q-hummingboard2-som-v15.dtb" "HB2 Dual/Quad v1.5" \
	"imx6dl-cubox-i.dtb" "Cubox-i Solo/DualLite" "imx6dl-cubox-i-emmc-som-v15.dtb" "Cubox-i Solo/DualLite v1.5 with eMMC" "imx6dl-cubox-i-som-v15.dtb" "Cubox-i Solo/DualLite v1.5" \
	"imx6q-cubox-i.dtb" "Cubox-i Dual/Quad" "imx6q-cubox-i-emmc-som-v15.dtb" "Cubox-i Dual/Quad v1.5 with eMMC" "imx6q-cubox-i-som-v15.dtb" "Cubox-i Dual/Quad v1.5")

	LIST_LENGHT=$((${#LIST[@]}/2));
	if [ "$LIST_LENGHT" -eq 1 ]; then
			TARGET_BOARD=${AVAL_KERNEL[0]}
	else
			exec 3>&1
			TARGET_BOARD=$(dialog --cancel-label "Cancel" --backtitle "$BACKTITLE" --no-collapse \
			--title "Select board configuration" --clear --menu "" $((6+${LIST_LENGHT})) 80 25 "${LIST[@]}" 2>&1 1>&3)
			exitstatus=$?;
			exec 3>&-
	fi
}


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
#-----------------------------------------------------------------------------------------------------------------------------------------#
# select video modes for a10 and a20
#
function get_a20modes ()
{
	IFS=$'\r'
	GLOBIGNORE='*'
	SCREEN_RESOLUTION=("1920x1080p60" "1280x720p60" "1920x1080p50" "1280x1024p60" "1024x768p60" "800x600p60" "640x480p60" "1360x768p60" "1440x900p60" "1680x1050p60")
	local LIST=()
	for i in "${SCREEN_RESOLUTION[@]}"
	do
			LIST+=( "${i[0]//[[:blank:]]/}" "" )
	done
	LIST_LENGHT=$((${#LIST[@]}/2));
	#echo $LIST_LENGHT
	#exit
	if [ "$LIST_LENGHT" -eq 1 ]; then
			SCREEN_RESOLUTION=${SCREEN_RESOLUTION[0]}
	else
			exec 3>&1
			SCREEN_RESOLUTION=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
			--title "Select video mode" --clear --menu "" $((6+${LIST_LENGHT})) 25 $((1+${LIST_LENGHT})) "${LIST[@]}" 2>&1 1>&3)
			exec 3>&-
	fi
}


505
#-----------------------------------------------------------------------------------------------------------------------------------------#
Igor Pecovnik's avatar
Igor Pecovnik committed
506
# select video modes for h3
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
#
function get_h3modes ()
{
	IFS=$'\r\n'
	GLOBIGNORE='*'
	SCREEN_RESOLUTION=($(h3disp -i))
	local LIST=()
	for i in "${SCREEN_RESOLUTION[@]}"
	do
			LIST+=( "${i[0]//[[:blank:]]/}" "" )
	done
	LIST_LENGHT=$((${#LIST[@]}/2));
	#echo $LIST_LENGHT
	#exit
	if [ "$LIST_LENGHT" -eq 1 ]; then
			SCREEN_RESOLUTION=${SCREEN_RESOLUTION[0]}
	else
			exec 3>&1
			SCREEN_RESOLUTION=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
			--title "Select video mode" --clear --menu "" $((6+${LIST_LENGHT})) 25 $((1+${LIST_LENGHT})) "${LIST[@]}" 2>&1 1>&3)
			exec 3>&-
	fi
}

531
function add_choose_user ()
532
#-----------------------------------------------------------------------------------------------------------------------------------------#
533
# create or pick unprivileged user
534
535
536
537
538
539
540
541
542
543
544
545
546
#
{
	IFS=$'\r\n'
	GLOBIGNORE='*'

	local USERS=($(awk -F'[/:]' '{if ($3 >= 1000 && $3 != 65534) print $1}' /etc/passwd))
	local LIST=()
	for i in "${USERS[@]}"
	do
			LIST+=( "${i[0]//[[:blank:]]/}" "" )
	done
	LIST_LENGHT=$((${#LIST[@]}/2));

547
548
549
550
551
552
553
554
555
556
557
558
	if [ "$LIST_LENGHT" -eq 0 ]; then
		dialog --backtitle "$BACKTITLE" --title " Notice " --msgbox "\nWe didn't find any unprivileged user with sudo rights which is required to run this service.\
		\n\nPress enter to create one!" 10 48
		read -t 0 temp
		echo -e "\nPlease provide a username (eg. your forename) or leave blank for canceling user creation: \c"
		read -e username
		CHOSEN_USER="$(echo "$username" | tr '[:upper:]' '[:lower:]' | tr -d -c '[:alnum:]')"
		[ -z "$CHOSEN_USER" ] && return
		echo "Trying to add user $CHOSEN_USER"
		adduser $CHOSEN_USER || return
	elif [ "$LIST_LENGHT" -eq 1 ]; then
			CHOSEN_USER=${USERS[0]}
559
560
	else
			exec 3>&1
561
562
			CHOSEN_USER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
			--title "Select unprivileged user" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
563
564
			exec 3>&-
	fi
565
}
566

Igor Pecovnik's avatar
Igor Pecovnik committed
567

568
569
570
571
572
573
574
575
576
577
#-----------------------------------------------------------------------------------------------------------------------------------------#
# configure armbian desktop
#
function configure_desktop ()
{
	add_choose_user

	if [ -n "$CHOSEN_USER" ]; then
		# install desktop and nodm
		debconf-apt-progress -- apt-get update
578
		debconf-apt-progress -- apt-get -y install armbian-${DISTROID}-desktop
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
		DEBIAN_FRONTEND=noninteractive debconf-apt-progress -- apt-get -y -qq install nodm
		# add user to groups
		for additionalgroup in sudo netdev audio video dialout plugdev bluetooth systemd-journal ssh; do
				usermod -aG ${additionalgroup} ${CHOSEN_USER} 2>/dev/null
		done

		# fix for gksu in Xenial
		touch /home/${CHOSEN_USER}/.Xauthority
		cp -R /etc/skel/. /home/${CHOSEN_USER}

		# set up profile sync daemon on desktop systems
		which psd >/dev/null 2>&1
		if [ $? -eq 0 ]; then
			echo "${CHOSEN_USER} ALL=(ALL) NOPASSWD: /usr/bin/psd-overlay-helper" >> /etc/sudoers
			touch /home/${CHOSEN_USER}/.activate_psd
		fi
595

596
597
598
599
600
601
602
		sed -i "s/NODM_USER=\(.*\)/NODM_USER=${CHOSEN_USER}/" /etc/default/nodm
		sed -i "s/NODM_ENABLED=\(.*\)/NODM_ENABLED=true/g" /etc/default/nodm
		chown -R ${CHOSEN_USER}:${CHOSEN_USER} /home/${CHOSEN_USER}/.
		sleep 3
		service nodm stop
		sleep 1
		service nodm start
603
604
605
606
	fi
}


Igor Pecovnik's avatar
Igor Pecovnik committed
607
608
609
610
611
612
613
#-----------------------------------------------------------------------------------------------------------------------------------------#
# search for wlan interfaces and provide a selection menu if there are more than one
#
function get_wlan_interface ()
{
	IFS=$'\r\n'
	GLOBIGNORE='*'
614

615
	WLAN_INTERFACES=($(LC_ALL=C nmcli --wait 10 dev status | grep wifi | grep disconnected |awk '{print $1}'))
Igor Pecovnik's avatar
Igor Pecovnik committed
616
617
618
619
620
621
	local LIST=()
	for i in "${WLAN_INTERFACES[@]}"
	do
			LIST+=( "${i[0]//[[:blank:]]/}" "" )
	done
	LIST_LENGHT=$((${#LIST[@]}/2));
622

Igor Pecovnik's avatar
Igor Pecovnik committed
623
624
625
626
627
	if [ "$LIST_LENGHT" -eq 1 ]; then
			WIRELESS_ADAPTER=${WLAN_INTERFACES[0]}
	else
			exec 3>&1
			WIRELESS_ADAPTER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
628
			--title "Select interface" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
Igor Pecovnik's avatar
Igor Pecovnik committed
629
630
631
632
633
			exec 3>&-
	fi
}


Igor Pecovnik's avatar
Igor Pecovnik committed
634
635
636
637
638
639
640
#-----------------------------------------------------------------------------------------------------------------------------------------#
# select interface if there is more than one
#
function select_default_interface ()
{
	IFS=$'\r\n'
	GLOBIGNORE='*'
641
	local ADAPTER=($(ls /sys/class/net | grep -E -v 'lo|tun|bonding_masters|dummy0|bond0|sit0'))
Igor Pecovnik's avatar
Igor Pecovnik committed
642
643
644
	local LIST=()
	for i in "${ADAPTER[@]}"
	do
645
			local IPADDR=$(ip -4 addr show dev ${i[0]} | awk '/inet/ {print $2}' | cut -d'/' -f1)
646
			[[ -n $IPADDR && $IPADDR != "172.24.1.1" ]] &&	LIST+=( "${i[0]//[[:blank:]]/}" "${IPADDR}" )
Igor Pecovnik's avatar
Igor Pecovnik committed
647
648
	done
	LIST_LENGHT=$((${#LIST[@]}/2));
649
650
651
	if [ "$LIST_LENGHT" -eq 0 ]; then
			DEFAULT_ADAPTER="lo"
	elif [ "$LIST_LENGHT" -eq 1 ]; then
Igor Pecovnik's avatar
Igor Pecovnik committed
652
653
654
655
			DEFAULT_ADAPTER=${ADAPTER[0]}
	else
			exec 3>&1
			DEFAULT_ADAPTER=$(dialog --nocancel --backtitle "$BACKTITLE" --no-collapse \
656
			--title "Select default interface" --clear --menu "" $((6+${LIST_LENGHT})) 40 15 "${LIST[@]}" 2>&1 1>&3)
Igor Pecovnik's avatar
Igor Pecovnik committed
657
658
659
660
661
			exec 3>&-
	fi
}


Igor Pecovnik's avatar
Igor Pecovnik committed
662
#-----------------------------------------------------------------------------------------------------------------------------------------#
Igor Pecovnik's avatar
Igor Pecovnik committed
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
# search for BT devices and connect
#
function connect_bt_interface ()
{
		IFS=$'\r\n'
		GLOBIGNORE='*'
		dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nDiscovering Bluetooth devices ... " 5 37
		BT_INTERFACES=($(hcitool scan | sed '1d'))

		local LIST=()
		for i in "${BT_INTERFACES[@]}"
		do
			local a=$(echo ${i[0]//[[:blank:]]/} | sed -e 's/^\(.\{17\}\).*/\1/')
			local b=${i[0]//$a/}
			local b=$(echo $b | sed -e 's/^[ \t]*//')
			LIST+=( "$a" "$b")
		done

		LIST_LENGHT=$((${#LIST[@]}/2));
		if [ "$LIST_LENGHT" -eq 0 ]; then
			BT_ADAPTER=${WLAN_INTERFACES[0]}
			dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nNo nearby Bluetooth devices were found!" 7 43
		else
			exec 3>&1
			BT_ADAPTER=$(dialog --backtitle "$BACKTITLE" --no-collapse --title "Select interface" \
			--clear --menu "" $((6+${LIST_LENGHT})) 50 15 "${LIST[@]}" 2>&1 1>&3)
			exec 3>&-
			if [[ $BT_ADAPTER != "" ]]; then
				dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nConnecting to $BT_ADAPTER " 5 35
Igor Pecovnik's avatar
Igor Pecovnik committed
692
693
694
695
696
				BT_EXEC=$(
				expect -c 'set prompt "#";set address '$BT_ADAPTER';spawn bluetoothctl;expect -re $prompt;send "disconnect $address\r";
				sleep 1;send "remove $address\r";sleep 1;expect -re $prompt;send "scan on\r";sleep 8;send "scan off\r";
				expect "Controller";send "trust $address\r";sleep 2;send "pair $address\r";sleep 2;send "connect $address\r";
				send_user "\nShould be paired now.\r";sleep 2;send "quit\r";expect eof')
Igor Pecovnik's avatar
Igor Pecovnik committed
697
698
699
700
701
702
703
704
705
706
				echo "$BT_EXEC" > /tmp/bt-connect-debug.log
					if [[ $(echo "$BT_EXEC" | grep "Connection successful" ) != "" ]]; then
						dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nYour device is ready to use!" 7 32
					else
						dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nError connecting. Try again!" 7 32
					fi
			fi
		fi
}

Igor Pecovnik's avatar
Igor Pecovnik committed
707

708
709
710
711
712
713






Igor Pecovnik's avatar
Igor Pecovnik committed
714
#-----------------------------------------------------------------------------------------------------------------------------------------#
Igor Pecovnik's avatar
Igor Pecovnik committed
715
# system
Igor Pecovnik's avatar
Igor Pecovnik committed
716
#
Igor Pecovnik's avatar
Igor Pecovnik committed
717
function submenu_settings ()
Igor Pecovnik's avatar
Igor Pecovnik committed
718
719
720
721
722
{
while true; do

	LIST=()

723
724
725
726
727
728
729
730
	# detect desktop
	DISPLAY_MANAGER=""; DESKTOP_INSTALLED=""
	check_if_installed nodm && DESKTOP_INSTALLED="nodm";
	check_if_installed lightdm && DESKTOP_INSTALLED="lightdm";
	[[ -n $(service lightdm status 2> /dev/null | grep -w active) ]] && DISPLAY_MANAGER="lightdm"
	[[ -n $(service nodm status 2> /dev/null | grep -w active) ]] && DISPLAY_MANAGER="nodm"


731
732
	local mark=$(apt-mark showhold | grep -w "$BOARD")

733
734
	[[ $(sed -n 's/^DEVNAME=//p' /sys/dev/block/$(mountpoint -d /)/uevent 2> /dev/null) == mmcblk* && -f /usr/sbin/nand-sata-install ]] \
	&& LIST+=( "Install" "Install to SATA, eMMC, NAND or USB" )
735
	if [[ -n "${mark}" ]]; then
Igor Pecovnik's avatar
Wording    
Igor Pecovnik committed
736
			LIST+=( "Defreeze" "Enable kernel upgrades" )
737
		else
Igor Pecovnik's avatar
Wording    
Igor Pecovnik committed
738
			LIST+=( "Freeze" "Disable kernel upgrades" )
739
740
741
742
743
744
745
746
747
748
749
	fi
	if [[ -z $(apt-mark showhold | grep -w "$BOARD") ]]; then
	[[ -f /etc/apt/sources.list.d/armbian.list ]] && [[ -n $(grep -w apt /etc/apt/sources.list.d/armbian.list) ]] \
		&& LIST+=( "Nightly" "Switch to nightly automated builds" )
	[[ -f /etc/apt/sources.list.d/armbian.list ]] && [[ -n $(grep -w beta /etc/apt/sources.list.d/armbian.list) ]] \
		&& LIST+=( "Stable" "Switch to stable builds" )
	fi
	[[ -n $(grep -w "#kernel.printk" /etc/sysctl.conf ) ]] && LIST+=( "Lowlevel" "Stop low-level messages on console" )
	[[ -f /boot/armbianEnv.txt ]] && LIST+=( "Bootenv" "Edit boot environment" )
	[[ -f /boot/boot.ini ]] && LIST+=( "Bootscript" "Edit boot script" )

750
	[[ -d ${OVERLAYDIR} ]] && \
751
	LIST+=( "Hardware" "Toggle hardware configuration: UART, I2C, etc." )
752
	[[ "$LINUXFAMILY" = cubox && "$BRANCH" = "next" ]] && LIST+=( "DTB" "Switch board .dtb configuration" )
753
754
	[[ -f /usr/bin/bin2fex && "$LINUXFAMILY" = sun*i && "$BRANCH" = "default" ]] && LIST+=( "Fexedit" "Board (fex) settings editor" )
	[[ $(apt-cache search --names-only '^linux-'$(lsb_release  -cs)'-root.*.'$BOARD'' | sed 's/.*(\(.*\))/\1/' | awk '{print $1}' \
755
	| wc -l) -gt 1 && -z "${mark}" ]] && LIST+=( "Switch" "Switch to alternative kernels" )
756
757


Igor Pecovnik's avatar
Igor Pecovnik committed
758
	LIST+=( "SSH" "Reconfigure SSH daemon" )
759
	LIST+=( "Firmware" "Run apt update & apt upgrade" )
760
761
	[[ "$LINUXFAMILY" = sun*i && "$BRANCH" = "default" && \
	-n $(bin2fex </boot/script.bin 2>/dev/null | grep -w "hdmi_used = 1") ]] && LIST+=( "Display" "set the display resolution" )
Igor Pecovnik's avatar
Igor Pecovnik committed
762

Igor Pecovnik's avatar
Igor Pecovnik committed
763
764
765
766
767

	if [[ -n $DISPLAY_MANAGER ]]; then
			LIST+=( "Desktop" "Disable desktop" )
			[[ $DISPLAY_MANAGER == 'nodm' ]] && 			LIST+=( "Lightdm" "Switch to standard login manager" )
			[[ $DISPLAY_MANAGER == 'lightdm' ]] && 			LIST+=( "Nodm" "Switch to simple auto login manager" )
768
769
770
771
772
773
	else
			if [[ -n $DESKTOP_INSTALLED ]]; then
				LIST+=( "Desktop" "Enable desktop" )
				else
				LIST+=( "Desktop" "Install desktop" )
			fi
Igor Pecovnik's avatar
Igor Pecovnik committed
774
775
	fi

Igor Pecovnik's avatar
Igor Pecovnik committed
776
777
778
779
780
781
782
783
784
785
786
	if [[ "$DISTRO" == "Ubuntu" && "$(modinfo overlay > /dev/null 2>&1; echo $?)" == "0" ]]; then
		if [ -n "$(mount | grep -w tmpfs-root)" ]; then
			LIST+=( "Overlayroot" "Disable virtual read-only root filesystem" )
		else
			LIST+=( "Overlayroot" "Enable virtual read-only root filesystem" )
		fi
	fi

	# count number of menu items to adjust window sizee
	LISTLENGHT="$((6+${#LIST[@]}/2))"
	BOXLENGHT=${#LIST[@]}
Igor Pecovnik's avatar
Igor Pecovnik committed
787
788

	exec 3>&1
Igor Pecovnik's avatar
Igor Pecovnik committed
789
	selection=$(dialog --colors --backtitle "$BACKTITLE" --title " System settings " --clear \
790
	--cancel-label "Cancel" --menu "$disclaimer" $LISTLENGHT 70 $BOXLENGHT \
Igor Pecovnik's avatar
Igor Pecovnik committed
791
792
793
794
	"${LIST[@]}" 2>&1 1>&3)
	exit_status=$?
	exec 3>&-
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && break
Igor Pecovnik's avatar
Igor Pecovnik committed
795
796

	# run main function
Igor Pecovnik's avatar
Igor Pecovnik committed
797
798
799
800
	jobs "$selection"
done
}

Igor Pecovnik's avatar
Igor Pecovnik committed
801

Igor Pecovnik's avatar
Igor Pecovnik committed
802
803
804
805
806
#-----------------------------------------------------------------------------------------------------------------------------------------#
# menu for networking
#
function submenu_networking ()
{
Igor Pecovnik's avatar
Igor Pecovnik committed
807
808

# if there is more than one connected device
809
select_default_interface
Igor Pecovnik's avatar
Igor Pecovnik committed
810

Igor Pecovnik's avatar
Igor Pecovnik committed
811
while true; do
Igor Pecovnik's avatar
Igor Pecovnik committed
812

Igor Pecovnik's avatar
Igor Pecovnik committed
813
	LIST=()
Igor Pecovnik's avatar
Igor Pecovnik committed
814

Igor Pecovnik's avatar
RC1    
Igor Pecovnik committed
815
	LIST+=( "IP" "Select dynamic or edit static IP address" )
Igor Pecovnik's avatar
Igor Pecovnik committed
816
817
818
819
820
821
	HOSTAPDBRIDGE=$(cat /etc/hostapd.conf 2> /dev/null | grep -w "^bridge=br0")
	HOSTAPDSTATUS=$(service hostapd status | grep -w active | grep -w running)
	if [[ -n "$HOSTAPDSTATUS" ]]; then
			HOSTAPDINFO=$(hostapd_cli get_config 2> /dev/null | grep ^ssid | sed 's/ssid=//g')
			HOSTAPDCLIENTS=$(hostapd_cli all_sta 2> /dev/null | grep connected_time | wc -l)
			LIST+=( "Hotspot" "Manage active wireless access point" )
Igor Pecovnik's avatar
Igor Pecovnik committed
822
		else
823
			[[ -n $(LC_ALL=C nmcli device status | grep wifi | grep -w disconnected) ]] && LIST+=( "Hotspot" "Create WiFi access point" )
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
824

Igor Pecovnik's avatar
Igor Pecovnik committed
825
	fi
826

827
828
829
830
831
832
833
834
	if pgrep -x "iperf3" > /dev/null
	then
		LIST+=( "Iperf3" "Disable network throughput tests daemon" )
		else
		LIST+=( "Iperf3" "Enable network throughput tests daemon" )
	fi


835
	if [[ -n $(LC_ALL=C nmcli device status | grep wifi | grep -v unavailable | grep -v unmanaged) ]]; then
836
837
838
839
		LIST+=( "WiFi" "Manage wireless networking" )
	else
		LIST+=( "Clear" "Clear possible blocked interfaces" )
	fi
840
841
842
843
844
845
846
847
	check_if_installed lirc && LIST+=( "Remove IR" "Remove IR support" ) || LIST+=( "IR" "Install IR support" )
	if check_if_installed bluetooth then ; then
			LIST+=( "BT remove" "Remove Bluetooth support" )
			if [[ -n $(service bluetooth status | grep -w active | grep -w running) ]]; then
				[[ $(hcitool dev | sed '1d') != "" ]] && LIST+=( "BT discover" "Discover and connect Bluetooth devices" )
			fi
		else
			LIST+=( "BT install" "Install Bluetooth support" )
Igor Pecovnik's avatar
Igor Pecovnik committed
848
849
	fi

850
851


852
853
	[[ -d /usr/local/vpnclient ]] && LIST+=( "VPN" "Manage Softether VPN client" ) && VPNSERVERIP=$(/usr/local/vpnclient/vpncmd /client localhost /cmd accountlist | grep "VPN Server" |grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | head -1)

Igor Pecovnik's avatar
RC1    
Igor Pecovnik committed
854
	LIST+=( "Advanced" "Edit /etc/network/interfaces" )
Igor Pecovnik's avatar
Igor Pecovnik committed
855
856
	[[ $(ls -1 /etc/NetworkManager/system-connections 2> /dev/null) ]] && \
	LIST+=( "Forget" "Disconnect and forget all wireless connections" )
Igor Pecovnik's avatar
Igor Pecovnik committed
857
858

	# count number of menu items to adjust window sizee
859
	LISTLENGHT="$((12+${#LIST[@]}/2))"
Igor Pecovnik's avatar
Igor Pecovnik committed
860
	BOXLENGHT=${#LIST[@]}
861
	WIFICONNECTED=$(LC_ALL=C nmcli -f NAME,TYPE connection show --active | grep wireless | awk 'NF{NF-=1};1')
Igor Pecovnik's avatar
Igor Pecovnik committed
862

Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
863
	local disclaimer=""
864
865
866

	local ipadd=$(ip -4 addr show dev $DEFAULT_ADAPTER | awk '/inet/ {print $2}' | cut -d'/' -f1)

867
868

	if [[ -n $(LC_ALL=C nmcli device status | grep $DEFAULT_ADAPTER | grep connected) ]]; then
869
		local ifup="\nIP ($DEFAULT_ADAPTER) via Network Manager: \Z1${ipadd}\n\Z0 "
870
	else
871
872
873
874
875
		if [[ -n $(service systemd-networkd status | grep -w active | grep -w running) ]]; then
			local ifup="\nIP ($DEFAULT_ADAPTER) via systemd-networkd: \Z1${ipadd}\n\Z0 "
		else
			local ifup="\nIP ($DEFAULT_ADAPTER) via IFUPDOWN: \Z1${ipadd}\n\Z0 "
		fi
876
	fi
877

878
879
	disclaimer="$ifup"

Igor Pecovnik's avatar
Igor Pecovnik committed
880
	if [[ -n $WIFICONNECTED ]]; then
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
881
		LISTLENGHT=$((LISTLENGHT+2))
882
883
		local connected="\n\Z0Connected to SSID: \Z1${WIFICONNECTED}\n\Z0 "
		disclaimer=$disclaimer"$connected"
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
884
885
	fi

886
887
888
889
890
891
	if [[ -n $VPNSERVERIP ]]; then
		local vpnserverip="\n\Z0Connected to VPN server: \Z1${VPNSERVERIP}\n\Z0 "
		disclaimer=$disclaimer"$vpnserverip"
		LISTLENGHT=$((LISTLENGHT+2))
	fi

Igor Pecovnik's avatar
Igor Pecovnik committed
892
	if [[ -n $HOSTAPDINFO && -n $HOSTAPDSTATUS ]]; then
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
893
		LISTLENGHT=$((LISTLENGHT+2))
Igor Pecovnik's avatar
Igor Pecovnik committed
894
		chpid=$(dmesg | grep $(grep ^interface /etc/hostapd.conf | sed 's/interface=//g') | head -1 | sed 's/\[.*\]//g' | awk '{print $1}')
895
		disclaimer=$disclaimer$"\n\Z0Hotspot SSID: \Z1$HOSTAPDINFO\Zn Band:";
896
		if [[ `grep ^hw_mode=a /etc/hostapd.conf` ]]; then local band="5Ghz"; else band="2.4Ghz"; fi
897
898
		if [[ `grep ^ieee80211n /etc/hostapd.conf` ]]; then local type="N"; fi
		if [[ `grep ^ieee80211ac /etc/hostapd.conf` ]]; then local type="AC"; fi
899
		disclaimer=$disclaimer$" \Z1${band} ${type}\Z0"
900
		[[ ! "$chpid" =~ .*IPv6.* ]] && disclaimer=$disclaimer$"\n\nChip: \Z1${chpid}\Z0";
Igor Pecovnik's avatar
Igor Pecovnik committed
901
		if [ "$HOSTAPDCLIENTS" -gt "0" ]; then disclaimer=$disclaimer$" Connected clients: \Z1$HOSTAPDCLIENTS\Zn"; fi
902
		if [[ ! "$chpid" =~ .*IPv6.* ]]; then LISTLENGHT=$((LISTLENGHT+2)); fi
Igor Pecovnik's avatar
Igor Pecovnik committed
903
		disclaimer=$disclaimer$"\n";
Igor Pecovnik's avatar
Igor Pecovnik committed
904
	fi
905
	disclaimer=$disclaimer"\n\Z1Note\Zn: This tool can be successful only when drivers are in good shape. If autodetection fails, you are on your own.\n "
Igor Pecovnik's avatar
Igor Pecovnik committed
906
907

	exec 3>&1
908
	selection=$(dialog --backtitle "$BACKTITLE" --colors --title " Wired, Wireless, Bluetooth, Hotspot " --clear \
909
	--cancel-label "Cancel" --menu "${disclaimer}" $LISTLENGHT 70 $BOXLENGHT \
Igor Pecovnik's avatar
Igor Pecovnik committed
910
911
912
913
914
	"${LIST[@]}" 2>&1 1>&3)
	exit_status=$?
	exec 3>&-
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && break

Igor Pecovnik's avatar
Igor Pecovnik committed
915
	# run main function
Igor Pecovnik's avatar
Igor Pecovnik committed
916
	jobs "$selection"
917

Igor Pecovnik's avatar
Igor Pecovnik committed
918
919
920
done
}

921

Igor Pecovnik's avatar
Igor Pecovnik committed
922
#-----------------------------------------------------------------------------------------------------------------------------------------#
923
# personal
Igor Pecovnik's avatar
Igor Pecovnik committed
924
#
925
function submenu_personal ()
Igor Pecovnik's avatar
Igor Pecovnik committed
926
927
928
929
{
while true; do

	LIST=()
930
931
	LIST+=( "Timezone" "Change timezone \Z5($(date +%Z))\Z0" )
	LIST+=( "Locales" "Reconfigure language \Z5($(locale | grep LANGUAGE | cut -d= -f2 | cut -d_ -f1))\Z0 and character set" )
932
	LIST+=( "Keyboard" "Change console keyboard layout (\Z5($(cat /etc/default/keyboard | grep XKBLAYOUT | grep -o '".*"' | sed 's/"//g')\Z0)")
933
	LIST+=( "Hostname" "Change your hostname \Z5($(cat /etc/hostname))\Z0" )
934
	[[ -f /etc/apt/sources.list.d/armbian.list ]] && LIST+=( "Mirror" "Change repository server" )
Igor Pecovnik's avatar
Igor Pecovnik committed
935
936
937
	LIST+=( "Welcome" "Toggle welcome screen items" )

	# count number of menu items to adjust window sizee
938
	LISTLENGHT="$((6+${#LIST[@]}/2))"
Igor Pecovnik's avatar
Igor Pecovnik committed
939
940
941
	BOXLENGHT=${#LIST[@]}

	exec 3>&1
942
943
	selection=$(dialog --colors --backtitle "$BACKTITLE" --title "Personal settings" --clear \
	--cancel-label "Cancel" --menu "$disclaimer" $LISTLENGHT 70 $BOXLENGHT \
Igor Pecovnik's avatar
Igor Pecovnik committed
944
945
946
947
	"${LIST[@]}" 2>&1 1>&3)
	exit_status=$?
	exec 3>&-
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && break
948
949

	# run main function
Igor Pecovnik's avatar
Igor Pecovnik committed
950
	jobs "$selection"
951

Igor Pecovnik's avatar
Igor Pecovnik committed
952
done
Igor Pecovnik's avatar
Igor Pecovnik committed
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
}


#-----------------------------------------------------------------------------------------------------------------------------------------#
# software
#
function submenu_software ()
{
while true; do

	LIST=()
	[[ -f /usr/bin/softy ]] && LIST+=( "Softy" "3rd party applications installer" )
	[[ -f /usr/bin/h3consumption && "$LINUXFAMILY" = "sun8i" && "$BRANCH" = "default" ]] && \
	LIST+=( "Consumption" "Control board consumption" )
	[[ -f /usr/bin/armbianmonitor ]] && LIST+=( "Monitor" "Simple CLI board monitoring" )
	[[ -f /usr/bin/armbianmonitor ]] && LIST+=( "Diagnostics" "Send diagnostics" )
969

Igor Pecovnik's avatar
Igor Pecovnik committed
970
971
	if [[ -n $(dpkg -l | grep linux-headers) ]]; then LIST+=( "Headers" "Remove kernel headers" ); else \
	LIST+=( "Headers" "Install kernel headers" ); fi
972
973
974
975
976
977
978
	if [[ -n $DISPLAY_MANAGER ]]; then
			if [[ $(service xrdp status 2> /dev/null | grep -w active) ]]; then
				LIST+=( "RDP" "Disable remote desktop access from Windows" )
				else
				LIST+=( "RDP" "Enable remote desktop access from Windows" )
			fi
	fi
Igor Pecovnik's avatar
Igor Pecovnik committed
979
980
981
982
983
984
985

	# count number of menu items to adjust window sizee
	LISTLENGHT="$((6+${#LIST[@]}/2))"
	BOXLENGHT=${#LIST[@]}

	exec 3>&1
	selection=$(dialog --backtitle "$BACKTITLE" --title "System and 3rd party software" --clear \
986
	--cancel-label "Cancel" --menu "$disclaimer" $LISTLENGHT 70 $BOXLENGHT \
Igor Pecovnik's avatar
Igor Pecovnik committed
987
988
989
990
991
992
993
	"${LIST[@]}" 2>&1 1>&3)
	exit_status=$?
	exec 3>&-
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && break

	# run main function
	jobs "$selection"
994

Igor Pecovnik's avatar
Igor Pecovnik committed
995
done
996
}
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015




DIALOG_CANCEL=1
DIALOG_ESC=255

#-----------------------------------------------------------------------------------------------------------------------------------------#
# gather info about the board and start with loading menu
#
[[ -f /etc/armbian-release ]] && source /etc/armbian-release && ARMBIAN="Armbian $VERSION $IMAGE_TYPE";
DISTRO=$(lsb_release -is)
DISTROID=$(lsb_release -sc)
KERNELID=$(uname -r)
[[ -z "${ARMBIAN// }" ]] && ARMBIAN=$KERNELID
BACKTITLE="Configuration utility, $ARMBIAN, https://www.armbian.com"
TITLE="$BOARD_NAME "
DEFAULT_ADAPTER=$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)')
[[ -z "${DEFAULT_ADAPTER// }" ]] && DEFAULT_ADAPTER="lo"
1016
1017
OVERLAYDIR="/boot/dtb/overlay";
[[ "$LINUXFAMILY" == "sunxi64" ]] && OVERLAYDIR="/boot/dtb/allwinner/overlay";
1018
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nLoading Armbian configuration utility ... " 5 45
1019
sleep 1