debian-config-submenu 14.6 KB
Newer Older
Igor Pecovnik's avatar
Igor Pecovnik committed
1
2
#!/bin/bash
#
Igor Pecovnik's avatar
Igor Pecovnik committed
3
# Copyright (c) 2018 Igor Pecovnik, igor.pecovnik@gma**.com
Igor Pecovnik's avatar
Igor Pecovnik committed
4
5
6
7
8
#
# 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.

9
10
11
12
13
# Functions:
# submenu_settings
# submenu_networking
# submenu_personal
# submenu_software
14

Igor Pecovnik's avatar
Igor Pecovnik committed
15
16
17
18


#
# system settings
Igor Pecovnik's avatar
Igor Pecovnik committed
19
#
Igor Pecovnik's avatar
Igor Pecovnik committed
20
function submenu_settings ()
Igor Pecovnik's avatar
Igor Pecovnik committed
21
{
22
unset main
Igor Pecovnik's avatar
Igor Pecovnik committed
23
24
25
while true; do

	LIST=()
Igor Pecovnik's avatar
Igor Pecovnik committed
26
27
	DIALOG_CANCEL=1
	DIALOG_ESC=255
Igor Pecovnik's avatar
Igor Pecovnik committed
28

29
30
31
	# detect desktop
	check_desktop

Igor Pecovnik's avatar
Igor Pecovnik committed
32
	# check update status of BSP packages
Igor Pečovnik's avatar
Igor Pečovnik committed
33
	local mark=$(apt-mark showhold | egrep "linux|armbian")
34

Igor Pečovnik's avatar
Igor Pečovnik committed
35
	# check if eMMC/SD is on the system
Igor Pecovnik's avatar
Igor Pecovnik committed
36
37
	if [[ $(sed -n 's/^DEVNAME=//p' /sys/dev/block/$(mountpoint -d /)/uevent 2> /dev/null) == mmcblk* \
	&& -f /usr/sbin/nand-sata-install ]]; then
Igor Pečovnik's avatar
Igor Pečovnik committed
38
		LIST+=( "Install" "Install to/update boot loader" )
Igor Pecovnik's avatar
Igor Pecovnik committed
39
40
41
	fi

	# armbian specific function
42
43
	if [[ -f /etc/armbian-release ]]; then
		if [[ -n "${mark}" ]]; then
Igor Pečovnik's avatar
Igor Pečovnik committed
44
				LIST+=( "Defreeze" "Enable Armbian upgrades " )
45
			else
Igor Pečovnik's avatar
Igor Pečovnik committed
46
				LIST+=( "Freeze" "Disable Armbian upgrades " )
47
		fi
48
	fi
Igor Pecovnik's avatar
Igor Pecovnik committed
49
50
51
52

	# armbian specific function, when upgrades are enabled
	if [[ -z ${mark} ]]; then
		[[ -f /etc/apt/sources.list.d/armbian.list ]] && [[ -n $(grep -w apt /etc/apt/sources.list.d/armbian.list) ]] \
53
		&& LIST+=( "Nightly" "Switch to nightly automated builds" )
Igor Pecovnik's avatar
Igor Pecovnik committed
54
		[[ -f /etc/apt/sources.list.d/armbian.list ]] && [[ -n $(grep -w beta /etc/apt/sources.list.d/armbian.list) ]] \
55
56
		&& LIST+=( "Stable" "Switch to stable builds" )
	fi
Igor Pecovnik's avatar
Igor Pecovnik committed
57

58
	[[ -n $(grep -w "#kernel.printk" /etc/sysctl.conf ) ]] && LIST+=( "Lowlevel" "Stop low-level messages on console" )
Igor Pecovnik's avatar
Igor Pecovnik committed
59

60
61
62
	[[ -f /boot/armbianEnv.txt ]] && LIST+=( "Bootenv" "Edit boot environment" )
	[[ -f /boot/boot.ini ]] && LIST+=( "Bootscript" "Edit boot script" )

63
64
65
66
	if [[ -f /etc/default/cpufrequtils ]]; then
		LIST+=( "CPU" "Set CPU speed and governor" )
	fi

67
68
69
70
71
72
73
	AVAHIDSTATUS=$(service avahi-daemon status 2> /dev/null | grep -w active | grep -w running)
	if [[ -n "$AVAHIDSTATUS" ]]; then
		LIST+=( "Avahi" "Disable system announce in the network" )
		else
		LIST+=( "Avahi" "Announce system in the network" )
	fi

74
	[[ -d ${OVERLAYDIR} ]] && \
75
	LIST+=( "Hardware" "Toggle hardware configuration: UART, I2C, etc." )
76
	[[ "$LINUXFAMILY" = cubox && "$BRANCH" = "next" ]] && LIST+=( "DTB" "Switch board .dtb configuration" )
77
78
79
	# this is avaliable only in kernel higher than 4.10
	testvercomp "$(uname -r | sed 's/-.*//')" "4.10.0" ">"
	[[ "$LINUXFAMILY" = odroidxu4 && $? == 0 ]] && LIST+=( "DTB" "Select optimised board configuration" )
80
	[[ -f /usr/bin/bin2fex && "$LINUXFAMILY" = sun*i && "$BRANCH" = "default" ]] && LIST+=( "Fexedit" "Board (fex) settings editor" )
81

Igor Pečovnik's avatar
Igor Pečovnik committed
82
	[[ -z ${mark} ]] && [[ -f /etc/apt/sources.list.d/armbian.list ]] && LIST+=( "Other" "Switch to other kernels" )
83

Igor Pecovnik's avatar
Igor Pecovnik committed
84
	LIST+=( "SSH" "Reconfigure SSH daemon" )
85
	LIST+=( "Firmware" "Run apt update & apt upgrade" )
86
87
88
89

	if [[ "$SHELL" != "/bin/bash" ]]; then
		LIST+=( "BASH" "Revert to stock BASH shell" )
		else
Igor Pečovnik's avatar
Igor Pečovnik committed
90
		LIST+=( "ZSH" "Install ZSH with plugins and tmux" )
91
92
93
	fi


94
	[[ "$LINUXFAMILY" = sun*i && "$BRANCH" = "default" && \
95
96
	-n $(bin2fex </boot/script.bin 2>/dev/null | grep -w "hdmi_used = 1") ]] && LIST+=( "Display" "Set the display resolution" )
	[[ "$LINUXFAMILY" = odroidc* || "$LINUXFAMILY" = odroidn2 && "$BRANCH" = "default" ]] && LIST+=( "Display" "Set the display resolution" )
Igor Pecovnik's avatar
Igor Pecovnik committed
97
	# desktop
Igor Pecovnik's avatar
Igor Pecovnik committed
98
	if [[ -n $DISPLAY_MANAGER ]]; then
Igor Pečovnik's avatar
Igor Pečovnik committed
99
			LIST+=( "Desktop" "Disable desktop or change login type" )
100
101
	else
			if [[ -n $DESKTOP_INSTALLED ]]; then
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
102
					LIST+=( "Desktop" "Enable desktop" )
103
				else
104
					LIST+=( "Default" "Install desktop with browser and extras" )
105
			fi
Igor Pecovnik's avatar
Igor Pecovnik committed
106
107
	fi

Igor Pecovnik's avatar
Igor Pecovnik committed
108
	# overlayroot
Igor Pecovnik's avatar
Igor Pecovnik committed
109
110
111
112
113
114
115
116
	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

JC Staudt's avatar
JC Staudt committed
117
118
119
	# count number of menu items to adjust window size
	LISTLENGTH="$((6+${#LIST[@]}/2))"
	BOXLENGTH=${#LIST[@]}
Igor Pečovnik's avatar
Igor Pečovnik committed
120
121
122
123
124
125
126
127
128
129
130
	temp_rc=$(mktemp)
	if [[ -n ${mark} || -n $(grep -w beta /etc/apt/sources.list.d/armbian.list 2> /dev/null) ]]; then
			cat <<-'EOF' > $temp_rc
			dialog_color = (RED,WHITE,OFF)
			screen_color = (WHITE,RED,ON)
			tag_color = (RED,WHITE,ON)
			item_selected_color = (WHITE,RED,ON)
			tag_selected_color = (WHITE,RED,ON)
			tag_key_selected_color = (WHITE,RED,ON)
			EOF
			[[ -n ${mark} ]] && local sys_title=" Warning - firmware packages frozen"
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
131
132
133
134
			[[ -n $(grep -w beta /etc/apt/sources.list.d/armbian.list 2> /dev/null) ]] && \
			local sys_title=" Warning - attached to beta repository"
			[[ -n ${mark} && -n $(grep -w beta /etc/apt/sources.list.d/armbian.list 2> /dev/null) ]] && \
			sys_title=" Warning - frozen & attached to beta repository"
Igor Pečovnik's avatar
Igor Pečovnik committed
135
136
137
138
139
		else
			local sys_title=" System settings "
			echo > $temp_rc
	fi

140
if [[ -z $selection ]]; then
Igor Pecovnik's avatar
Igor Pecovnik committed
141
	exec 3>&1
Igor Pečovnik's avatar
Igor Pečovnik committed
142
	selection=$(DIALOGRC=$temp_rc dialog --colors --backtitle "$BACKTITLE" --title " $sys_title " --clear \
143
	--cancel-label "Back" --menu "$disclaimer" $LISTLENGTH 0 $BOXLENGTH \
Igor Pecovnik's avatar
Igor Pecovnik committed
144
145
146
147
	"${LIST[@]}" 2>&1 1>&3)
	exit_status=$?
	exec 3>&-
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && break
148
fi
Igor Pecovnik's avatar
Igor Pecovnik committed
149
150

	# run main function
Igor Pecovnik's avatar
Igor Pecovnik committed
151
152
153
154
	jobs "$selection"
done
}

Igor Pecovnik's avatar
Igor Pecovnik committed
155

Igor Pecovnik's avatar
Igor Pecovnik committed
156
157
158


#
Igor Pecovnik's avatar
Igor Pecovnik committed
159
160
161
162
# menu for networking
#
function submenu_networking ()
{
Igor Pecovnik's avatar
Igor Pecovnik committed
163

164
165
# select default interface if there is more than one connected
#select_interface "default"
166
unset main
Igor Pecovnik's avatar
Igor Pecovnik committed
167
while true; do
Igor Pecovnik's avatar
Igor Pecovnik committed
168

Igor Pecovnik's avatar
Igor Pecovnik committed
169
	LIST=()
Igor Pecovnik's avatar
Igor Pecovnik committed
170
171
	DIALOG_CANCEL=1
	DIALOG_ESC=255
Igor Pecovnik's avatar
Igor Pecovnik committed
172

173
174
175
	# check if we have some LTE modems
	for i in $(lsusb | awk '{print $6}'); do lte "$i"; done;

Igor Pecovnik's avatar
Igor Pecovnik committed
176
	# edit ip
Igor Pecovnik's avatar
RC1    
Igor Pecovnik committed
177
	LIST+=( "IP" "Select dynamic or edit static IP address" )
Igor Pecovnik's avatar
Igor Pecovnik committed
178
179

	# hostapd
Igor Pecovnik's avatar
Igor Pecovnik committed
180
	HOSTAPDBRIDGE=$(cat /etc/hostapd.conf 2> /dev/null | grep -w "^bridge=br0")
Igor Pecovnik's avatar
Igor Pecovnik committed
181
	HOSTAPDSTATUS=$(service hostapd status 2> /dev/null | grep -w active | grep -w running)
Igor Pecovnik's avatar
Igor Pecovnik committed
182
183
184
185
	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
186
		else
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
187
188
			[[ -n $(LC_ALL=C nmcli device status 2> /dev/null | grep wifi | grep -w disconnected) ]] && \
			LIST+=( "Hotspot" "Create WiFi access point" )
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
189

Igor Pecovnik's avatar
Igor Pecovnik committed
190
	fi
191

JC Staudt's avatar
JC Staudt committed
192
	# toggle IPv6
Igor Pečovnik's avatar
Igor Pečovnik committed
193
	if [[ $(cat /proc/sys/net/ipv6/conf/all/disable_ipv6) == 1 ]]; then
JC Staudt's avatar
JC Staudt committed
194
			LIST+=( "IPV6" "Enable IPv6 for APT and system" )
Igor Pečovnik's avatar
Igor Pečovnik committed
195
		else
JC Staudt's avatar
JC Staudt committed
196
			LIST+=( "IPV6" "Disable IPv6 for APT and system" )
Igor Pečovnik's avatar
Igor Pečovnik committed
197
198
	fi

Igor Pecovnik's avatar
Igor Pecovnik committed
199
200
201
202
203
204
205
206
	# network throughput test
	if check_if_installed iperf3; then
		if pgrep -x "iperf3" > /dev/null
		then
			LIST+=( "Iperf3" "Disable network throughput tests daemon" )
			else
			LIST+=( "Iperf3" "Enable network throughput tests daemon" )
		fi
207
208
	fi

209
	if [[ -n $(LC_ALL=C nmcli device status 2> /dev/null | grep wifi | grep -v unavailable | grep -v unmanaged) ]]; then
210
211
212
213
		LIST+=( "WiFi" "Manage wireless networking" )
	else
		LIST+=( "Clear" "Clear possible blocked interfaces" )
	fi
214
215
216
217
218
219
220

	if [[ -n $LTE_MODEM ]]; then
		# apply udev rules
		initialize_lte
		LIST+=( "LTE" "$LTE_MODEM" )
	fi

221
222
223
224
225
226
227
228
	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
229
230
	fi

231
232


233
234
	[[ -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
235
	LIST+=( "Advanced" "Edit /etc/network/interfaces" )
Igor Pecovnik's avatar
Igor Pecovnik committed
236
237
	[[ $(ls -1 /etc/NetworkManager/system-connections 2> /dev/null) ]] && \
	LIST+=( "Forget" "Disconnect and forget all wireless connections" )
Igor Pecovnik's avatar
Igor Pecovnik committed
238

JC Staudt's avatar
JC Staudt committed
239
240
241
	# count number of menu items to adjust window size
	LISTLENGTH="$((12+${#LIST[@]}/2))"
	BOXLENGTH=${#LIST[@]}
242
	WIFICONNECTED=$(LC_ALL=C nmcli -f NAME,TYPE connection show --active 2> /dev/null | grep wireless | awk 'NF{NF-=1};1')
Igor Pecovnik's avatar
Igor Pecovnik committed
243

Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
244
	local disclaimer=""
245
246
247

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

248

249
	if [[ -n $(LC_ALL=C nmcli device status 2> /dev/null | grep $DEFAULT_ADAPTER | grep connected) ]]; then
250
		local ifup="\nIP ($DEFAULT_ADAPTER) via Network Manager: \Z1${ipadd}\n\Z0 "
251
	else
252
253
254
255
256
		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
257
	fi
258

259
260
	disclaimer="$ifup"

Igor Pecovnik's avatar
Igor Pecovnik committed
261
	if [[ -n $WIFICONNECTED ]]; then
JC Staudt's avatar
JC Staudt committed
262
		LISTLENGTH=$((LISTLENGTH+2))
263
264
		local connected="\n\Z0Connected to SSID: \Z1${WIFICONNECTED}\n\Z0 "
		disclaimer=$disclaimer"$connected"
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
265
266
	fi

267
268
269
	if [[ -n $VPNSERVERIP ]]; then
		local vpnserverip="\n\Z0Connected to VPN server: \Z1${VPNSERVERIP}\n\Z0 "
		disclaimer=$disclaimer"$vpnserverip"
JC Staudt's avatar
JC Staudt committed
270
		LISTLENGTH=$((LISTLENGTH+2))
271
272
	fi

Igor Pecovnik's avatar
Igor Pecovnik committed
273
	if [[ -n $HOSTAPDINFO && -n $HOSTAPDSTATUS ]]; then
JC Staudt's avatar
JC Staudt committed
274
		LISTLENGTH=$((LISTLENGTH+2))
Igor Pecovnik's avatar
Igor Pecovnik committed
275
		chpid=$(dmesg | grep $(grep ^interface /etc/hostapd.conf | sed 's/interface=//g') | head -1 | sed 's/\[.*\]//g' | awk '{print $1}')
276
		disclaimer=$disclaimer$"\n\Z0Hotspot SSID: \Z1$HOSTAPDINFO\Zn Band:";
277
		if [[ `grep ^hw_mode=a /etc/hostapd.conf` ]]; then local band="5Ghz"; else band="2.4Ghz"; fi
278
279
		if [[ `grep ^ieee80211n /etc/hostapd.conf` ]]; then local type="N"; fi
		if [[ `grep ^ieee80211ac /etc/hostapd.conf` ]]; then local type="AC"; fi
280
		disclaimer=$disclaimer$" \Z1${band} ${type}\Z0"
281
		[[ ! "$chpid" =~ .*IPv6.* ]] && disclaimer=$disclaimer$"\n\nChip: \Z1${chpid}\Z0";
Igor Pecovnik's avatar
Igor Pecovnik committed
282
		if [ "$HOSTAPDCLIENTS" -gt "0" ]; then disclaimer=$disclaimer$" Connected clients: \Z1$HOSTAPDCLIENTS\Zn"; fi
JC Staudt's avatar
JC Staudt committed
283
		if [[ ! "$chpid" =~ .*IPv6.* ]]; then LISTLENGTH=$((LISTLENGTH+2)); fi
Igor Pecovnik's avatar
Igor Pecovnik committed
284
		disclaimer=$disclaimer$"\n";
Igor Pecovnik's avatar
Igor Pecovnik committed
285
	fi
JC Staudt's avatar
JC Staudt committed
286
	disclaimer=$disclaimer"\n\Z1Note\Zn: This tool can be successful only when drivers are configured properly. If auto-detection fails, you are on your own.\n "
Igor Pecovnik's avatar
Igor Pecovnik committed
287

288
if [[ -z $selection ]]; then
Igor Pecovnik's avatar
Igor Pecovnik committed
289
	exec 3>&1
290
	selection=$(dialog --backtitle "$BACKTITLE" --colors --title " Wired, Wireless, Bluetooth, Hotspot " --clear \
JC Staudt's avatar
JC Staudt committed
291
	--cancel-label "Back" --menu "${disclaimer}" $LISTLENGTH 70 $BOXLENGTH \
Igor Pecovnik's avatar
Igor Pecovnik committed
292
293
294
295
	"${LIST[@]}" 2>&1 1>&3)
	exit_status=$?
	exec 3>&-
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && break
296
fi
Igor Pecovnik's avatar
Igor Pecovnik committed
297
	# run main function
Igor Pecovnik's avatar
Igor Pecovnik committed
298
	jobs "$selection"
299

Igor Pecovnik's avatar
Igor Pecovnik committed
300
301
302
done
}

303

Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
304
305
306


#
307
# personal
Igor Pecovnik's avatar
Igor Pecovnik committed
308
#
309
function submenu_personal ()
Igor Pecovnik's avatar
Igor Pecovnik committed
310
{
311
unset main
Igor Pecovnik's avatar
Igor Pecovnik committed
312
313
314
while true; do

	LIST=()
Igor Pečovnik's avatar
Igor Pečovnik committed
315
	LIST+=( "Timezone" "Change timezone \Z5($(LC_ALL=C timedatectl | grep zone | awk '{$1=$1;print}' | sed "s/Time zone: //"))\Z0" )
316
	LIST+=( "Locales" "Reconfigure language \Z5($(locale | grep LANGUAGE | cut -d= -f2 | cut -d_ -f1))\Z0 and character set" )
Igor Pecovnik's avatar
Igor Pecovnik committed
317
	LIST+=( "Keyboard" "Change console keyboard layout (\Z5$(cat /etc/default/keyboard | grep XKBLAYOUT | grep -o '".*"' | sed 's/"//g')\Z0)")
318
	LIST+=( "Hostname" "Change your hostname \Z5($(cat /etc/hostname))\Z0" )
Igor Pečovnik's avatar
Igor Pečovnik committed
319
320
321
	BEFORE="$(cat /etc/apt/sources.list.d/armbian.list | sed 's/http/\nhttp/g' | grep ^http | sed 's/\(^http[^ <]*\)\(.*\)/\1/g' | sed 's/https\?:\/\///')"
	BEFORE_DESC=$(description "${BEFORE}")
	[[ -f /etc/apt/sources.list.d/armbian.list ]] && LIST+=( "Mirror" "Change repository server \Z5(${BEFORE_DESC})\Z0" )
Igor Pecovnik's avatar
Igor Pecovnik committed
322
323
324
	LIST+=( "Welcome" "Toggle welcome screen items" )

	# count number of menu items to adjust window sizee
JC Staudt's avatar
JC Staudt committed
325
326
	LISTLENGTH="$((6+${#LIST[@]}/2))"
	BOXLENGTH=${#LIST[@]}
Igor Pecovnik's avatar
Igor Pecovnik committed
327
328

	exec 3>&1
329
	selection=$(dialog --colors --backtitle "$BACKTITLE" --title "Personal settings" --clear \
JC Staudt's avatar
JC Staudt committed
330
	--cancel-label "Back" --menu "$disclaimer" $LISTLENGTH 70 $BOXLENGTH \
Igor Pecovnik's avatar
Igor Pecovnik committed
331
332
333
334
	"${LIST[@]}" 2>&1 1>&3)
	exit_status=$?
	exec 3>&-
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && break
335
336

	# run main function
Igor Pecovnik's avatar
Igor Pecovnik committed
337
	jobs "$selection"
338

Igor Pecovnik's avatar
Igor Pecovnik committed
339
done
Igor Pecovnik's avatar
Igor Pecovnik committed
340
341
342
}


Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
343
344
345


#
Igor Pecovnik's avatar
Igor Pecovnik committed
346
347
348
349
# software
#
function submenu_software ()
{
350
unset main
Igor Pecovnik's avatar
Igor Pecovnik committed
351
352
while true; do

353
354
355
	# detect desktop
	check_desktop

Igor Pecovnik's avatar
Igor Pecovnik committed
356
	LIST=()
357
	[[ -f /usr/bin/softy || -f softy ]] && LIST+=( "Softy" "3rd party applications installer" )
Igor Pecovnik's avatar
Igor Pecovnik committed
358
359
360
	[[ -f /usr/bin/h3consumption && "$LINUXFAMILY" = "sun8i" && "$BRANCH" = "default" ]] && \
	LIST+=( "Consumption" "Control board consumption" )
	[[ -f /usr/bin/armbianmonitor ]] && LIST+=( "Monitor" "Simple CLI board monitoring" )
Igor Pecovnik's avatar
Igor Pecovnik committed
361
	LIST+=( "Benchmarking" "sbc-bench board benchmarking" )
Igor Pecovnik's avatar
Igor Pecovnik committed
362
	[[ -f /usr/bin/armbianmonitor ]] && LIST+=( "Diagnostics" "Send diagnostics" )
363

Igor Pecovnik's avatar
Igor Pecovnik committed
364
365
	if [[ -n $(dpkg -l | grep linux-headers) ]]; then LIST+=( "Headers" "Remove kernel headers" ); else \
	LIST+=( "Headers" "Install kernel headers" ); fi
366

Igor Pečovnik's avatar
Igor Pečovnik committed
367
	SOURCE_PKG=$(apt-cache --names-only search ^linux-source-* | awk '{ print $1 }' | grep ${BRANCH}-${LINUXFAMILY} | tail -1)
Igor Pecovnik's avatar
Igor Pecovnik committed
368
	if [[ -n $SOURCE_PKG ]]; then
Igor Pecovnik's avatar
Igor Pecovnik committed
369
		if ls /usr/src/linux-source* 1> /dev/null 2>&1; then LIST+=( "Source" "Remove kernel source" ); else \
Igor Pecovnik's avatar
Igor Pecovnik committed
370
371
372
	        LIST+=( "Source" "Install kernel source" ); fi
	fi

Igor Pecovnik's avatar
Igor Pecovnik committed
373
	if [[ -f /etc/armbian.txt ]]; then
Igor Pecovnik's avatar
Bugfix    
Igor Pecovnik committed
374
		if [[ -n $(dpkg -l | grep -w "armbian-firmware-full ") ]]; then
375
376
377
378
379
380
			LIST+=( "Mini" "Install mini firmware package" );
		else
			LIST+=( "Full" "Install full firmware package" );
		fi
	fi

381
382
383
384
385
386
	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
387
			if ! check_if_installed thunderbird ; then
388
389
390
391
				LIST+=( "Thunderbird" "Install full featured email client" )
				else
				LIST+=( "Thunderbird" "Remove full featured email client" )
			fi
392
393
394
395
396
                        if ! check_if_installed gimp ; then
                                LIST+=( "Gimp" "Install photo manipulation tool" )
                                else
                                LIST+=( "Gimp" "Remove photo manipulation tool" )
                        fi
397
			if ! check_if_installed libreoffice-writer ; then
398
399
400
				LIST+=( "Writer" "Libreoffice: Writer only" )
				LIST+=( "Suite" "Libreoffice: Full suite" )
				else
401
					if ! check_if_installed libreoffice-base ; then
402
403
404
405
406
407
						LIST+=( "Suite" "Libreoffice: Full suite" )
						LIST+=( "Libre" "Remove Libre office packages" )
					else
						LIST+=( "Libre" "Remove Libre office packages" )
					fi
			fi
408
	fi
Igor Pecovnik's avatar
Igor Pecovnik committed
409
410

	# count number of menu items to adjust window sizee
JC Staudt's avatar
JC Staudt committed
411
412
	LISTLENGTH="$((6+${#LIST[@]}/2))"
	BOXLENGTH=${#LIST[@]}
Igor Pecovnik's avatar
Igor Pecovnik committed
413

414
if [[ -z $selection ]]; then
Igor Pecovnik's avatar
Igor Pecovnik committed
415
416
	exec 3>&1
	selection=$(dialog --backtitle "$BACKTITLE" --title "System and 3rd party software" --clear \
JC Staudt's avatar
JC Staudt committed
417
	--cancel-label "Back" --menu "$disclaimer" $LISTLENGTH 70 $BOXLENGTH \
Igor Pecovnik's avatar
Igor Pecovnik committed
418
419
420
421
	"${LIST[@]}" 2>&1 1>&3)
	exit_status=$?
	exec 3>&-
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && break
422
fi
Igor Pecovnik's avatar
Igor Pecovnik committed
423
424
425

	# run main function
	jobs "$selection"
426

Igor Pecovnik's avatar
Igor Pecovnik committed
427
done
428
}