debian-config-submenu 11.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

Igor Pecovnik's avatar
Igor Pecovnik committed
11
#-----------------------------------------------------------------------------------------------------------------------------------------#
Igor Pecovnik's avatar
Igor Pecovnik committed
12
# system
Igor Pecovnik's avatar
Igor Pecovnik committed
13
#
Igor Pecovnik's avatar
Igor Pecovnik committed
14
function submenu_settings ()
Igor Pecovnik's avatar
Igor Pecovnik committed
15
16
17
18
19
{
while true; do

	LIST=()

20
21
22
23
24
25
26
27
	# 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"


28
29
	local mark=$(apt-mark showhold | grep -w "$BOARD")

30
31
	[[ $(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" )
32
33
34
35
36
37
	if [[ -f /etc/armbian-release ]]; then
		if [[ -n "${mark}" ]]; then
				LIST+=( "Defreeze" "Enable kernel upgrades" )
			else
				LIST+=( "Freeze" "Disable kernel upgrades" )
		fi
38
39
40
41
42
43
44
45
46
47
48
	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" )

49
	[[ -d ${OVERLAYDIR} ]] && \
50
	LIST+=( "Hardware" "Toggle hardware configuration: UART, I2C, etc." )
51
	[[ "$LINUXFAMILY" = cubox && "$BRANCH" = "next" ]] && LIST+=( "DTB" "Switch board .dtb configuration" )
52
53
	[[ -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}' \
54
	| wc -l) -gt 1 && -z "${mark}" ]] && LIST+=( "Switch" "Switch to alternative kernels" )
55
56


Igor Pecovnik's avatar
Igor Pecovnik committed
57
	LIST+=( "SSH" "Reconfigure SSH daemon" )
58
	LIST+=( "Firmware" "Run apt update & apt upgrade" )
59
60
	[[ "$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
61

Igor Pecovnik's avatar
Igor Pecovnik committed
62
63
64
65
66

	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" )
67
68
69
70
71
72
	else
			if [[ -n $DESKTOP_INSTALLED ]]; then
				LIST+=( "Desktop" "Enable desktop" )
				else
				LIST+=( "Desktop" "Install desktop" )
			fi
Igor Pecovnik's avatar
Igor Pecovnik committed
73
74
	fi

Igor Pecovnik's avatar
Igor Pecovnik committed
75
76
77
78
79
80
81
82
83
84
85
	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
86
87

	exec 3>&1
Igor Pecovnik's avatar
Igor Pecovnik committed
88
	selection=$(dialog --colors --backtitle "$BACKTITLE" --title " System settings " --clear \
89
	--cancel-label "Cancel" --menu "$disclaimer" $LISTLENGHT 70 $BOXLENGHT \
Igor Pecovnik's avatar
Igor Pecovnik committed
90
91
92
93
	"${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
94
95

	# run main function
Igor Pecovnik's avatar
Igor Pecovnik committed
96
97
98
99
	jobs "$selection"
done
}

Igor Pecovnik's avatar
Igor Pecovnik committed
100

Igor Pecovnik's avatar
Igor Pecovnik committed
101
102
103
104
105
#-----------------------------------------------------------------------------------------------------------------------------------------#
# menu for networking
#
function submenu_networking ()
{
Igor Pecovnik's avatar
Igor Pecovnik committed
106
107

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

Igor Pecovnik's avatar
Igor Pecovnik committed
110
while true; do
Igor Pecovnik's avatar
Igor Pecovnik committed
111

Igor Pecovnik's avatar
Igor Pecovnik committed
112
	LIST=()
Igor Pecovnik's avatar
Igor Pecovnik committed
113

Igor Pecovnik's avatar
RC1    
Igor Pecovnik committed
114
	LIST+=( "IP" "Select dynamic or edit static IP address" )
Igor Pecovnik's avatar
Igor Pecovnik committed
115
116
117
118
119
120
	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
121
		else
122
			[[ -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
123

Igor Pecovnik's avatar
Igor Pecovnik committed
124
	fi
125

126
127
128
129
130
131
132
133
	if pgrep -x "iperf3" > /dev/null
	then
		LIST+=( "Iperf3" "Disable network throughput tests daemon" )
		else
		LIST+=( "Iperf3" "Enable network throughput tests daemon" )
	fi


134
	if [[ -n $(LC_ALL=C nmcli device status | grep wifi | grep -v unavailable | grep -v unmanaged) ]]; then
135
136
137
138
		LIST+=( "WiFi" "Manage wireless networking" )
	else
		LIST+=( "Clear" "Clear possible blocked interfaces" )
	fi
139
140
141
142
143
144
145
146
	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
147
148
	fi

149
150


151
152
	[[ -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
153
	LIST+=( "Advanced" "Edit /etc/network/interfaces" )
Igor Pecovnik's avatar
Igor Pecovnik committed
154
155
	[[ $(ls -1 /etc/NetworkManager/system-connections 2> /dev/null) ]] && \
	LIST+=( "Forget" "Disconnect and forget all wireless connections" )
Igor Pecovnik's avatar
Igor Pecovnik committed
156
157

	# count number of menu items to adjust window sizee
158
	LISTLENGHT="$((12+${#LIST[@]}/2))"
Igor Pecovnik's avatar
Igor Pecovnik committed
159
	BOXLENGHT=${#LIST[@]}
160
	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
161

Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
162
	local disclaimer=""
163
164
165

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

166
167

	if [[ -n $(LC_ALL=C nmcli device status | grep $DEFAULT_ADAPTER | grep connected) ]]; then
168
		local ifup="\nIP ($DEFAULT_ADAPTER) via Network Manager: \Z1${ipadd}\n\Z0 "
169
	else
170
171
172
173
174
		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
175
	fi
176

177
178
	disclaimer="$ifup"

Igor Pecovnik's avatar
Igor Pecovnik committed
179
	if [[ -n $WIFICONNECTED ]]; then
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
180
		LISTLENGHT=$((LISTLENGHT+2))
181
182
		local connected="\n\Z0Connected to SSID: \Z1${WIFICONNECTED}\n\Z0 "
		disclaimer=$disclaimer"$connected"
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
183
184
	fi

185
186
187
188
189
190
	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
191
	if [[ -n $HOSTAPDINFO && -n $HOSTAPDSTATUS ]]; then
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
192
		LISTLENGHT=$((LISTLENGHT+2))
Igor Pecovnik's avatar
Igor Pecovnik committed
193
		chpid=$(dmesg | grep $(grep ^interface /etc/hostapd.conf | sed 's/interface=//g') | head -1 | sed 's/\[.*\]//g' | awk '{print $1}')
194
		disclaimer=$disclaimer$"\n\Z0Hotspot SSID: \Z1$HOSTAPDINFO\Zn Band:";
195
		if [[ `grep ^hw_mode=a /etc/hostapd.conf` ]]; then local band="5Ghz"; else band="2.4Ghz"; fi
196
197
		if [[ `grep ^ieee80211n /etc/hostapd.conf` ]]; then local type="N"; fi
		if [[ `grep ^ieee80211ac /etc/hostapd.conf` ]]; then local type="AC"; fi
198
		disclaimer=$disclaimer$" \Z1${band} ${type}\Z0"
199
		[[ ! "$chpid" =~ .*IPv6.* ]] && disclaimer=$disclaimer$"\n\nChip: \Z1${chpid}\Z0";
Igor Pecovnik's avatar
Igor Pecovnik committed
200
		if [ "$HOSTAPDCLIENTS" -gt "0" ]; then disclaimer=$disclaimer$" Connected clients: \Z1$HOSTAPDCLIENTS\Zn"; fi
201
		if [[ ! "$chpid" =~ .*IPv6.* ]]; then LISTLENGHT=$((LISTLENGHT+2)); fi
Igor Pecovnik's avatar
Igor Pecovnik committed
202
		disclaimer=$disclaimer$"\n";
Igor Pecovnik's avatar
Igor Pecovnik committed
203
	fi
204
	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
205
206

	exec 3>&1
207
	selection=$(dialog --backtitle "$BACKTITLE" --colors --title " Wired, Wireless, Bluetooth, Hotspot " --clear \
208
	--cancel-label "Cancel" --menu "${disclaimer}" $LISTLENGHT 70 $BOXLENGHT \
Igor Pecovnik's avatar
Igor Pecovnik committed
209
210
211
212
213
	"${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
214
	# run main function
Igor Pecovnik's avatar
Igor Pecovnik committed
215
	jobs "$selection"
216

Igor Pecovnik's avatar
Igor Pecovnik committed
217
218
219
done
}

220

Igor Pecovnik's avatar
Igor Pecovnik committed
221
#-----------------------------------------------------------------------------------------------------------------------------------------#
222
# personal
Igor Pecovnik's avatar
Igor Pecovnik committed
223
#
224
function submenu_personal ()
Igor Pecovnik's avatar
Igor Pecovnik committed
225
226
227
228
{
while true; do

	LIST=()
229
230
	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" )
231
	LIST+=( "Keyboard" "Change console keyboard layout (\Z5($(cat /etc/default/keyboard | grep XKBLAYOUT | grep -o '".*"' | sed 's/"//g')\Z0)")
232
	LIST+=( "Hostname" "Change your hostname \Z5($(cat /etc/hostname))\Z0" )
233
	[[ -f /etc/apt/sources.list.d/armbian.list ]] && LIST+=( "Mirror" "Change repository server" )
Igor Pecovnik's avatar
Igor Pecovnik committed
234
235
236
	LIST+=( "Welcome" "Toggle welcome screen items" )

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

	exec 3>&1
241
242
	selection=$(dialog --colors --backtitle "$BACKTITLE" --title "Personal settings" --clear \
	--cancel-label "Cancel" --menu "$disclaimer" $LISTLENGHT 70 $BOXLENGHT \
Igor Pecovnik's avatar
Igor Pecovnik committed
243
244
245
246
	"${LIST[@]}" 2>&1 1>&3)
	exit_status=$?
	exec 3>&-
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && break
247
248

	# run main function
Igor Pecovnik's avatar
Igor Pecovnik committed
249
	jobs "$selection"
250

Igor Pecovnik's avatar
Igor Pecovnik committed
251
done
Igor Pecovnik's avatar
Igor Pecovnik committed
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
}


#-----------------------------------------------------------------------------------------------------------------------------------------#
# 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" )
268

Igor Pecovnik's avatar
Igor Pecovnik committed
269
270
	if [[ -n $(dpkg -l | grep linux-headers) ]]; then LIST+=( "Headers" "Remove kernel headers" ); else \
	LIST+=( "Headers" "Install kernel headers" ); fi
271
272
273
274
275
276
277
	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
278
279
280
281
282
283
284

	# 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 \
285
	--cancel-label "Cancel" --menu "$disclaimer" $LISTLENGHT 70 $BOXLENGHT \
Igor Pecovnik's avatar
Igor Pecovnik committed
286
287
288
289
290
291
292
	"${LIST[@]}" 2>&1 1>&3)
	exit_status=$?
	exec 3>&-
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && break

	# run main function
	jobs "$selection"
293

Igor Pecovnik's avatar
Igor Pecovnik committed
294
done
295
}