setup: robustify install script and update deps

* increased support for running within a container
* optionally install OpenJDK 14
* optionally install RTPS
* adds better output messages
This commit is contained in:
Ramon Roche
2022-01-31 07:59:55 -08:00
parent c6a019a9d3
commit 92deb37f64
+275 -155
View File
@@ -2,20 +2,22 @@
set -e set -e
## Bash script to setup PX4 development environment on Ubuntu LTS (20.04, 18.04, 16.04). ## Bash script to setup PX4 development environment on Ubuntu LTS (20.04, 18.04).
## Can also be used in docker. ## Can also be used in docker.
## ##
## Installs: ## Installs:
## - Common dependencies and tools for nuttx, jMAVSim, Gazebo ## - Common dependencies and tools for NuttX, jMAVSim, Gazebo
## - NuttX toolchain (omit with arg: --no-nuttx) ## - NuttX toolchain (omit with arg: --no-nuttx)
## - jMAVSim and Gazebo9 simulator (omit with arg: --no-sim-tools) ## - jMAVSim and Gazebo simulator (omit with arg: --no-sim-tools)
## ## Optional:
## Not Installs: ## - FastRTPS and FastCDR (with args: --with-rtps)
## - FastRTPS and FastCDR
INSTALL_NUTTX="true" INSTALL_NUTTX="true"
INSTALL_SIM="true" INSTALL_SIM="true"
INSTALL_ARCH=`uname -m` INSTALL_ARCH=`uname -m`
INSTALL_RTPS="false"
INSTALL_JAVA="false"
INSIDE_DOCKER="false"
# Parse arguments # Parse arguments
for arg in "$@" for arg in "$@"
@@ -28,19 +30,19 @@ do
INSTALL_SIM="false" INSTALL_SIM="false"
fi fi
done if [[ $arg == "--with-rtps" ]]; then
INSTALL_RTPS="true"
fi
# detect if running in docker if [[ $arg == "--with-java" ]]; then
if [ -f /.dockerenv ]; then INSTALL_JAVA="true"
echo "Running within docker, installing initial dependencies"; fi
apt-get --quiet -y update && DEBIAN_FRONTEND=noninteractive apt-get --quiet -y install \
ca-certificates \ if [[ $arg == "--from-docker" ]]; then
gnupg \ INSIDE_DOCKER="true"
lsb-core \ fi
sudo \
wget \ done
;
fi
# script directory # script directory
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
@@ -69,88 +71,117 @@ elif [[ "${UBUNTU_RELEASE}" == "20.04" ]]; then
echo "Ubuntu 20.04" echo "Ubuntu 20.04"
fi fi
VERBOSE_BAR="####################"
echo
echo $VERBOSE_BAR
echo "#⚡️ Starting PX4 Dependency Installer for Ubuntu ${UBUNTU_RELEASE} (${INSTALL_ARCH})"
echo "# Options:
#
# - Install NuttX = ${INSTALL_NUTTX}
# - Install Java = ${INSTALL_JAVA}
# - Install Simulation = ${INSTALL_SIM}
# - Install RTPS = ${INSTALL_RTPS}"
echo $VERBOSE_BAR
echo
echo echo
echo "Installing PX4 general dependencies" echo $VERBOSE_BAR
echo "🍻 Installing System Dependencies"
echo $VERBOSE_BAR
echo
sudo apt-get update -y --quiet sudo apt-get update -y --quiet
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \ sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
astyle \
build-essential \ build-essential \
cmake \ g++ \
cppcheck \ gcc \
file \ gdb \
g++ \ astyle \
gcc \ cmake \
gdb \ cppcheck \
git \ file \
lcov \ git \
libxml2-dev \ lcov \
libxml2-utils \ libxml2-dev \
make \ libxml2-utils \
ninja-build \ make \
python3 \ ninja-build \
python3-dev \ python3 \
python3-pip \ python3-dev \
python3-setuptools \ python3-pip \
python3-wheel \ python3-setuptools \
rsync \ python3-wheel \
shellcheck \ rsync \
unzip \ shellcheck \
zip \ unzip \
; zip \
libssl-dev \
;
# Python3 dependencies # Python 3 dependencies
echo echo
echo "Installing PX4 Python3 dependencies" echo $VERBOSE_BAR
echo "🍻 Installing Python dependencies"
echo $VERBOSE_BAR
echo
if [ -n "$VIRTUAL_ENV" ]; then if [ -n "$VIRTUAL_ENV" ]; then
# virtual envrionments don't allow --user option # virtual envrionments don't allow --user option
python -m pip install -r ${DIR}/requirements.txt python -m pip install -r ${DIR}/requirements.txt
else else
# older versions of Ubuntu require --user option # older versions of Ubuntu require --user option
python3 -m pip install --user -r ${DIR}/requirements.txt if [[ $INSIDE_DOCKER == "true" ]]; then
# when running inside a docker container we don't need to install
# under --user since the installer user is root
# its best to install packages globaly for any user to find
python3 -m pip install -r /tmp/requirements.txt
else
python3 -m pip install --user -r ${DIR}/requirements.txt
fi
fi fi
# NuttX toolchain (arm-none-eabi-gcc) # NuttX toolchain (arm-none-eabi-gcc)
if [[ $INSTALL_NUTTX == "true" ]]; then if [[ $INSTALL_NUTTX == "true" ]]; then
echo echo
echo "Installing NuttX dependencies" echo $VERBOSE_BAR
echo "🍻 Installing NuttX dependencies"
echo $VERBOSE_BAR
echo
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \ sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
automake \ automake \
binutils-dev \ binutils-dev \
bison \ bison \
build-essential \ flex \
flex \ genromfs \
g++-multilib \ gettext \
gcc-multilib \ gperf \
gdb-multiarch \ libelf-dev \
genromfs \ libexpat-dev \
gettext \ libgmp-dev \
gperf \ libisl-dev \
libelf-dev \ libmpc-dev \
libexpat-dev \ libmpfr-dev \
libgmp-dev \ libncurses5 \
libisl-dev \ libncurses5-dev \
libmpc-dev \ libncursesw5-dev \
libmpfr-dev \ libtool \
libncurses5 \ pkg-config \
libncurses5-dev \ screen \
libncursesw5-dev \ texinfo \
libtool \ u-boot-tools \
pkg-config \ util-linux \
screen \ vim-common \
texinfo \ g++-arm-linux-gnueabihf \
u-boot-tools \ gcc-arm-linux-gnueabihf \
util-linux \ ;
vim-common \
; if [[ "${UBUNTU_RELEASE}" == "20.04" ]]; then
if [[ "${UBUNTU_RELEASE}" == "20.04" ]]; then sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \ kconfig-frontends \
kconfig-frontends \ ;
; fi
fi
if [ -n "$USER" ]; then if [ -n "$USER" ]; then
@@ -158,97 +189,186 @@ if [[ $INSTALL_NUTTX == "true" ]]; then
sudo usermod -a -G dialout $USER sudo usermod -a -G dialout $USER
fi fi
# arm-none-eabi-gcc NUTTX_GCC_VERSION="9-2020-q2-update"
NUTTX_GCC_VERSION="9-2020-q2-update" NUTTX_GCC_VERSION_SHORT="9-2020q2"
NUTTX_GCC_VERSION_SHORT="9-2020q2" echo
echo $VERBOSE_BAR
echo "🍻 Verifying proper gcc version (${NUTTX_GCC_VERSION}), and installing if not found"
echo
source $HOME/.profile # load changed path for the case the script is reran before relogin source $HOME/.profile # load changed path for the case the script is reran before relogin
if [ $(which arm-none-eabi-gcc) ]; then if [ $(which arm-none-eabi-gcc) ]; then
GCC_VER_STR=$(arm-none-eabi-gcc --version) GCC_VER_STR=$(arm-none-eabi-gcc --version)
GCC_FOUND_VER=$(echo $GCC_VER_STR | grep -c "${NUTTX_GCC_VERSION}") GCC_VER_FOUND=$(echo $GCC_VER_STR | grep -c "${NUTTX_GCC_VERSION}")
fi fi
if [[ "$GCC_FOUND_VER" == "1" ]]; then if [[ $(echo $GCC_VER_STR | grep -c "${NUTTX_GCC_VERSION}") == "1" ]]; then
echo "arm-none-eabi-gcc-${NUTTX_GCC_VERSION} found, skipping installation" echo "📌 Skipping installation, the arm cross compiler was found"
echo $VERBOSE_BAR
echo
else else
echo "Installing arm-none-eabi-gcc-${NUTTX_GCC_VERSION}"; echo "📌 The arm cross compiler was not found";
wget -O /tmp/gcc-arm-none-eabi-${NUTTX_GCC_VERSION}-linux.tar.bz2 https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/${NUTTX_GCC_VERSION_SHORT}/gcc-arm-none-eabi-${NUTTX_GCC_VERSION}-${INSTALL_ARCH}-linux.tar.bz2 && \ echo " * Installing arm-none-eabi-gcc-${NUTTX_GCC_VERSION}";
sudo tar -jxf /tmp/gcc-arm-none-eabi-${NUTTX_GCC_VERSION}-linux.tar.bz2 -C /opt/; # The arm cross compiler hosting provider is known to throttle download speeds
# for users who reach a certain limit of downloads in a given time frame
# for this reason we allow for using a previously downloaded file
# this is specially helpful when debugging this installer script
# from within a container COMPILER_PATH="/tmp/gcc-arm-none-eabi-${NUTTX_GCC_VERSION}-linux.tar.bz2"
COMPILER_NAME="gcc-arm-none-eabi-${NUTTX_GCC_VERSION}"
COMPILER_PATH="/tmp/$COMPILER_NAME-linux.tar.bz2"
if [ ! -f "$COMPILER_PATH" ]; then
wget -O $COMPILER_PATH https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/${NUTTX_GCC_VERSION_SHORT}/${COMPILER_NAME}-${INSTALL_ARCH}-linux.tar.bz2
fi
sudo tar -jxf $COMPILER_PATH -C /opt/;
# add arm-none-eabi-gcc to user's PATH # add arm-none-eabi-gcc to user's PATH
exportline="export PATH=/opt/gcc-arm-none-eabi-${NUTTX_GCC_VERSION}/bin:\$PATH" exportline="export PATH=\"/opt/${COMPILER_NAME}/bin:\$PATH\""
if [[ $INSIDE_DOCKER == "true" ]]; then
# when running on a docker container its best to set the environment globally
# since we don't know which user is going to be running commands on the container
touch /etc/profile.d/px4env.sh
echo $exportline >> /etc/profile.d/px4env.sh
else
if grep -Fxq "$exportline" $HOME/.profile; then
echo "${NUTTX_GCC_VERSION} path already set.";
else
echo $exportline >> $HOME/.profile;
fi
fi
echo " * arm-none-eabi-gcc (${NUTTX_GCC_VERSION}) Installed Succesful to /opt/${COMPILER_NAME}/bin"
echo $VERBOSE_BAR
echo
fi
fi
# Install JAVA
if [[ $INSTALL_JAVA == "true" ]]; then
JDK_VERSION="14.0.2_12"
echo
echo $VERBOSE_BAR
echo "🍻 Installing Java JDK
* Version: $JDK_VERSION
* Path: /opt/jdk-14.0.2+12"
echo $VERBOSE_BAR
echo
JDK_DOWNLOAD="/tmp/OpenJDK14U-jdk_x64_linux_hotspot_$JDK_VERSION.tar.gz"
wget -O $JDK_DOWNLOAD https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.2%2B12/OpenJDK14U-jdk_x64_linux_hotspot_14.0.2_12.tar.gz
sudo tar -xzf $JDK_DOWNLOAD -C /opt/
export PATH="/opt/jdk-14.0.2+12/bin:$PATH"
fi
# Fast-RTPS
if [[ $INSTALL_RTPS == "true" ]]; then
echo
echo $VERBOSE_BAR
echo "🍻 Installing Fast-RTPS"
echo $VERBOSE_BAR
echo
GRADLE_VERSION="6.4.1"
wget -O "/tmp/gradle-$GRADLE_VERSION-bin.zip" "https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip" \
&& unzip -d /opt/gradle "/tmp/gradle-$GRADLE_VERSION-bin.zip"
export PATH="$PATH:/opt/gradle/gradle-$GRADLE_VERSION/bin"
# Intall foonathan_memory from source as it is required to Fast-RTPS >= 1.9
git clone https://github.com/eProsima/foonathan_memory_vendor.git /tmp/foonathan_memory \
&& cd /tmp/foonathan_memory \
&& mkdir build && cd build \
&& cmake .. \
&& cmake --build . --target install -- -j $(nproc)
# Fast-DDS (Fast-RTPS 2.1.1)
git clone --recursive https://github.com/eProsima/Fast-DDS.git -b v2.1.1 /tmp/FastRTPS-2.1.1 \
&& cd /tmp/FastRTPS-2.1.1 \
&& mkdir build && cd build \
&& cmake -DTHIRDPARTY=ON -DSECURITY=ON .. \
&& cmake --build . --target install -- -j $(nproc)
# Fast-RTPS-Gen 1.0.4
git clone --recursive https://github.com/eProsima/Fast-DDS-Gen.git -b v1.0.4 /tmp/Fast-RTPS-Gen-1.0.4 \
&& cd /tmp/Fast-RTPS-Gen-1.0.4 \
&& gradle assemble \
&& gradle install
if grep -Fxq "$exportline" $HOME/.profile; then
echo "${NUTTX_GCC_VERSION} path already set.";
else
echo $exportline >> $HOME/.profile;
fi
fi
fi fi
# Simulation tools # Simulation tools
if [[ $INSTALL_SIM == "true" ]]; then if [[ $INSTALL_SIM == "true" ]]; then
echo echo
echo "Installing PX4 simulation dependencies" echo $VERBOSE_BAR
echo "🍻 Installing PX4 Simulation Tools"
echo
# General simulation dependencies if [[ "${UBUNTU_RELEASE}" == "18.04" ]]; then
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \ gazebo_version=9
bc \ elif [[ "${UBUNTU_RELEASE}" == "20.04" ]]; then
; gazebo_version=11
fi
if [[ "${UBUNTU_RELEASE}" == "18.04" ]]; then echo " * Gazebo Version $gazebo_version"
java_version=11 echo $VERBOSE_BAR
gazebo_version=9
elif [[ "${UBUNTU_RELEASE}" == "20.04" ]]; then
java_version=13
gazebo_version=11
else
java_version=14
gazebo_version=11
fi
# Java (jmavsim or fastrtps)
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
ant \
openjdk-$java_version-jre \
openjdk-$java_version-jdk \
libvecmath-java \
;
# Set Java 11 as default # General simulation dependencies
sudo update-alternatives --set java $(update-alternatives --list java | grep "java-$java_version") sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
bc \
ant \
libvecmath-java \
;
# Gazebo # Installing Gazebo and dependencies
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' # Setup OSRF Gazebo repository
wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add - sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
# Update list, since new gazebo-stable.list has been added wget http://packages.osrfoundation.org/gazebo.key -O - | sudo apt-key add -
sudo apt-get update -y --quiet # Update list, since new gazebo-stable.list has been added
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \ sudo apt-get update -y --quiet
dmidecode \ sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
gazebo$gazebo_version \ dmidecode \
gstreamer1.0-plugins-bad \ gazebo$gazebo_version \
gstreamer1.0-plugins-base \ gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-good \ gstreamer1.0-plugins-base \
gstreamer1.0-plugins-ugly \ gstreamer1.0-plugins-good \
gstreamer1.0-libav \ gstreamer1.0-plugins-ugly \
libeigen3-dev \ gstreamer1.0-libav \
libgazebo$gazebo_version-dev \ libeigen3-dev \
libgstreamer-plugins-base1.0-dev \ libgazebo$gazebo_version-dev \
libimage-exiftool-perl \ libgstreamer-plugins-base1.0-dev \
libopencv-dev \ libimage-exiftool-perl \
libxml2-utils \ libopencv-dev \
pkg-config \ libxml2-utils \
protobuf-compiler \ pkg-config \
; protobuf-compiler \
;
if sudo dmidecode -t system | grep -q "Manufacturer: VMware, Inc." ; then if sudo dmidecode -t system | grep -q "Manufacturer: VMware, Inc." ; then
# fix VMWare 3D graphics acceleration for gazebo # fix VMWare 3D graphics acceleration for gazebo
echo "export SVGA_VGPU10=0" >> ~/.profile echo "export SVGA_VGPU10=0" >> ~/.profile
fi fi
fi fi
if [[ $INSTALL_NUTTX == "true" ]]; then if [[ $INSIDE_DOCKER == "true" ]]; then
echo # cleanup installation
echo "Relogin or reboot computer before attempting to build NuttX targets" rm -rf /tmp/
fi fi
if [[ $INSIDE_DOCKER == "false" ]] && [[ $INSTALL_NUTTX == "true" ]]; then
echo
echo $VERBOSE_BAR
echo "💡 We recommend you relogin/reboot before attempting to build NuttX targets"
echo $VERBOSE_BAR
echo
fi
echo
echo
echo $VERBOSE_BAR
echo "#⚡️ PX4 Dependency Installer Ended Succesfully
#
# For more information on PX4 Autopilot check out our docs
# at docs.px4.io, if you find a bug please file an issue
# on GitHub https://github.com/px4/px4-autopilot"
echo $VERBOSE_BAR
echo