debian-config 5.77 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
Aristo Chen's avatar
Aristo Chen committed
28
29
	read -n 1 -s -p "Warning: Configuration cannot work properly without a working internet connection. \
	Press CTRL C to stop or any key to ignore and continue."
30
31
32
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
# Script parameters handling
while [[ $1 == *=* ]]; do
Aristo Chen's avatar
Aristo Chen committed
61
62
63
64
65
66
	parameter=${1%%=*}
	value=${1##*=}
	shift
	echo "Command line: setting $parameter to ${value:-(empty)}"
	eval "$parameter=\"$value\""
	scripted=true
67
done
Igor Pecovnik's avatar
Igor Pecovnik committed
68

69
70
71
72
# Display help
if [[ $1 == "--help" ]]; then
	echo "Armbian config options:"
	echo ""
73
74
	echo "Examples:"
	echo ""
Igor Pecovnik's avatar
Igor Pecovnik committed
75
	echo "Install headers:					${BASH_SOURCE[0]} main=Sytem selection=Headers"
76
77
78
	echo "Update, upgrade and reboot:			${BASH_SOURCE[0]} main=System selection=Firmware"
	echo "Switch to nightly builds:				${BASH_SOURCE[0]} main=System selection=Nightly"
	echo "Switch to stable builds: 				${BASH_SOURCE[0]} main=System selection=Stable"
79
	echo "Install default desktop:                          ${BASH_SOURCE[0]} main=System selection=Default"
80
	echo "Change to ZSH:					${BASH_SOURCE[0]} main=System selection=ZSH"
Igor Pecovnik's avatar
Igor Pecovnik committed
81
	echo "Change to BASH: 					${BASH_SOURCE[0]} main=System selection=BASH"
82
	echo "Change to stable repository [branch=dev]:		${BASH_SOURCE[0]} main=System selection=Stable"
83
	echo "Change to nightly repository [branch=dev]:	${BASH_SOURCE[0]} main=System selection=Nightly"
84
	echo "Install headers:					${BASH_SOURCE[0]} main=Software selection=Headers_install"
85
86
87
	echo "Remove headers:					${BASH_SOURCE[0]} main=Software selection=Headers_remove"
	echo "Install kernel source:				${BASH_SOURCE[0]} main=Software selection=Source_install"
	echo "Remove kernel source:				${BASH_SOURCE[0]} main=Software selection=Source_remove"
Igor Pecovnik's avatar
Igor Pecovnik committed
88
	echo "Install Avahi mDNS/DNS-SD daemon:			${BASH_SOURCE[0]} main=Software selection=Avahi"
89
90
	exit
fi
Igor Pecovnik's avatar
Igor Pecovnik committed
91

92
93
# collect info
main "$@"
94

Igor Pecovnik's avatar
Igor Pecovnik committed
95
#
Igor Pecovnik's avatar
Igor Pecovnik committed
96
# Main menu
97
#
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
98
99
while true
do
Igor Pecovnik's avatar
Igor Pecovnik committed
100
	LIST=()
101

102
103
104
	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
105
106
	LIST+=( "Software" "System and 3rd party software install" )
	LIST+=( "Help" "Documentation, support, sources" )
107

108
	# count number of menu items to adjust window size
JC Staudt's avatar
JC Staudt committed
109
110
	LISTLENGTH="$((11+${#LIST[@]}/2))"
	BOXLENGTH=${#LIST[@]}
111
112
113
	MENUTITLE="Configure \Z1$DISTRO $DISTROID\Z0"

	# read cpu speed
114
	POLICY="policy0"
115
	[[ $(grep -c '^processor' /proc/cpuinfo) -gt 4 ]] && POLICY="policy4"
116
	[[ ! -d /sys/devices/system/cpu/cpufreq/policy4 ]] && POLICY="policy0"
117
	[[ -d /sys/devices/system/cpu/cpufreq/policy0 && -d /sys/devices/system/cpu/cpufreq/policy2 ]] && POLICY="policy2"
118
	num=$(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_min_freq 2> /dev/null)
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
119
	if [[ -f /etc/default/cpufrequtils && ! -z "${num##*[!0-9]*}" ]]; then
120
		LISTLENGTH=$((LISTLENGTH + 2))
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
121
122
123
124
125
		MIN_CPU=$(($(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_min_freq) / 1000))
		MAX_CPU=$(($(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_max_freq) / 1000))
		GOVERNOR_CPU=$(cat /sys/devices/system/cpu/cpufreq/$POLICY/scaling_governor)
		FREQENCIES="\nSoC runs between \Z1${MIN_CPU}\Z0 and \Z1${MAX_CPU} MHz\Z0 using \Z1${GOVERNOR_CPU}\Z0 governor.\n"
	fi
126

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

Igor Pecovnik's avatar
Igor Pecovnik committed
129
130
131
	# main dialog routine
	DIALOG_CANCEL=1
	DIALOG_ESC=255
JC Staudt's avatar
JC Staudt committed
132
	TITLELENGTH=${#MENUTITLE}
Igor Pecovnik's avatar
Igor Pecovnik committed
133

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

136
if [[ -z $main ]]; then
Igor Pecovnik's avatar
RFC #2    
Igor Pecovnik committed
137
	exec 3>&1
138
	main=$(dialog --colors --backtitle "$BACKTITLE" --title " armbian-config " --clear \
139
	--cancel-label "Exit" --menu "\n$MENUTITLE \n$FREQENCIES\nSupport: \Z1https://forum.armbian.com\Z0\n " \
JC Staudt's avatar
JC Staudt committed
140
	$LISTLENGTH ${TITLELENGTH} $BOXLENGTH "${LIST[@]}" 2>&1 1>&3)
Igor Pecovnik's avatar
RFC #2    
Igor Pecovnik committed
141
142
	exit_status=$?
	exec 3>&-
143

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

146
	dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox \
147
148
149
	"\nLoading ${main,,} submodule ... " 5 $((26+${#main}))
fi
	case $main in
Igor Pecovnik's avatar
RFC #2    
Igor Pecovnik committed
150

151
152
		"System" )
			submenu_settings
153
		;;
154
155

		"Network" )
156
157
			submenu_networking
		;;
158
159
160

		"Personal" )
			submenu_personal
161
		;;
162
163
164

		"Software" )
			submenu_software
165
		;;
166

167
		"Help" )
168
			unset main
169
170
171
172
173
174
175
			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"
176
		;;
Igor Pecovnik's avatar
Cleanup    
Igor Pecovnik committed
177
	esac
JC Staudt's avatar
JC Staudt committed
178
done