-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathinstall_packages.sh
executable file
·209 lines (187 loc) · 8.1 KB
/
install_packages.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/bash
# This file is part of the Network Performance Monitor which is released under the GNU General Public License v3.0
# See the file LICENSE for full license details.
if [[ ! -f /opt/netperf/scriptutils.sh ]]; then
printf "Can't find a required file.\nPlease copy the project files to /opt/netperf before running this script.\ne.g.:\nsudo cp -R network_performance_monitor/netperf /opt/netperf\n\n"
exit 1
fi
# check that the script is being run as root
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root, e.g:"
echo "sudo ./$(basename $0)"
exit 1
fi
source /opt/netperf/scriptutils.sh
raspbian_os_packages=( sqlite3 python3-daemon python3-numpy python3-matplotlib iperf3 \
dnsutils texlive-latex-base texlive-latex-extra bc nginx gunicorn rabbitmq-server python3-pip)
debian_os_packages=( sqlite3 python3-daemon python3-numpy python3-matplotlib iperf3 dnsutils texlive-latex-base texlive-latex-extra \
iw wpasupplicant bc nginx gunicorn rabbitmq-server python3-pip )
centos_os_packages=( epel-release gcc sqlite python3-daemon python3-matplotlib python36-devel iperf3 \
bind-utils iw wpa_supplicant bc nginx python3-gunicorn rabbitmq-server python3-pip libqhull texlive-latex \
texlive-collection-latexrecommended texlive-titlesec )
fedora_os_packages=( gcc sqlite python3-daemon python3-matplotlib python3-devel iperf3 \
bind-utils iw wpa_supplicant bc nginx python3-gunicorn rabbitmq-server python3-pip libqhull texlive-latex \
texlive-collection-latexrecommended texlive-titlesec newt cronie cronie-anacron )
pip_packages=( posix_ipc flask flask-socketio requests kombu celery )
printf "\nInstalling software packages required for the Network Performance Monitor project.\n\n"
os_id=$( get_os_id )
printf "System type: $os_id\n\n"
if [[ "$os_id" == "centos" ]]; then
# install 'newt' for the whiptail command used by this script
install_os_package newt > /dev/null
# enable PowerTools repository for libqhull (required for python3-matplotlib on CentOS systems)
printf "Installing dnf-plugins-core...\n"
install_os_package dnf-plugins-core > /dev/null
printf "Enabling PowerTools repository...\n"
dnf config-manager --set-enabled PowerTools
os_packages=("${centos_os_packages[@]}")
# check if SELinux is enforced on this system
sel_enforced=$( selinux_enforced )
if [[ "$sel_enforced" == true ]]; then
# add package that contains the 'semanage' tool
os_packages+=( policycoreutils-python-utils )
fi
else
if [[ "$os_id" == "fedora" ]]; then
# install 'newt' for the whiptail command used by this script
install_os_package newt > /dev/null
os_packages=("${fedora_os_packages[@]}")
sel_enforced=$( selinux_enforced )
if [[ "$sel_enforced" == true ]]; then
# add package that contains the 'semanage' tool
os_packages+=( policycoreutils-python-utils )
fi
else
if [[ "$os_id" == "raspbian" ]]; then
os_packages=("${raspbian_os_packages[@]}")
else
if [[ "$os_id" == "debian" ]]; then
os_packages=("${debian_os_packages[@]}")
else
printf "Unsupported operating system: $os_od\n"
exit 1
fi
fi
fi
fi
result=$( whiptail --title "Speedtest client selection" --menu --nocancel \
"The system performs periodic Internet speed tests against Ookla speedtest.net servers. \
There are two speedtest clients available for performing these tests:\n\n\
speedtest-cli: an open source speedtest client that may report inaccurate speeds on faster Internet connections\n\n\
Ookla Speedtest CLI: a closed source proprietary client that reports accurate speeds on faster Internet connections\n\n\
Which client do you want to install?\n\n
" 20 80 2 \
"speedtest-cli" " open source client" \
"Ookla Speedtest CLI" " closed source proprietary client" 3>&1 1>&2 2>&3 )
if [[ "$result" == "speedtest-cli" ]]; then
# uninstall Ookla client, add speedtest-cli to the package list
package_installed=$( os_package_installed speedtest )
if [[ "$package_installed" == true ]]; then
printf "Removing Ookla Speedtest CLI client...\n"
remove_os_package speedtest
fi
pip_packages+=( speedtest-cli )
else
# uninstall speedtest-cli, add Ookla client + dependencies to the package list
package_installed=$( pip_package_installed speedtest-cli )
if [[ "$package_installed" == true ]]; then
printf "Removing speedtest-cli client...\n"
remove_pip_package speedtest-cli > /dev/null
fi
# Due to changes in how Ookla distributes its command line tool it must be installed manually
# before running this package installer script. Refer to the project wiki for instructions:
# https://github.com/mr-canoehead/network_performance_monitor/wiki/Install-project-files-and-required-software-packages
command -v speedtest > /dev/null
if [[ "$?" -ne 0 ]]; then
printf "The Ookla speedtest client must be installed manually prior to running this script.\n"
printf "Refer to the project wiki for instructions:\n"
printf "https://github.com/mr-canoehead/network_performance_monitor/wiki/Install-project-files-and-required-software-packages"
exit 1
fi
#if [[ "$os_id" == "centos" || "$os_id" == "fedora" ]]; then
# printf "Adding Ookla repository...\n"
# package_installed=$( os_package_installed wget )
# if [[ "$package_installed" == false ]]; then
# printf "Installing wget...\n"
# install_os_package wget > /dev/null
# fi
# wget https://bintray.com/ookla/rhel/rpm -O bintray-ookla-rhel.repo > /dev/null 2>&1
# mv bintray-ookla-rhel.repo /etc/yum.repos.d/ > /dev/null 2>&1
# os_packages+=( speedtest )
#else
# if [[ "$os_id" == "raspbian" || "$os_id" == "debian" ]]; then
# printf "Adding Ookla repository...\n"
# INSTALL_KEY=379CE192D401AB61
# DEB_DISTRO=$(lsb_release -sc)
# install_os_package gnupg1 > /dev/null
# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys "$INSTALL_KEY"
# echo "deb https://ookla.bintray.com/debian ${DEB_DISTRO} main" | sudo tee /etc/apt/sources.list.d/speedtest.list > /dev/null
# os_packages+=( apt-transport-https dirmngr speedtest)
# fi
#fi
fi
printf "Updating repository cache...\n"
update_repository_cache
all_packages_installed=true
printf "Installing required packages...\n"
for os_package in "${os_packages[@]}"
do
# test if package is already installed
result=$( os_package_installed "$os_package" )
if [[ "$result" == true ]]; then
printf " $os_package is installed\n"
else
#try 3 times to install the package (sometimes Raspbian mirrors can be unreliable)
package_installed=false
for i in {1..3}
do
printf " Installing package $os_package... "
install_os_package "$os_package" > /dev/null
# check that the package is now installed
result=$( os_package_installed "$os_package" )
if [[ "$result" == true ]]; then
printf " done.\n"
package_installed=true
break
fi
done
if [[ "$package_installed" == "false" ]]; then
printf " error, installation failed.\n"
all_packages_installed=false
fi
fi
done
for pip_package in "${pip_packages[@]}"
do
# test if package is already installed
installed=$( pip_package_installed "$pip_package" )
if [[ "$installed" == true ]]; then
echo " $pip_package is installed"
else
#try 3 times to install the package (sometimes Raspbian mirrors can be unreliable)
package_installed=false
for i in {1..3}
do
printf " Installing pip package $pip_package..."
install_pip_package "$pip_package" > /dev/null
# check that the package is now installed
installed=$( pip_package_installed "$pip_package" )
if [[ "$installed" == true ]]; then
printf " done.\n"
package_installed=true
break
fi
done
if [[ "$package_installed" == "false" ]]; then
echo " error, installation failed.\n"
all_packages_installed=false
fi
fi
done
if [[ "$all_packages_installed" == "false" ]]; then
echo
echo "Error: One or more required packages failed to install. Check your Internet connection from this machine, or switch mirrors."
echo " Then run this script again."
else
echo "All required packages were installed successfully."
fi