Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/environment_install/install-prereqs-ubuntu.sh
9692 views
1
#!/usr/bin/env bash
2
echo "---------- $0 start ----------"
3
set -e
4
set -x
5
6
if [ $EUID == 0 ]; then
7
echo "Please do not run this script as root; don't sudo it!"
8
exit 1
9
fi
10
11
OPT="/opt"
12
# Ardupilot Tools
13
ARDUPILOT_TOOLS="Tools/autotest"
14
15
ASSUME_YES=false
16
QUIET=false
17
sep="##############################################"
18
19
OPTIND=1 # Reset in case getopts has been used previously in the shell.
20
while getopts "yq" opt; do
21
case "$opt" in
22
\?)
23
exit 1
24
;;
25
y) ASSUME_YES=true
26
;;
27
q) QUIET=true
28
;;
29
esac
30
done
31
32
APT_GET="sudo apt-get"
33
if $ASSUME_YES; then
34
APT_GET="$APT_GET --assume-yes"
35
fi
36
if $QUIET; then
37
APT_GET="$APT_GET -qq"
38
fi
39
40
# update apt package list
41
$APT_GET update
42
43
function package_is_installed() {
44
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed"
45
}
46
47
function heading() {
48
echo "$sep"
49
echo $*
50
echo "$sep"
51
}
52
53
# Install lsb-release as it is needed to check Ubuntu version
54
if ! package_is_installed "lsb-release"; then
55
heading "Installing lsb-release"
56
$APT_GET install lsb-release
57
echo "Done!"
58
fi
59
60
# Checking Ubuntu release to adapt software version to install
61
RELEASE_CODENAME=$(lsb_release -c -s)
62
63
RELEASE_DISTRIBUTOR=$(lsb_release -i -s | tr '[:upper:]' '[:lower:]')
64
case ${RELEASE_DISTRIBUTOR} in
65
elementary)
66
case ${RELEASE_CODENAME} in
67
jolnir)
68
RELEASE_CODENAME='focal'
69
;;
70
esac
71
;;
72
linuxmint)
73
# translate Mint-codenames to Ubuntu-codenames based on https://www.linuxmint.com/download_all.php
74
case ${RELEASE_CODENAME} in
75
wilma | xia)
76
RELEASE_CODENAME='noble'
77
;;
78
vanessa | vera | victoria | virginia)
79
RELEASE_CODENAME='jammy'
80
;;
81
una | uma | ulyssa | ulyana)
82
RELEASE_CODENAME='focal'
83
;;
84
tricia | tina | tessa | tara)
85
RELEASE_CODENAME='bionic'
86
;;
87
elsie)
88
RELEASE_CODENAME='bullseye'
89
;;
90
*)
91
echo "Unable to map ${RELEASE_CODENAME} to an Ubuntu release. Please patch this script and submit a pull request, or report at https://github.com/ArduPilot/ardupilot/issues"
92
exit 1
93
esac
94
;;
95
esac
96
97
PYTHON_V="python3" # starting from ubuntu 20.04, python isn't symlink to default python interpreter
98
PIP=pip3
99
100
if [ ${RELEASE_CODENAME} == 'bionic' ] ||
101
[ ${RELEASE_CODENAME} == 'buster' ]; then
102
echo "ArduPilot no longer supports developing on this operating system that has reached end of standard support."
103
exit 1
104
elif [ ${RELEASE_CODENAME} == 'trixie' ]; then
105
SITLFML_VERSION="2.6"
106
SITLCFML_VERSION="2.6"
107
PYTHON_V="python3"
108
PIP=pip3
109
elif [ ${RELEASE_CODENAME} == 'bookworm' ]; then
110
SITLFML_VERSION="2.5"
111
SITLCFML_VERSION="2.5"
112
PYTHON_V="python3"
113
PIP=pip3
114
elif [ ${RELEASE_CODENAME} == 'focal' ]; then
115
SITLFML_VERSION="2.5"
116
SITLCFML_VERSION="2.5"
117
PYTHON_V="python3"
118
PIP=pip3
119
elif [ ${RELEASE_CODENAME} == 'jammy' ]; then
120
SITLFML_VERSION="2.5"
121
SITLCFML_VERSION="2.5"
122
PYTHON_V="python3"
123
PIP=pip3
124
elif [ ${RELEASE_CODENAME} == 'lunar' ]; then
125
SITLFML_VERSION="2.5"
126
SITLCFML_VERSION="2.5"
127
PYTHON_V="python3"
128
PIP=pip3
129
elif [ ${RELEASE_CODENAME} == 'mantic' ]; then
130
SITLFML_VERSION="2.5"
131
SITLCFML_VERSION="2.5"
132
PYTHON_V="python3"
133
PIP=pip3
134
elif [ ${RELEASE_CODENAME} == 'noble' ]; then
135
SITLFML_VERSION="2.6"
136
SITLCFML_VERSION="2.6"
137
PYTHON_V="python3"
138
PIP=pip3
139
elif [ ${RELEASE_CODENAME} == 'oracular' ]; then
140
SITLFML_VERSION="2.6"
141
SITLCFML_VERSION="2.6"
142
PYTHON_V="python3"
143
PIP=pip3
144
elif [ ${RELEASE_CODENAME} == 'plucky' ]; then
145
SITLFML_VERSION="2.6"
146
SITLCFML_VERSION="2.6"
147
PYTHON_V="python3"
148
PIP="python3 -m pip"
149
elif [ ${RELEASE_CODENAME} == 'questing' ]; then
150
SITLFML_VERSION="2.6"
151
SITLCFML_VERSION="2.6"
152
PYTHON_V="python3"
153
PIP="python3 -m pip"
154
elif [ ${RELEASE_CODENAME} == 'groovy' ] ||
155
[ ${RELEASE_CODENAME} == 'bullseye' ]; then
156
SITLFML_VERSION="2.5"
157
SITLCFML_VERSION="2.5"
158
PYTHON_V="python3"
159
PIP=pip3
160
else
161
# We assume APT based system, so let's try with apt-cache first.
162
SITLCFML_VERSION=$(apt-cache search -n '^libcsfml-audio' | cut -d" " -f1 | head -1 | grep -Eo '[+-]?[0-9]+([.][0-9]+)?')
163
SITLFML_VERSION=$(apt-cache search -n '^libsfml-audio' | cut -d" " -f1 | head -1 | grep -Eo '[+-]?[0-9]+([.][0-9]+)?')
164
# If we cannot retrieve the number with apt-cache, try a last time with dpkg-query
165
re='^[+-]?[0-9]+([.][0-9]+)?$'
166
if ! [[ $SITLCFML_VERSION =~ $re ]] || ! [[ $SITLFML_VERSION =~ $re ]] ; then
167
# Extract the floating point number that is the version of the libcsfml package.
168
SITLCFML_VERSION=$(dpkg-query --search libcsfml-audio | cut -d":" -f1 | grep libcsfml-audio | head -1 | grep -Eo '[+-]?[0-9]+([.][0-9]+)?')
169
# And same for libsfml-audio.
170
SITLFML_VERSION=$(dpkg-query --search libsfml-audio | cut -d":" -f1 | grep libsfml-audio | head -1 | grep -Eo '[+-]?[0-9]+([.][0-9]+)?')
171
fi
172
fi
173
174
# Check whether the specific ARM pkg-config package is available or whether we should emulate the effect of installing it.
175
# Check if we need to manually install libtool-bin
176
ARM_PKG_CONFIG_NOT_PRESENT=0
177
if [ -z "$(apt-cache search -n '^pkg-config-arm-linux-gnueabihf')" ]; then
178
ARM_PKG_CONFIG_NOT_PRESENT=$(dpkg-query --search pkg-config-arm-linux-gnueabihf |& grep -c "dpkg-query:")
179
fi
180
if [ "$ARM_PKG_CONFIG_NOT_PRESENT" -eq 1 ]; then
181
INSTALL_PKG_CONFIG=""
182
# No need to install Ubuntu's pkg-config-arm-linux-gnueabihf, instead install the base pkg-config.
183
$APT_GET install pkg-config
184
if [ -f /usr/share/pkg-config-crosswrapper ]; then
185
# We are on non-Ubuntu so simulate effect of installing pkg-config-arm-linux-gnueabihf.
186
sudo ln -sf /usr/share/pkg-config-crosswrapper /usr/bin/arm-linux-gnueabihf-pkg-config
187
else
188
echo "Warning: unable to link to pkg-config-crosswrapper"
189
fi
190
else
191
# Package is available so install it later.
192
INSTALL_PKG_CONFIG="pkg-config-arm-linux-gnueabihf"
193
fi
194
195
# Lists of packages to install
196
BASE_PKGS="build-essential ccache g++ gawk git make wget valgrind screen python3-pexpect astyle"
197
PYTHON_PKGS="future lxml pymavlink pyserial MAVProxy geocoder empy==3.3.4 ptyprocess dronecan"
198
PYTHON_PKGS="$PYTHON_PKGS flake8 junitparser wsproto tabulate"
199
200
# add some Python packages required for commonly-used MAVProxy modules and hex file generation:
201
if [[ $SKIP_AP_EXT_ENV -ne 1 ]]; then
202
PYTHON_PKGS="$PYTHON_PKGS pygame intelhex"
203
fi
204
ARM_LINUX_PKGS="g++-arm-linux-gnueabihf $INSTALL_PKG_CONFIG"
205
# python-wxgtk packages are added to SITL_PKGS below
206
207
if [ ${RELEASE_CODENAME} == 'trixie' ] ||
208
[ ${RELEASE_CODENAME} == 'bookworm' ] ||
209
[ ${RELEASE_CODENAME} == 'lunar' ] ||
210
[ ${RELEASE_CODENAME} == 'mantic' ] ||
211
[ ${RELEASE_CODENAME} == 'noble' ] ||
212
[ ${RELEASE_CODENAME} == 'oracular' ] ||
213
[ ${RELEASE_CODENAME} == 'plucky' ] ||
214
[ ${RELEASE_CODENAME} == 'questing' ] ||
215
false; then
216
# on Lunar (and presumably later releases), we install in venv, below
217
PYTHON_PKGS+=" numpy pyparsing psutil"
218
SITL_PKGS="python3-dev"
219
else
220
SITL_PKGS="libtool libxml2-dev libxslt1-dev ${PYTHON_V}-dev ${PYTHON_V}-pip ${PYTHON_V}-setuptools ${PYTHON_V}-numpy ${PYTHON_V}-pyparsing ${PYTHON_V}-psutil"
221
fi
222
223
# add some packages required for commonly-used MAVProxy modules:
224
if [[ $SKIP_AP_GRAPHIC_ENV -ne 1 ]]; then
225
if [ ${RELEASE_CODENAME} == 'trixie' ] ||
226
[ ${RELEASE_CODENAME} == 'bookworm' ] ||
227
[ ${RELEASE_CODENAME} == 'lunar' ] ||
228
[ ${RELEASE_CODENAME} == 'mantic' ] ||
229
[ ${RELEASE_CODENAME} == 'noble' ] ||
230
[ ${RELEASE_CODENAME} == 'oracular' ] ||
231
[ ${RELEASE_CODENAME} == 'plucky' ] ||
232
[ ${RELEASE_CODENAME} == 'questing' ] ||
233
false; then
234
PYTHON_PKGS+=" matplotlib scipy opencv-python pyyaml"
235
SITL_PKGS+=" xterm xfonts-base libcsfml-dev libcsfml-audio${SITLCFML_VERSION} libcsfml-dev libcsfml-graphics${SITLCFML_VERSION} libcsfml-network${SITLCFML_VERSION} libcsfml-system${SITLCFML_VERSION} libcsfml-window${SITLCFML_VERSION} libsfml-audio${SITLFML_VERSION} libsfml-dev libsfml-graphics${SITLFML_VERSION} libsfml-network${SITLFML_VERSION} libsfml-system${SITLFML_VERSION} libsfml-window${SITLFML_VERSION}"
236
else
237
SITL_PKGS="$SITL_PKGS xterm xfonts-base ${PYTHON_V}-matplotlib ${PYTHON_V}-serial ${PYTHON_V}-scipy ${PYTHON_V}-opencv libcsfml-dev libcsfml-audio${SITLCFML_VERSION} libcsfml-dev libcsfml-graphics${SITLCFML_VERSION} libcsfml-network${SITLCFML_VERSION} libcsfml-system${SITLCFML_VERSION} libcsfml-window${SITLCFML_VERSION} libsfml-audio${SITLFML_VERSION} libsfml-dev libsfml-graphics${SITLFML_VERSION} libsfml-network${SITLFML_VERSION} libsfml-system${SITLFML_VERSION} libsfml-window${SITLFML_VERSION} ${PYTHON_V}-yaml"
238
fi
239
fi
240
if [[ $SKIP_AP_COV_ENV -ne 1 ]]; then
241
# Coverage utilities
242
COVERAGE_PKGS="lcov gcovr"
243
fi
244
245
# ArduPilot official Toolchain for STM32 boards
246
function install_arm_none_eabi_toolchain() {
247
# GNU Tools for ARM Embedded Processors
248
# (see https://launchpad.net/gcc-arm-embedded/)
249
ARM_ROOT="gcc-arm-none-eabi-10-2020-q4-major"
250
case $(uname -m) in
251
x86_64)
252
if [ ! -d $OPT/$ARM_ROOT ]; then
253
(
254
cd $OPT
255
heading "Installing toolchain for STM32 Boards"
256
echo "Installing toolchain for STM32 Boards"
257
echo "Downloading from ArduPilot server"
258
sudo wget --progress=dot:giga https://firmware.ardupilot.org/Tools/STM32-tools/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
259
echo "Installing..."
260
sudo chmod -R 777 gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
261
sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
262
echo "... Cleaning"
263
sudo rm gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
264
)
265
fi
266
echo "Registering STM32 Toolchain for ccache"
267
sudo ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-g++
268
sudo ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-gcc
269
echo "Done!";;
270
271
aarch64)
272
if [ ! -d $OPT/$ARM_ROOT ]; then
273
(
274
cd $OPT
275
heading "Installing toolchain for STM32 Boards"
276
echo "Installing toolchain for STM32 Boards"
277
echo "Downloading from ArduPilot server"
278
sudo wget --progress=dot:giga https://firmware.ardupilot.org/Tools/STM32-tools/gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
279
echo "Installing..."
280
sudo chmod -R 777 gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
281
sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
282
echo "... Cleaning"
283
sudo rm gcc-arm-none-eabi-10-2020-q4-major-aarch64-linux.tar.bz2
284
)
285
fi
286
echo "Registering STM32 Toolchain for ccache"
287
sudo ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-g++
288
sudo ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-gcc
289
echo "Done!";;
290
esac
291
}
292
293
function maybe_prompt_user() {
294
if $ASSUME_YES; then
295
return 0
296
else
297
read -p "$1"
298
if [[ $REPLY =~ ^[Yy]$ ]]; then
299
return 0
300
else
301
return 1
302
fi
303
fi
304
}
305
306
heading "Add user to dialout group to allow managing serial ports"
307
sudo usermod -a -G dialout $USER
308
echo "Done!"
309
310
# Add back python symlink to python interpreter on Ubuntu >= 20.04
311
if [ ${RELEASE_CODENAME} == 'focal' ];
312
then
313
BASE_PKGS+=" python-is-python3"
314
SITL_PKGS+=" libpython3-stdlib" # for argparse
315
elif [ ${RELEASE_CODENAME} == 'groovy' ] ||
316
[ ${RELEASE_CODENAME} == 'bullseye' ] ||
317
[ ${RELEASE_CODENAME} == 'jammy' ]; then
318
BASE_PKGS+=" python-is-python3"
319
SITL_PKGS+=" libpython3-stdlib" # for argparse
320
elif [ ${RELEASE_CODENAME} == 'trixie' ]; then
321
SITL_PKGS+=" libpython3-stdlib" # for argparse
322
elif [ ${RELEASE_CODENAME} == 'bookworm' ]; then
323
SITL_PKGS+=" libpython3-stdlib" # for argparse
324
elif [ ${RELEASE_CODENAME} == 'lunar' ]; then
325
SITL_PKGS+=" libpython3-stdlib" # for argparse
326
elif [ ${RELEASE_CODENAME} != 'mantic' ] &&
327
[ ${RELEASE_CODENAME} != 'noble' ] &&
328
[ ${RELEASE_CODENAME} != 'oracular' ] &&
329
[ ${RELEASE_CODENAME} != 'plucky' ] &&
330
[ ${RELEASE_CODENAME} != 'questing' ] &&
331
true; then
332
if apt-cache search python-argparse | grep argp; then
333
SITL_PKGS+=" python-argparse"
334
elif apt-cache search python3-argparse | grep argp; then
335
SITL_PKGS+=" python3-argparse"
336
fi
337
fi
338
339
# Check for graphical package for MAVProxy
340
if [[ $SKIP_AP_GRAPHIC_ENV -ne 1 ]]; then
341
if [ ${RELEASE_CODENAME} == 'bullseye' ]; then
342
SITL_PKGS+=" libjpeg62-turbo-dev"
343
elif [ ${RELEASE_CODENAME} == 'groovy' ] ||
344
[ ${RELEASE_CODENAME} == 'focal' ]; then
345
SITL_PKGS+=" libjpeg8-dev"
346
elif [ ${RELEASE_CODENAME} == 'trixie' ]; then
347
SITL_PKGS+=" libgtk-3-dev libwxgtk3.2-dev "
348
elif [ ${RELEASE_CODENAME} == 'bookworm' ]; then
349
SITL_PKGS+=" libgtk-3-dev libwxgtk3.2-dev "
350
elif [ ${RELEASE_CODENAME} == 'lunar' ]; then
351
SITL_PKGS+=" libgtk-3-dev libwxgtk3.2-dev "
352
elif [ ${RELEASE_CODENAME} == 'mantic' ]; then
353
SITL_PKGS+=" libgtk-3-dev libwxgtk3.2-dev "
354
# see below
355
elif [ ${RELEASE_CODENAME} == 'noble' ]; then
356
SITL_PKGS+=" libgtk-3-dev libwxgtk3.2-dev "
357
# see below
358
elif [ ${RELEASE_CODENAME} == 'oracular' ]; then
359
SITL_PKGS+=" libgtk-3-dev libwxgtk3.2-dev "
360
# see below
361
elif [ ${RELEASE_CODENAME} == 'plucky' ]; then
362
SITL_PKGS+=" libgtk-3-dev libwxgtk3.2-dev "
363
# see below
364
elif [ ${RELEASE_CODENAME} == 'questing' ]; then
365
SITL_PKGS+=" libgtk-3-dev libwxgtk3.2-dev "
366
# see below
367
elif apt-cache search python-wxgtk3.0 | grep wx; then
368
SITL_PKGS+=" python-wxgtk3.0"
369
elif apt-cache search python3-wxgtk4.0 | grep wx; then
370
# see below
371
:
372
else
373
# we only support back to trusty:
374
SITL_PKGS+=" python-wxgtk2.8"
375
SITL_PKGS+=" fonts-freefont-ttf libfreetype6-dev libjpeg8-dev libpng12-0 libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev" # for pygame
376
fi
377
378
if [ ${RELEASE_CODENAME} == 'trixie' ]; then
379
PYTHON_PKGS+=" opencv-python"
380
SITL_PKGS+=" python3-wxgtk4.0"
381
SITL_PKGS+=" fonts-freefont-ttf libfreetype6-dev libpng16-16 libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev" # for pygame
382
elif [ ${RELEASE_CODENAME} == 'bookworm' ]; then
383
PYTHON_PKGS+=" opencv-python"
384
SITL_PKGS+=" python3-wxgtk4.0"
385
SITL_PKGS+=" fonts-freefont-ttf libfreetype6-dev libpng16-16 libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev" # for pygame
386
elif [ ${RELEASE_CODENAME} == 'lunar' ]; then
387
PYTHON_PKGS+=" wxpython opencv-python"
388
SITL_PKGS+=" python3-wxgtk4.0"
389
SITL_PKGS+=" fonts-freefont-ttf libfreetype6-dev libpng16-16 libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev" # for pygame
390
elif [ ${RELEASE_CODENAME} == 'mantic' ] ||
391
[ ${RELEASE_CODENAME} == 'noble' ] ||
392
[ ${RELEASE_CODENAME} == 'oracular' ] ||
393
[ ${RELEASE_CODENAME} == 'plucky' ] ||
394
[ ${RELEASE_CODENAME} == 'questing' ] ||
395
false; then
396
PYTHON_PKGS+=" wxpython opencv-python"
397
SITL_PKGS+=" python3-wxgtk4.0"
398
SITL_PKGS+=" fonts-freefont-ttf libfreetype6-dev libpng16-16 libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev" # for pygame
399
elif [ ${RELEASE_CODENAME} == 'bullseye' ] ||
400
[ ${RELEASE_CODENAME} == 'groovy' ] ||
401
[ ${RELEASE_CODENAME} == 'focal' ] ||
402
[ ${RELEASE_CODENAME} == 'jammy' ]; then
403
SITL_PKGS+=" python3-wxgtk4.0"
404
SITL_PKGS+=" fonts-freefont-ttf libfreetype6-dev libpng16-16 libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev" # for pygame
405
fi
406
fi
407
408
# Check if we need to manually install realpath
409
RP=$(apt-cache search -n '^realpath$')
410
if [ -n "$RP" ]; then
411
BASE_PKGS+=" realpath"
412
fi
413
414
# Check if we need to manually install libtool-bin
415
LBTBIN=$(apt-cache search -n '^libtool-bin')
416
if [ -n "$LBTBIN" ]; then
417
SITL_PKGS+=" libtool-bin"
418
fi
419
420
SITL_PKGS+=" ppp"
421
422
# Install all packages
423
$APT_GET install $BASE_PKGS $SITL_PKGS $PX4_PKGS $ARM_LINUX_PKGS $COVERAGE_PKGS
424
425
if [[ $SKIP_AP_GRAPHIC_ENV -ne 1 ]]; then
426
# If xfonts-base was just installed, you need to rebuild the font information cache.
427
# https://discuss.ardupilot.org/t/using-the-gdb-window-on-a-high-dpi-display/128150/2
428
fc-cache
429
fi
430
431
heading "Check if we are inside docker environment..."
432
IS_DOCKER=false
433
if [[ ${AP_DOCKER_BUILD:-0} -eq 1 ]] || [[ -f /.dockerenv ]] || grep -Eq '(lxc|docker)' /proc/1/cgroup ; then
434
IS_DOCKER=true
435
fi
436
echo "Done!"
437
438
SHELL_LOGIN=".profile"
439
if $IS_DOCKER; then
440
echo "Inside docker, we add the tools path into .bashrc directly"
441
SHELL_LOGIN=".ardupilot_env"
442
echo "# ArduPilot env file. Need to be loaded by your Shell." > ~/$SHELL_LOGIN
443
fi
444
445
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
446
ARDUPILOT_ROOT=$(realpath "$SCRIPT_DIR/../../")
447
448
PIP_USER_ARGUMENT="--user"
449
450
# create a Python venv on more recent releases:
451
PYTHON_VENV_PACKAGE=""
452
if [ ${RELEASE_CODENAME} == 'bookworm' ] ||
453
[ ${RELEASE_CODENAME} == 'lunar' ] ||
454
[ ${RELEASE_CODENAME} == 'mantic' ]; then
455
PYTHON_VENV_PACKAGE=python3.11-venv
456
elif [ ${RELEASE_CODENAME} == 'noble' ]; then
457
PYTHON_VENV_PACKAGE=python3.12-venv
458
elif [ ${RELEASE_CODENAME} == 'oracular' ]; then
459
PYTHON_VENV_PACKAGE=python3.12-venv
460
elif [ ${RELEASE_CODENAME} == 'trixie' ] ||
461
[ ${RELEASE_CODENAME} == 'plucky' ] ||
462
[ ${RELEASE_CODENAME} == 'questing' ] ||
463
false; then
464
PYTHON_VENV_PACKAGE=python3-venv
465
fi
466
467
if [ -n "$PYTHON_VENV_PACKAGE" ]; then
468
$APT_GET install $PYTHON_VENV_PACKAGE
469
470
# Check if venv already exists in ARDUPILOT_ROOT (check both venv-ardupilot and venv)
471
VENV_PATH=""
472
if [ -d "$ARDUPILOT_ROOT/venv-ardupilot" ]; then
473
VENV_PATH="$ARDUPILOT_ROOT/venv-ardupilot"
474
echo "Found existing venv at $VENV_PATH"
475
elif [ -d "$ARDUPILOT_ROOT/venv" ]; then
476
VENV_PATH="$ARDUPILOT_ROOT/venv"
477
echo "Found existing venv at $VENV_PATH"
478
elif [ -d "$ARDUPILOT_ROOT/.venv" ]; then
479
VENV_PATH="$ARDUPILOT_ROOT/.venv"
480
echo "Found existing venv at $VENV_PATH"
481
else
482
VENV_PATH="$HOME/venv-ardupilot"
483
echo "Creating new venv at $VENV_PATH"
484
python3 -m venv --system-site-packages "$VENV_PATH"
485
fi
486
487
SOURCE_LINE="source $VENV_PATH/bin/activate"
488
489
# activate it:
490
$SOURCE_LINE
491
PIP_USER_ARGUMENT=""
492
493
if [[ -z "${DO_PYTHON_VENV_ENV}" ]] && maybe_prompt_user "Make ArduPilot venv default for python [N/y]?\nThis means that any terminal will open and load ArduPilot venv" ; then
494
DO_PYTHON_VENV_ENV=1
495
fi
496
497
if [[ $DO_PYTHON_VENV_ENV -eq 1 ]]; then
498
echo $SOURCE_LINE >> ~/$SHELL_LOGIN
499
else
500
echo "Please use \`$SOURCE_LINE\` to activate the ArduPilot venv"
501
fi
502
fi
503
504
# try update packaging, setuptools and wheel before installing pip package that may need compilation
505
SETUPTOOLS="setuptools"
506
if [ ${RELEASE_CODENAME} == 'focal' ]; then
507
SETUPTOOLS=setuptools==70.3.0
508
fi
509
$PIP install $PIP_USER_ARGUMENT -U pip packaging $SETUPTOOLS wheel
510
511
if [ "$GITHUB_ACTIONS" == "true" ]; then
512
PIP_USER_ARGUMENT+=" --progress-bar off"
513
fi
514
515
if [ ${RELEASE_CODENAME} == 'trixie' ] ||
516
[ ${RELEASE_CODENAME} == 'bookworm' ] ||
517
[ ${RELEASE_CODENAME} == 'lunar' ] ||
518
[ ${RELEASE_CODENAME} == 'mantic' ] ||
519
[ ${RELEASE_CODENAME} == 'noble' ] ||
520
[ ${RELEASE_CODENAME} == 'oracular' ] ||
521
[ ${RELEASE_CODENAME} == 'plucky' ] ||
522
[ ${RELEASE_CODENAME} == 'questing' ] ||
523
false; then
524
# must do this ahead of wxPython pip3 run :-/
525
$PIP install $PIP_USER_ARGUMENT -U attrdict3
526
fi
527
528
# install Python packages one-at-a-time so it is clear which package
529
# is causing problems:
530
for PACKAGE in $PYTHON_PKGS; do
531
if [ "$PACKAGE" == "wxpython" ]; then
532
echo "##### $PACKAGE takes a *VERY* long time to install (~30 minutes). Be patient."
533
# Use wheel repository for specific supported Ubuntu releases only
534
case ${RELEASE_CODENAME} in
535
focal)
536
echo "##### Adding wxpython wheel repository for faster installation"
537
WXPYTHON_WHEEL_REPO="https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-20.04"
538
time $PIP install $PIP_USER_ARGUMENT -U -f $WXPYTHON_WHEEL_REPO $PACKAGE
539
;;
540
jammy)
541
echo "##### Adding wxpython wheel repository for faster installation"
542
WXPYTHON_WHEEL_REPO="https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-22.04"
543
time $PIP install $PIP_USER_ARGUMENT -U -f $WXPYTHON_WHEEL_REPO $PACKAGE
544
;;
545
noble)
546
echo "##### Adding wxpython wheel repository for faster installation"
547
WXPYTHON_WHEEL_REPO="https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-24.04"
548
time $PIP install $PIP_USER_ARGUMENT -U -f $WXPYTHON_WHEEL_REPO $PACKAGE
549
;;
550
*)
551
echo "##### Installing wxpython from PyPI (no specific wheel repository for this release)"
552
time $PIP install $PIP_USER_ARGUMENT -U $PACKAGE
553
;;
554
esac
555
else
556
time $PIP install $PIP_USER_ARGUMENT -U $PACKAGE
557
fi
558
done
559
560
# somehow Plucky really wants Pillow reinstalled or MAVProxy's map
561
# won't load (version mismatch between "Core" and "Pillow")
562
if [ ${RELEASE_CODENAME} == 'plucky' ] ||
563
${RELEASE_CODENAME} == 'questing' ] ||
564
false; then
565
$PIP install --force-reinstall pillow
566
fi
567
568
if [[ -z "${DO_AP_STM_ENV}" ]] && maybe_prompt_user "Install ArduPilot STM32 toolchain [N/y]?" ; then
569
DO_AP_STM_ENV=1
570
fi
571
572
heading "Removing modemmanager and brltty package that could conflict with firmware uploading"
573
if package_is_installed "modemmanager"; then
574
$APT_GET remove modemmanager
575
fi
576
if package_is_installed "brltty"; then
577
$APT_GET remove brltty
578
fi
579
echo "Done!"
580
581
CCACHE_PATH=$(which ccache)
582
if [[ $DO_AP_STM_ENV -eq 1 ]]; then
583
install_arm_none_eabi_toolchain
584
fi
585
586
heading "Adding ArduPilot Tools to environment"
587
588
if [[ $DO_AP_STM_ENV -eq 1 ]]; then
589
exportline="export PATH=$OPT/$ARM_ROOT/bin:\$PATH";
590
grep -Fxq "$exportline" ~/$SHELL_LOGIN 2>/dev/null || {
591
if maybe_prompt_user "Add $OPT/$ARM_ROOT/bin to your PATH [N/y]?" ; then
592
echo "$exportline" >> ~/$SHELL_LOGIN
593
eval "$exportline"
594
else
595
echo "Skipping adding $OPT/$ARM_ROOT/bin to PATH."
596
fi
597
}
598
fi
599
600
exportline2="export PATH=\"$ARDUPILOT_ROOT/$ARDUPILOT_TOOLS:\"\$PATH";
601
grep -Fxq "$exportline2" ~/$SHELL_LOGIN 2>/dev/null || {
602
if maybe_prompt_user "Add $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to your PATH [N/y]?" ; then
603
echo "$exportline2" >> ~/$SHELL_LOGIN
604
eval "$exportline2"
605
else
606
echo "Skipping adding $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to PATH."
607
fi
608
}
609
610
if [[ $SKIP_AP_COMPLETION_ENV -ne 1 ]]; then
611
exportline3="source \"$ARDUPILOT_ROOT/Tools/completion/completion.bash\"";
612
grep -Fxq "$exportline3" ~/$SHELL_LOGIN 2>/dev/null || {
613
if maybe_prompt_user "Add ArduPilot Bash Completion to your bash shell [N/y]?" ; then
614
echo "$exportline3" >> ~/.bashrc
615
eval "$exportline3"
616
else
617
echo "Skipping adding ArduPilot Bash Completion."
618
fi
619
}
620
fi
621
622
exportline4="export PATH=/usr/lib/ccache:\$PATH";
623
grep -Fxq "$exportline4" ~/$SHELL_LOGIN 2>/dev/null || {
624
if maybe_prompt_user "Append CCache to your PATH [N/y]?" ; then
625
echo "$exportline4" >> ~/$SHELL_LOGIN
626
eval "$exportline4"
627
else
628
echo "Skipping appending CCache to PATH."
629
fi
630
}
631
echo "Done!"
632
633
if [[ $SKIP_AP_GIT_CHECK -ne 1 ]]; then
634
if [ -d ".git" ]; then
635
heading "Update git submodules"
636
cd "$ARDUPILOT_ROOT"
637
git submodule update --init --recursive
638
echo "Done!"
639
fi
640
fi
641
642
if $IS_DOCKER; then
643
echo "Finalizing ArduPilot env for Docker"
644
echo "source ~/.ardupilot_env">> ~/.bashrc
645
fi
646
647
echo "---------- $0 end ----------"
648
649