debian-config 4.21 KB
Newer Older
Igor Pecovnik's avatar
RFC #2    
Igor Pecovnik committed
1
2
#!/bin/bash
#
3
# Copyright (c) Authors: http://www.armbian.com/authors, info@armbian.com
Igor Pecovnik's avatar
RFC #2    
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.

Igor Pecovnik's avatar
Igor Pecovnik committed
9
10
11


#
JC Staudt's avatar
JC Staudt committed
12
# check for root privileges
13
14
#
if [[ $EUID != 0 ]]; then
ThomasKaiser's avatar
ThomasKaiser committed
15
	echo "This tool requires root privileges. Try again with \"sudo \" please ..." >&2
16
	sleep 2
ThomasKaiser's avatar
ThomasKaiser committed
17
	exit 1
18
19
20
fi


Igor Pecovnik's avatar
Igor Pecovnik committed
21
22
23


#
24
# check for internet connection to install dependencies
25
#
26
wget -q --spider http://github.com
27
if [[ $? -ne 0 ]]; then
JC Staudt's avatar
JC Staudt committed
28
		read -n 1 -s -p "Warning: Configuration cannot work properly without a working internet connection. \
29
30
31
32
		Press CTRL C to stop to stop or any key to ignore and continue."
fi


33

Igor Pecovnik's avatar
Igor Pecovnik committed
34
35
36
37

#
# load functions, local first
#
38
39
40
41
42
43
44
45
46
if  [[ -f ${BASH_SOURCE}-jobs ]]; then source ${BASH_SOURCE}-jobs;
	elif  [[ -f /usr/lib/armbian-config/jobs.sh ]]; then source /usr/lib/armbian-config/jobs.sh;
	else exit 1;
fi

if  [[ -f ${BASH_SOURCE}-submenu ]]; then source ${BASH_SOURCE}-submenu;
	elif  [[ -f /usr/lib/armbian-config/submenu.sh ]]; then source /usr/lib/armbian-config/submenu.sh;
	else exit 1;
fi
47

48
49
50
51
52
53
54
55
56
57
if  [[ -f ${BASH_SOURCE}-functions ]]; then source ${BASH_SOURCE}-functions;
	elif  [[ -f /usr/lib/armbian-config/functions.sh ]]; then source /usr/lib/armbian-config/functions.sh;
	else exit 1;
fi

if  [[ -f ${BASH_SOURCE}-functions-network ]]; then source ${BASH_SOURCE}-functions-network;
	elif  [[ -f /usr/lib/armbian-config/functions-network.sh ]]; then source /usr/lib/armbian-config/functions-network.sh;
	else exit 1;
fi

Igor Pecovnik's avatar
Igor Pecovnik committed
58
59
60



61
62
# collect info
main "$@"
63
64


Igor Pecovnik's avatar
Igor Pecovnik committed
65
66
67


#
Igor Pecovnik's avatar
Igor Pecovnik committed
68
# Main menu
69
#
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
70
71
while true
do
Igor Pecovnik's avatar
Igor Pecovnik committed
72
	LIST=()
73

74
75
76
	LIST+=( "System" "System and security settings" )
	LIST+=( "Network" "Wired, wireless, Bluetooth, access point" )
	LIST+=( "Personal" "Timezone, language, hostname" )
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
77
78
	LIST+=( "Software" "System and 3rd party software install" )
	LIST+=( "Help" "Documentation, support, sources" )
79

80
	# count number of menu items to adjust window size
JC Staudt's avatar
JC Staudt committed
81
82
	LISTLENGTH="$((11+${#LIST[@]}/2))"
	BOXLENGTH=${#LIST[@]}
83
84
85
	MENUTITLE="Configure \Z1$DISTRO $DISTROID\Z0"

	# read cpu speed
86
	POLICY="policy0"
87
	[[ $(grep -c '^processor' /proc/cpuinfo) -gt 4 ]] && POLICY="policy4"
88
	[[ ! -d /sys/devices/system/cpu/cpufreq/policy4 ]] && POLICY="policy0"
89
	num=$(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_min_freq 2> /dev/null)
90
91
92
        if [[ -f /etc/default/cpufrequtils && ! -z "${num##*[!0-9]*}" ]]; then
                FREQENCIES="\n"$(LC_ALL="C" cpufreq-info | grep policy | sed "s/  current policy: //" | sed 's/.*/\u&/' | tail -1)"\n"
		LISTLENGTH=$((LISTLENGTH + 2))
93
		FREQENCIES="\nSoC runs between \Z1$(($(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_min_freq) / 1000))\Z0 and \Z1$(($(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_max_freq) / 1000)) MHz\Z0 using \Z1$(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_governor)\Z0 governor.\n"
94
95
        fi

96
	[[ -n "${BOARD_NAME/ /}" ]] && MENUTITLE=$MENUTITLE" based \Z1Armbian\Z0 for the \Z1${BOARD_NAME}\Z0 "
Igor Pecovnik's avatar
RFC #2    
Igor Pecovnik committed
97

Igor Pecovnik's avatar
Igor Pecovnik committed
98
99
100
	# main dialog routine
	DIALOG_CANCEL=1
	DIALOG_ESC=255
JC Staudt's avatar
JC Staudt committed
101
	TITLELENGTH=${#MENUTITLE}
Igor Pecovnik's avatar
Igor Pecovnik committed
102

JC Staudt's avatar
JC Staudt committed
103
	[[ "$TITLELENGTH" -lt 60 ]] && TITLELENGTH="60"
104

Igor Pecovnik's avatar
RFC #2    
Igor Pecovnik committed
105
	exec 3>&1
106
	selection=$(dialog --colors --backtitle "$BACKTITLE" --title " armbian-config " --clear \
107
	--cancel-label "Exit" --menu "\n$MENUTITLE \n$FREQENCIES\nSupport: \Z1https://forum.armbian.com\Z0\n " \
JC Staudt's avatar
JC Staudt committed
108
	$LISTLENGTH ${TITLELENGTH} $BOXLENGTH "${LIST[@]}" 2>&1 1>&3)
Igor Pecovnik's avatar
RFC #2    
Igor Pecovnik committed
109
110
	exit_status=$?
	exec 3>&-
111

Igor Pecovnik's avatar
Igor Pecovnik committed
112
	[[ $exit_status == $DIALOG_CANCEL || $exit_status == $DIALOG_ESC ]] && clear && exit
Igor Pecovnik's avatar
Igor Pecovnik committed
113

114
115
	dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox \
	"\nLoading ${selection,,} submodule ... " 5 $((26+${#selection}))
116

Igor Pecovnik's avatar
RFC #2    
Igor Pecovnik committed
117
118
	case $selection in

119
120
		"System" )
			submenu_settings
121
		;;
122
123

		"Network" )
124
125
			submenu_networking
		;;
126
127
128

		"Personal" )
			submenu_personal
129
		;;
130
131
132

		"Software" )
			submenu_software
133
		;;
134

135
		"Help" )
136
137
138
139
140
141
142
			t="This tool provides a straightforward way of configuring."
			t=$t"\n \nAlthough it can be run at any time, some of the"
			t=$t" options may have difficulties if you alter system settings manually.\n"
			t=$t"\n\Z1Documentation:\Z0     https://docs.armbian.com"
			t=$t"\n\n\Z1Support:\Z0           https://forum.armbian.com\n"
			t=$t"\n\Z1Sources:\Z0           https://github.com/armbian/config"
			show_box "Info" "$t" "18"
143
		;;
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
144
	esac
JC Staudt's avatar
JC Staudt committed
145
done