Path: blob/master/Tools/environment_install/install-prereqs-mac.sh
9688 views
#!/usr/bin/env bash1echo "---------- $0 start ----------"2set -e3set -x45if [ $EUID == 0 ]; then6echo "Please do not run this script as root; don't sudo it!"7exit 18fi910if [[ $SHELL == *"zsh"* ]]; then11AP_COMPLETION_SCR="completion.zsh"12SHELL_LOGIN=".zshrc"13elif [[ $SHELL == *"bash"* ]]; then14AP_COMPLETION_SCR="completion.bash"15SHELL_LOGIN=".bash_profile"16else17echo "Unsupported shell"18exit 119fi2021OPT="/opt"22# Ardupilot Tools23ARDUPILOT_TOOLS="Tools/autotest"2425ASSUME_YES=false26sep="##############################################"2728OPTIND=1 # Reset in case getopts has been used previously in the shell.29while getopts "y" opt; do30case "$opt" in31\?)32exit 133;;34y) ASSUME_YES=true35;;36esac37done383940echo "Checking homebrew..."41$(which -s brew) ||42{43echo "installing homebrew..."44/usr/bin/env bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"45}46echo "Homebrew installed"4748# Detect Homebrew prefix (different on Apple Silicon vs Intel)49HOMEBREW_PREFIX="$(brew --prefix)"5051#install command line tools52echo "Checking CLI Tools installed..."53{54ERROR=$(xcode-select --install 2>&1 > /dev/null)55} ||56{57if [[ $ERROR != *"ommand line tools are already installed"* ]]; then58echo "$ERROR" 1>&259exit 160fi61}6263# ArduPilot official Toolchain for STM32 boards64function install_arm_none_eabi_toolchain() {65# GNU Tools for ARM Embedded Processors66# (see https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)67ARM_ROOT="gcc-arm-none-eabi-10-2020-q4-major"68ARM_TARBALL="$ARM_ROOT-mac.tar.bz2"69ARM_TARBALL_URL="https://firmware.ardupilot.org/Tools/STM32-tools/$ARM_TARBALL"70if [ ! -d $OPT/$ARM_ROOT ]; then71(72cd $OPT;73echo "Installing toolchain for STM32 Boards"74echo "Downloading from ArduPilot server"75sudo wget $ARM_TARBALL_URL76echo "Installing..."77sudo tar xjf ${ARM_TARBALL}78echo "... Cleaning"79sudo rm ${ARM_TARBALL};80)81fi82echo "Registering STM32 Toolchain for ccache"83sudo mkdir -p $HOMEBREW_PREFIX/opt/ccache/libexec84sudo ln -s -f $CCACHE_PATH $HOMEBREW_PREFIX/opt/ccache/libexec/arm-none-eabi-g++85sudo ln -s -f $CCACHE_PATH $HOMEBREW_PREFIX/opt/ccache/libexec/arm-none-eabi-gcc86echo "Done!"87}8889function maybe_prompt_user() {90if $ASSUME_YES; then91return 092else93read -p "$1"94if [[ $REPLY =~ ^[Yy]$ ]]; then95return 096else97return 198fi99fi100}101102# delete links installed by github in /usr/local/bin; installing or103# upgrading python via brew fails if these links are in place. brew104# auto-updates things when you install other packages which depend on105# more recent versions.106# see https://github.com/orgs/Homebrew/discussions/3895107# Note: /usr/local/bin may not exist on Apple Silicon Macs108if [ -d /usr/local/bin ]; then109find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete110fi111112# brew update randomly failing on CI, so ignore errors:113brew update114brew install --force --overwrite gawk coreutils wget115116PIP="python3 -m pip"117if maybe_prompt_user "Install python using pyenv [N/y]?" ; then118echo "Checking pyenv..."119{120$(which -s pyenv)121} ||122{123echo "Installing pyenv"124curl https://pyenv.run | bash125126pushd $HOME/.pyenv127git fetch --tags128git checkout v2.6.7129popd130exportline="export PYENV_ROOT=\$HOME/.pyenv"131echo $exportline >> ~/$SHELL_LOGIN132exportline="export PATH=\$PYENV_ROOT/bin:\$PATH"133echo $exportline >> ~/$SHELL_LOGIN134evalline="eval \"\$(pyenv init --path)\""135echo $evalline >> ~/$SHELL_LOGIN136evalline="eval \"\$(pyenv init -)\""137echo $evalline >> ~/$SHELL_LOGIN138source ~/$SHELL_LOGIN139}140echo "pyenv installed"141{142$(pyenv global 3.10.18)143} || {144env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.10.18145pyenv global 3.10.18146}147fi148149150if [[ -z "${DO_AP_STM_ENV}" ]] && maybe_prompt_user "Install ArduPilot STM32 toolchain [N/y]?" ; then151DO_AP_STM_ENV=1152fi153154echo "Checking ccache..."155{156$(which -s ccache)157} ||158{159brew install ccache160exportline="export PATH=$HOMEBREW_PREFIX/opt/ccache/libexec:\$PATH";161eval $exportline162}163CCACHE_PATH=$(which ccache)164165if [[ $DO_AP_STM_ENV -eq 1 ]]; then166install_arm_none_eabi_toolchain167fi168169PYTHON_PKGS="setuptools future lxml matplotlib pymavlink MAVProxy pexpect geocoder flake8 junitparser empy==3.3.4 dronecan"170# add some Python packages required for commonly-used MAVProxy modules and hex file generation:171if [[ $SKIP_AP_EXT_ENV -ne 1 ]]; then172PYTHON_PKGS="$PYTHON_PKGS intelhex gnureadline"173fi174# add some packages required for commonly-used MAVProxy modules:175if [[ $SKIP_AP_GRAPHIC_ENV -ne 1 ]]; then176PYTHON_PKGS="$PYTHON_PKGS wxPython billiard"177fi178179$PIP install --upgrade pip180$PIP install --force-reinstall wheel181$PIP install $PYTHON_PKGS182183echo "Adding ArduPilot Tools to environment"184185SCRIPT_DIR=$(dirname $(grealpath ${BASH_SOURCE[0]}))186ARDUPILOT_ROOT=$(grealpath "$SCRIPT_DIR/../../")187188if [[ $DO_AP_STM_ENV -eq 1 ]]; then189exportline="export PATH=$OPT/$ARM_ROOT/bin:\$PATH";190grep -Fxq "$exportline" ~/$SHELL_LOGIN 2>/dev/null || {191if maybe_prompt_user "Add $OPT/$ARM_ROOT/bin to your PATH [N/y]?" ; then192echo $exportline >> ~/$SHELL_LOGIN193eval $exportline194else195echo "Skipping adding $OPT/$ARM_ROOT/bin to PATH."196fi197}198fi199200exportline2="export PATH=$ARDUPILOT_ROOT/$ARDUPILOT_TOOLS:\$PATH";201grep -Fxq "$exportline2" ~/$SHELL_LOGIN 2>/dev/null || {202if maybe_prompt_user "Add $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to your PATH [N/y]?" ; then203echo $exportline2 >> ~/$SHELL_LOGIN204eval $exportline2205else206echo "Skipping adding $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to PATH."207fi208}209210if [[ $SKIP_AP_COMPLETION_ENV -ne 1 ]]; then211exportline3="source $ARDUPILOT_ROOT/Tools/completion/$AP_COMPLETION_SCR";212grep -Fxq "$exportline3" ~/$SHELL_LOGIN 2>/dev/null || {213if maybe_prompt_user "Add ArduPilot Bash Completion to your bash shell [N/y]?" ; then214echo $exportline3 >> ~/$SHELL_LOGIN215eval $exportline3216else217echo "Skipping adding ArduPilot Bash Completion."218fi219}220fi221222exportline4="export PATH=$HOMEBREW_PREFIX/opt/ccache/libexec:\$PATH";223grep -Fxq "$exportline4" ~/$SHELL_LOGIN 2>/dev/null || {224if maybe_prompt_user "Append CCache to your PATH [N/y]?" ; then225echo $exportline4 >> ~/$SHELL_LOGIN226eval $exportline4227else228echo "Skipping appending CCache to PATH."229fi230}231echo "Done!"232233git submodule update --init --recursive234235echo "finished"236237238