-
Notifications
You must be signed in to change notification settings - Fork 119
/
install_base.sh
executable file
·337 lines (289 loc) · 10.3 KB
/
install_base.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#!/usr/bin/env bash
#
# SPDX-License-Identifier: Apache-2.0
#
# Copyright (C) 2024, ARM Limited and contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Script to install the depenencies for LISA on an Ubuntu-like system.
# This is intended to be used for setting up containers and virtual machines to
# run LISA (e.g. for CI infrastructure or for docker installation).
# This can also work for a fresh LISA install on a workstation.
# Read standard /etc/os-release file and extract the needed field lsb_release
# binary is not installed on all distro, but that file is found pretty much
# anywhere.
read_os_release() {
local field_name=$1
(source /etc/os-release &> /dev/null && printf "%s" "${!field_name}")
}
# Test the value of a field in /etc/os-release
test_os_release(){
local field_name=$1
local value=$2
if [[ "$(read_os_release "$field_name")" == "$value" ]]; then
# same as "true" command
return 0
else
# same as "false" commnad
return 1
fi
}
lower_or_equal() {
local x
local y
x=$(printf "%s" "$1" | sed 's/\.//2g')
y=$(printf "%s" "$2" | sed 's/\.//2g')
[[ "$(printf "%s\n%s\n" "$x" "$y" | sort -g | head -1)" == "$x" ]]
}
LISA_HOME=${LISA_HOME:-$(dirname "${BASH_SOURCE[0]}")}
cd "$LISA_HOME" || (echo "LISA_HOME ($LISA_HOME) does not exists" && exit 1)
# Must be kept in sync with shell/lisa_shell
export ANDROID_HOME="$LISA_HOME/tools/android-sdk-linux/"
install_apt() {
echo "Installing apt packages ..."
local apt_cmd=(DEBIAN_FRONTEND=noninteractive apt-get)
sudo "${apt_cmd[@]}" update
if [[ $unsupported_distro == 1 ]]; then
for package in "${apt_packages[@]}"; do
if ! sudo "${apt_cmd[@]}" install -y "$package"; then
echo "Failed to install $package on that distribution" >&2
fi
done
else
sudo "${apt_cmd[@]}" install -y "${apt_packages[@]}" || exit $?
fi
}
install_pacman() {
echo "Installing pacman packages ..."
sudo pacman -Sy --needed --noconfirm "${pacman_packages[@]}" || exit $?
}
register_pip_extra_requirements() {
local content
local requirements="$LISA_HOME/extra_requirements.txt"
local devmode_requirements="$LISA_HOME/devmode_extra_requirements.txt"
echo "Registering extra Python pip requirements in $requirements:"
content=$(printf "%s\n" "${pip_extra_requirements[@]}")
printf "%s\n\n" "$content" | tee "$requirements"
# All the requirements containing "./" are prefixed with "-e " to install
# them in editable mode
printf "%s\n\n" "$(printf "%s" "$content" | sed '/.\//s/^/-e /')" > "$devmode_requirements"
}
devlib_setup_host() {
if [ ${#devlib_params[@]} -ne 0 ]; then
"${LISA_HOME}/external/devlib/tools/android/setup_host.sh" "${devlib_params[@]}"
fi
}
# Extra Python pip requirements, to be installed by lisa-install
pip_extra_requirements=()
# APT-based distributions like Ubuntu or Debian
apt_packages=(
build-essential
coreutils
git
kernelshark
openssh-client
python3
# venv is not installed by default on Ubuntu, even though it is part of the
# Python standard library
python3-pip
python3-venv
python3-tk
python3-setuptools
qemu-user-static
)
# pacman-based distributions like Archlinux or its derivatives
pacman_packages=(
base-devel
coreutils
git
kernelshark
openssh
python
python-pip
python-setuptools
qemu-user-static
)
HOST_ARCH="$(uname -m)"
# ABI-specific packages
case $HOST_ARCH in
aarch64)
# Allows building C extensions from sources, when they do not ship a
# prebuilt wheel for that arch
apt_packages+=(python3-dev)
# pacman_packages+=()
;;
esac
# More recent versions of Ubuntu ship firefox as a snap package already
# containing the geckodriver
if test_os_release NAME "Ubuntu" && lower_or_equal "$(read_os_release VERSION_ID)" "22"; then
# In order to save plots using bokeh, we need a browser usable with
# selenium, along with its selenium driver.
#
# Note: firefox seems to cope well without X11, unlike chromium.
apt_packages+=(firefox-geckodriver)
fi
# Array of functions to call in order
install_functions=(
register_pip_extra_requirements
)
# Detection based on the package-manager, so that it works on derivatives of
# distributions we expect. Matching on distro name would prevent that.
if which apt-get &>/dev/null; then
install_functions+=(install_apt)
package_manager='apt-get'
expected_distro="Ubuntu"
elif which pacman &>/dev/null; then
install_functions+=(install_pacman)
package_manager="pacman"
expected_distro="Arch Linux"
else
echo "The package manager of distribution $(read_os_release NAME) is not supported, will only install distro-agnostic code"
fi
if [[ -n "$package_manager" ]] && ! test_os_release NAME "$expected_distro"; then
unsupported_distro=1
echo -e "\nINFO: the distribution seems based on $package_manager but is not $expected_distro, some package names might not be right\n"
else
unsupported_distro=0
fi
usage() {
echo "Usage: $0 [--help] [--cleanup-android-sdk] [--install-android-tools]
[--install-android-platform-tools] [--install-doc-extras]
[--install-tests-extra] [--install-bisector-dbus] [--install-toolchains]
[--install-all]"
cat << EOF
Install distribution packages and other bits that don't fit in the Python
venv managed by lisa-install. Archlinux and Ubuntu are supported, although
derivative distributions will probably work as well.
--install-android-platform-tools is not needed when using --install-android-tools,
but has the advantage of not needing a Java installation and is quicker to install.
EOF
}
# Defaults to --install-all if no option is given
if [[ -z "$*" ]]; then
args=("--install-all")
else
args=("$@")
fi
# Use conditional fall-through ;;& to all matching all branches with
# --install-all
devlib_params=()
for arg in "${args[@]}"; do
# We need this flag since *) does not play well with fall-through ;;&
handled=0
case "$arg" in
"--cleanup-android-sdk" | "--install-android-platform-tools" )
devlib_params+=(${arg})
install_functions+=(devlib_setup_host)
handled=1
;;&
"--install-android-tools" | "--install-all" )
devlib_params+=("--install-android-tools")
install_functions+=(devlib_setup_host)
handled=1
;;&
"--install-doc-extras" | "--install-all")
apt_packages+=(plantuml graphviz pandoc)
# plantuml can be installed from the AUR
pacman_packages+=(graphviz pandoc)
handled=1
;;&
# Requirement for LISA's self tests (in tests/ folder), not the synthetic
# kernel tests.
"--install-tests-extras" | "--install-all")
apt_packages+=(clang)
pacman_packages+=(clang)
handled=1
;;&
"--install-toolchains" | "--install-all")
apt_packages+=(build-essential gcc-arm-linux-gnueabi gcc-aarch64-linux-gnu)
# arm-linux-gnueabihf-gcc can be installed from the AUR
pacman_packages+=(base-devel aarch64-linux-gnu-gcc flex)
# Build dependencies of some assets
apt_packages+=(autopoint autoconf libtool bison flex cmake)
# gettext for autopoint
pacman_packages+=(gettext autoconf libtool bison cmake)
handled=1
;;&
"--install-kernel-build-dependencies" | "--install-all")
apt_packages+=(build-essential gcc bc bison flex libssl-dev libncurses5-dev libelf-dev)
if test_os_release NAME "Ubuntu"; then
case $(read_os_release VERSION_ID) in
# Ubuntu Jammy 22.04 does ship a pahole package
"18.04" | "18.10" | "19.04" | "19.10" | "20.04" | "20.10" | "21.04" | "21.10" | "22.10" | "23.04" | "23.10")
apt_packages+=(dwarves)
;;
*)
apt_packages+=(pahole)
;;
esac
fi
handled=1
;;&
"--install-bisector-dbus")
apt_packages+=(
gobject-introspection
# Some of that seems to only be needed on some version of Ubuntu.
# GTK/Glib does not shine on packaging side, so ere on the side of
# caution and install all the things that seem to avoid issues ...
libcairo2-dev
libgirepository1.0-dev
gir1.2-gtk-3.0
)
# plantuml can be installed from the AUR
pacman_packages+=(gobject-introspection)
pip_extra_requirements+=(./tools/bisector[dbus])
handled=1
;;&
"--help")
usage
exit 0
;;&
*)
if [[ $handled != 1 ]]; then
echo "Unrecognised argument: $arg"
usage
exit 2
fi
;;
esac
done
# In order in which they will be executed if specified in command line
ordered_functions=(
# Distro package managers before anything else, so all the basic
# pre-requisites are there
install_apt
install_pacman
register_pip_extra_requirements
devlib_setup_host
)
# Remove duplicates in the list
# shellcheck disable=SC2207
install_functions=($(echo "${install_functions[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
# Call all the hooks in the order of available_functions
ret=0
for _func in "${ordered_functions[@]}"; do
for func in "${install_functions[@]}"; do
if [[ $func == "$_func" ]]; then
# If one hook returns non-zero, we keep going but return an overall failure code.
$func; _ret=$?
if [[ $_ret != 0 ]]; then
ret=$_ret
echo "Stage $func failed with exit code $ret" >&2
else
echo "Stage $func succeeded" >&2
fi
fi
done
done
exit ${ret}
# vim: set tabstop=4 shiftwidth=4 textwidth=80 expandtab: