Skip to content

Commit

Permalink
Tools: Add scripts for Fedora systems
Browse files Browse the repository at this point in the history
  • Loading branch information
radityankn authored and Ryanf55 committed Dec 3, 2024
1 parent eaf20db commit 52ec360
Showing 1 changed file with 219 additions and 0 deletions.
219 changes: 219 additions & 0 deletions Tools/environment_install/install-prereqs-fedora.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
#!/usr/bin/env bash
echo "---------- $0 start ----------"
set -e
set -x
set +H

if [ $EUID == 0 ]; then
echo "Please do not run this script as root; don't sudo it!"
exit 1
fi


OPT="/opt"
# Ardupilot Tools
ARDUPILOT_TOOLS="Tools/autotest"

ASSUME_YES=false
QUIET=false
sep="##############################################"

OPTIND=1 # Reset in case getopts has been used previously in the shell.
while getopts "yq" opt; do
case "$opt" in
\?)
exit 1
;;
y) ASSUME_YES=true
;;
q) QUIET=true
;;
esac
done

DNF="sudo dnf install --setopt=install_weak_deps=False"
if $ASSUME_YES; then
DNF="sudo dnf install -y --setopt=install_weak_deps=False"
fi
PIP3=pip3
if $QUIET; then
PIP3="pip3 -q"
fi

function package_is_installed() {
rpm -q $1 &>/dev/null
}

function heading() {
echo "$sep"
echo $*
echo "$sep"
}

#Don't install python3, Fedora already has it anyway
#$DNF python3 || echo "Check dnf output for errors"

#As Fedora can have many python versions, we need to know which one is currently active
PYPKGVER=python$(python3 --version | cut -d' ' -f2 | awk -F. '{printf"%s.%s",$1,$2}')

BASE_PKGS="make automake gcc kernel-devel ccache git axel valgrind screen gcc-c++ xterm free-ttf-fonts SFML-devel zip glibc-static rsync"
#SITL_PKGS_FEDORA below is the only python packages here for fedora that does not follow naming convention. we should to improve the script
#integration for these packages
SITL_PKGS_FEDORA="python3-pyyaml python3-wxpython4"
SITL_PKGS="${PYPKGVER}-pip ${PYPKGVER}-devel ${PYPKGVER}-setuptools ${PYPKGVER}-wheel ${PYPKGVER}-lxml ${PYPKGVER}-pyparsing ${PYPKGVER}-opencv ${PYPKGVER}-numpy ${PYPKGVER}-scipy ${PYPKGVER}-matplotlib"

PYTHON_PKGS="future lxml pymavlink MAVProxy pexpect argparse pyparsing geocoder pyserial empy==3.3.4 ptyprocess dronecan"
PYTHON_PKGS+=" flake8 junitparser pygame intelhex psutil pyyaml"
# GNU Tools for ARM Embedded Processors
# (see https://launchpad.net/gcc-arm-embedded/)
ARM_ROOT="gcc-arm-none-eabi-10-2020-q4-major"
ARM_TARBALL="$ARM_ROOT-x86_64-linux.tar.bz2"
ARM_TARBALL_URL="https://firmware.ardupilot.org/Tools/STM32-tools/$ARM_TARBALL"

ARM_LINUX_ROOT=gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf
ARM_LINUX_GCC_URL="https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz"
ARM_LINUX_TARBALL="gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz"

function maybe_prompt_user() {
if $ASSUME_YES; then
return 0
else
read -p "$1"
if [[ $REPLY =~ ^[Yy]$ ]]; then
return 0
else
return 1
fi
fi
}

sudo usermod -a -G dialout "$USER"

$DNF $BASE_PKGS $SITL_PKGS $SITL_PKGS_FEDORA || echo "Check dnf output for errors"

python3 -m venv "$HOME"/venv-ardupilot

SHELL_LOGIN=".profile"
# activate it:
SOURCE_LINE="source $HOME/venv-ardupilot/bin/activate"
$SOURCE_LINE

if ! grep -Fxq "$SOURCE_LINE" ~/.bashrc; then
if [[ -z "${DO_PYTHON_VENV_ENV}" ]] && maybe_prompt_user "Make ArduPilot venv default for python [N/y]?" ; then
DO_PYTHON_VENV_ENV=1
fi

if [[ $DO_PYTHON_VENV_ENV -eq 1 ]]; then
echo $SOURCE_LINE >> ~/.bashrc
else
echo "Please use \`$SOURCE_LINE\` to activate the ArduPilot venv"
fi
fi

$PIP3 install -U pip packaging setuptools wheel
$PIP3 install -U attrdict3
$PIP3 install -U $PYTHON_PKGS

(
cd /usr/lib64/ccache
for C in arm-none-eabi-g++ arm-none-eabi-gcc arm-linux-gnueabihf-g++ arm-linux-gnueabihf-gcc; do
if [ ! -f "$C" ]; then
sudo ln -s ../../bin/ccache "$C"
fi
done
)

ccache --set-config sloppiness=file_macro,locale,time_macros
ccache --set-config ignore_options="--specs=nano.specs --specs=nosys.specs"

if [ ! -d $OPT/$ARM_ROOT ]; then
(
cd $OPT;
sudo axel -a -c $ARM_TARBALL_URL;
sudo tar xjf ${ARM_TARBALL};
sudo rm ${ARM_TARBALL};
)
fi

if [ ! -d $OPT/$ARM_LINUX_ROOT ]; then
(
cd $OPT;
sudo axel -a -c "${ARM_LINUX_GCC_URL}";
sudo tar xf ${ARM_LINUX_TARBALL};
sudo rm ${ARM_LINUX_TARBALL};
)
fi

heading "Removing modemmanager and brltty package that could conflict with firmware uploading"
if package_is_installed "ModemManager"; then
sudo dnf remove ModemManager
fi
if package_is_installed "brltty"; then
sudo dnf remove brltty
fi
echo "Done!"

heading "Adding ArduPilot Tools to environment"

SCRIPT_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
ARDUPILOT_ROOT=$(realpath "$SCRIPT_DIR/../../")


exportline="export PATH=$OPT/$ARM_ROOT/bin:\$PATH";
if ! grep -Fxq "$exportline" ~/$SHELL_LOGIN ; then
if maybe_prompt_user "Add $OPT/$ARM_ROOT/bin to your PATH [N/y]?" ; then
echo $exportline >> ~/$SHELL_LOGIN
else
echo "Skipping adding $OPT/$ARM_ROOT/bin to PATH."
fi
fi

exportline1="export PATH=$OPT/$ARM_LINUX_ROOT/bin:\$PATH";
if ! grep -Fxq "$exportline1" ~/$SHELL_LOGIN ; then
if maybe_prompt_user "Add $OPT/$ARM_LINUX_ROOT/bin to your PATH [N/y]?" ; then
echo $exportline1 >> ~/$SHELL_LOGIN
else
echo "Skipping adding $OPT/$ARM_LINUX_ROOT/bin to PATH."
fi
fi

exportline2="export PATH=$ARDUPILOT_ROOT/$ARDUPILOT_TOOLS:\$PATH";
if ! grep -Fxq "$exportline2" ~/$SHELL_LOGIN ; then
if maybe_prompt_user "Add $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to your PATH [N/y]?" ; then
echo $exportline2 >> ~/$SHELL_LOGIN
else
echo "Skipping adding $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to PATH."
fi
fi

exportline3="source $ARDUPILOT_ROOT/Tools/completion/completion.bash";
if ! grep -Fxq "$exportline3" ~/.bashrc ; then
if maybe_prompt_user "Add ArduPilot Bash Completion to your bash shell [N/y]?" ; then
echo $exportline3 >> ~/.bashrc
else
echo "Skipping adding ArduPilot Bash Completion."
fi
fi

exportline4="export PATH=/usr/lib64/ccache:\$PATH";
if ! grep -Fxq "$exportline4" ~/$SHELL_LOGIN ; then
if maybe_prompt_user "Append CCache to your PATH [N/y]?" ; then
echo $exportline4 >> ~/$SHELL_LOGIN
else
echo "Skipping appending CCache to PATH."
fi
fi
echo "Done!"

if [[ $SKIP_AP_GIT_CHECK -ne 1 ]]; then
cd "$ARDUPILOT_ROOT"
if [ -d ".git" ]; then
heading "Update git submodules"
cd $ARDUPILOT_ROOT
git submodule update --init --recursive
echo "Done!"
fi
fi

echo "---------- $0 end ----------"
echo "Done. Please log out and log in again."

0 comments on commit 52ec360

Please sign in to comment.