forked from ARM-software/lisa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_base.sh
executable file
·412 lines (349 loc) · 13.1 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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#! /usr/bin/env bash
# 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 Vagrant 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=$(printf "$1" | sed 's/\.//2g')
local y=$(printf "$2" | sed 's/\.//2g')
[[ "$(printf "$x\n$y\n" | 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
ANDROID_HOME="$LISA_HOME/tools/android-sdk-linux/"
ANDROID_SDK_ROOT="$ANDROID_HOME"
mkdir -p "$ANDROID_HOME"
# No need for the whole SDK for this one
install_android_platform_tools() {
echo "Installing Android platform tools ..."
local url="https://dl.google.com/android/repository/platform-tools-latest-linux.zip"
local archive="$ANDROID_HOME/android-platform-tools.zip"
wget --no-verbose "$url" -O "$archive" &&
echo "Extracting $archive ..." &&
unzip -q -o "$archive" -d "$ANDROID_HOME"
}
cleanup_android_home() {
echo "Cleaning up Android SDK: $ANDROID_HOME"
rm -r "$ANDROID_HOME"
mkdir -p "$ANDROID_HOME"
}
install_android_sdk_manager() {
echo "Installing Android SDK manager ..."
# URL taken from "Command line tools only": https://developer.android.com/studio
# Used to be "https://dl.google.com/android/repository/commandlinetools-linux-7302050_latest.zip"
# Used to be "https://dl.google.com/android/repository/commandlinetools-linux-8092744_latest.zip"
local url="https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip"
local archive="$ANDROID_HOME/android-sdk-manager.zip"
rm "$archive" &>/dev/null
echo "Downloading Android SDK manager from: $url"
wget --no-verbose "$url" -O "$archive" &&
echo "Extracting $archive ..." &&
unzip -q -o "$archive" -d "$ANDROID_HOME"
yes | (call_android_sdkmanager --licenses || true)
call_android_sdkmanager --list
}
# Android SDK is picky on Java version, so we need to set JAVA_HOME manually.
# In most distributions, Java is installed under /usr/lib/jvm so use that.
# according to the distribution
ANDROID_SDK_JAVA_VERSION=11
find_java_home() {
_JAVA_BIN=$(find /usr/lib/jvm -path "*$ANDROID_SDK_JAVA_VERSION*/bin/java" -not -path '*/jre/bin/*' -print -quit)
_JAVA_HOME=$(dirname "$_JAVA_BIN")/../
echo "Found JAVA_HOME=$_JAVA_HOME"
}
call_android_sdk() {
# Used to be:
# local tool="$ANDROID_HOME/tools/bin/$1"
local tool="$ANDROID_HOME/cmdline-tools/bin/$1"
shift
echo "Using JAVA_HOME=$_JAVA_HOME for Android SDK" >&2
# Use grep to remove the progress bar, as there is no CLI option for the SDK
# manager to do that
JAVA_HOME=$_JAVA_HOME "$tool" "$@" | grep -v '\[='
}
call_android_sdkmanager() {
call_android_sdk sdkmanager --sdk_root="$ANDROID_SDK_ROOT" "$@"
}
# Needs install_android_sdk_manager first
install_android_tools() {
# We could use install_android_platform_tools here for platform-tools if the
# SDK starts being annoying
yes | call_android_sdkmanager --verbose --channel=0 --install "build-tools;33.0.2"
yes | call_android_sdkmanager --verbose --channel=0 --install "platform-tools"
}
# Clone alpine-chroot-install repo
clone_alpine_chroot_install() {
rm -rf "$LISA_HOME/tools/alpine-chroot-install"
git -C $LISA_HOME/tools clone https://github.com/alpinelinux/alpine-chroot-install.git --depth=1
}
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 requirements="$LISA_HOME/extra_requirements.txt"
local devmode_requirements="$LISA_HOME/devmode_extra_requirements.txt"
echo "Registering extra Python pip requirements in $requirements:"
local 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"
}
# Extra Python pip requirements, to be installed by lisa-install
pip_extra_requirements=()
# APT-based distributions like Ubuntu or Debian
apt_packages=(
coreutils
build-essential
git
openssh-client
sshpass
wget
rsync
unzip
qemu-user-static
kernelshark
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
)
# pacman-based distributions like Archlinux or its derivatives
pacman_packages=(
coreutils
git
rsync
openssh
sshpass
base-devel
wget
unzip
qemu-user-static
python
python-pip
python-setuptools
kernelshark
)
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 [[ ! -z "$package_manager" ]] && ! test_os_release NAME "$expected_distro"; then
unsupported_distro=1
echo
echo "INFO: the distribution seems based on $package_manager but is not $expected_distro, some package names might not be right"
echo
else
unsupported_distro=0
fi
usage() {
echo "Usage: $0 [--help] [--cleanup-android-sdk] [--install-android-tools] [--install-android-platform-tools] [--install-doc-extras] [--install-bisector-dbus] [--install-toolchains] [--install-vagrant] [--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
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_functions+=(cleanup_android_home)
handled=1
;;&
# TODO: remove --install-android-sdk, since it is only temporarily there to
# give some time to migrate CI scripts
"--install-android-sdk" | "--install-android-tools" | "--install-all")
install_functions+=(
find_java_home
install_android_sdk_manager # Needed by install_android_build_tools
install_android_tools
)
apt_packages+=(openjdk-$ANDROID_SDK_JAVA_VERSION-jre openjdk-$ANDROID_SDK_JAVA_VERSION-jdk)
pacman_packages+=(jre$ANDROID_SDK_JAVA_VERSION-openjdk jdk$ANDROID_SDK_JAVA_VERSION-openjdk)
handled=1;
;;&
# Not part of --install-all since that is already satisfied by
# --install-android-tools The advantage of that method is that it does not
# require the Java JDK/JRE to be installed, and is a bit quicker. However,
# it will not provide the build-tools which are needed by devlib.
"--install-android-platform-tools")
install_functions+=(install_android_platform_tools)
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;
;;&
"--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)
install_functions+=(clone_alpine_chroot_install)
handled=1;
;;&
"--install-vagrant" | "--install-all")
# Only install the package if we are not already inside the VM to save
# some install time
vm=$(systemd-detect-virt 2>/dev/null)
if [[ $vm == 'oracle' ]] ; then
echo "VirtualBox detected, not installing virtualbox apt packages" >&2
elif [[ $HOST_ARCH == 'aarch64' ]]; then
echo "VirtualBox not supported on $HOST_ARCH" >&2
else
apt_packages+=(vagrant virtualbox)
pacman_packages+=(vagrant virtualbox virtualbox-host-dkms)
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
find_java_home
# cleanup must be done BEFORE installing
cleanup_android_home
install_android_sdk_manager # Needed by install_android_build_tools
install_android_tools
install_android_platform_tools
register_pip_extra_requirements
clone_alpine_chroot_install
)
# Remove duplicates in the list
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: