Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/environment_install/install-prereqs-mac.sh
Views: 1798
#!/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#install command line tools49echo "Checking CLI Tools installed..."50{51ERROR=$(xcode-select --install 2>&1 > /dev/null)52} ||53{54if [[ $ERROR != *"ommand line tools are already installed"* ]]; then55echo "$ERROR" 1>&256exit 157fi58}5960# ArduPilot official Toolchain for STM32 boards61function install_arm_none_eabi_toolchain() {62# GNU Tools for ARM Embedded Processors63# (see https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)64ARM_ROOT="gcc-arm-none-eabi-10-2020-q4-major"65ARM_TARBALL="$ARM_ROOT-mac.tar.bz2"66ARM_TARBALL_URL="https://firmware.ardupilot.org/Tools/STM32-tools/$ARM_TARBALL"67if [ ! -d $OPT/$ARM_ROOT ]; then68(69cd $OPT;70echo "Installing toolchain for STM32 Boards"71echo "Downloading from ArduPilot server"72sudo wget $ARM_TARBALL_URL73echo "Installing..."74sudo tar xjf ${ARM_TARBALL}75echo "... Cleaning"76sudo rm ${ARM_TARBALL};77)78fi79echo "Registering STM32 Toolchain for ccache"80sudo mkdir -p /usr/local/opt/ccache/libexec81sudo ln -s -f $CCACHE_PATH /usr/local/opt/ccache/libexec/arm-none-eabi-g++82sudo ln -s -f $CCACHE_PATH /usr/local/opt/ccache/libexec/arm-none-eabi-gcc83echo "Done!"84}8586function maybe_prompt_user() {87if $ASSUME_YES; then88return 089else90read -p "$1"91if [[ $REPLY =~ ^[Yy]$ ]]; then92return 093else94return 195fi96fi97}9899# delete links installed by github in /usr/local/bin; installing or100# upgrading python via brew fails if these links are in place. brew101# auto-updates things when you install other packages which depend on102# more recent versions.103# see https://github.com/orgs/Homebrew/discussions/3895104find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete105106# brew update randomly failing on CI, so ignore errors:107brew update108brew install --force --overwrite gawk coreutils wget109110PIP=pip111if maybe_prompt_user "Install python using pyenv [N/y]?" ; then112echo "Checking pyenv..."113{114$(which -s pyenv)115} ||116{117echo "Installing pyenv"118curl https://pyenv.run | bash119120pushd $HOME/.pyenv121git fetch --tags122git checkout v2.3.12123popd124exportline="export PYENV_ROOT=\$HOME/.pyenv"125echo $exportline >> ~/$SHELL_LOGIN126exportline="export PATH=\$PYENV_ROOT/bin:\$PATH"127echo $exportline >> ~/$SHELL_LOGIN128evalline="eval \"\$(pyenv init --path)\""129echo $evalline >> ~/$SHELL_LOGIN130evalline="eval \"\$(pyenv init -)\""131echo $evalline >> ~/$SHELL_LOGIN132source ~/$SHELL_LOGIN133}134echo "pyenv installed"135{136$(pyenv global 3.10.4)137} || {138env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.10.4139pyenv global 3.10.4140}141fi142143144if [[ -z "${DO_AP_STM_ENV}" ]] && maybe_prompt_user "Install ArduPilot STM32 toolchain [N/y]?" ; then145DO_AP_STM_ENV=1146fi147148echo "Checking ccache..."149{150$(which -s ccache)151} ||152{153brew install ccache154exportline="export PATH=/usr/local/opt/ccache/libexec:\$PATH";155eval $exportline156}157CCACHE_PATH=$(which ccache)158159if [[ $DO_AP_STM_ENV -eq 1 ]]; then160install_arm_none_eabi_toolchain161fi162163PYTHON_PKGS="future lxml pymavlink MAVProxy pexpect geocoder flake8 junitparser empy==3.3.4 dronecan"164# add some Python packages required for commonly-used MAVProxy modules and hex file generation:165if [[ $SKIP_AP_EXT_ENV -ne 1 ]]; then166PYTHON_PKGS="$PYTHON_PKGS intelhex gnureadline"167fi168# add some packages required for commonly-used MAVProxy modules:169if [[ $SKIP_AP_GRAPHIC_ENV -ne 1 ]]; then170PYTHON_PKGS="$PYTHON_PKGS wxPython billiard"171fi172173$PIP install --upgrade pip174$PIP install wheel175$PIP install $PYTHON_PKGS176177echo "Adding ArduPilot Tools to environment"178179SCRIPT_DIR=$(dirname $(grealpath ${BASH_SOURCE[0]}))180ARDUPILOT_ROOT=$(grealpath "$SCRIPT_DIR/../../")181182if [[ $DO_AP_STM_ENV -eq 1 ]]; then183exportline="export PATH=$OPT/$ARM_ROOT/bin:\$PATH";184grep -Fxq "$exportline" ~/$SHELL_LOGIN 2>/dev/null || {185if maybe_prompt_user "Add $OPT/$ARM_ROOT/bin to your PATH [N/y]?" ; then186echo $exportline >> ~/$SHELL_LOGIN187eval $exportline188else189echo "Skipping adding $OPT/$ARM_ROOT/bin to PATH."190fi191}192fi193194exportline2="export PATH=$ARDUPILOT_ROOT/$ARDUPILOT_TOOLS:\$PATH";195grep -Fxq "$exportline2" ~/$SHELL_LOGIN 2>/dev/null || {196if maybe_prompt_user "Add $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to your PATH [N/y]?" ; then197echo $exportline2 >> ~/$SHELL_LOGIN198eval $exportline2199else200echo "Skipping adding $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to PATH."201fi202}203204if [[ $SKIP_AP_COMPLETION_ENV -ne 1 ]]; then205exportline3="source $ARDUPILOT_ROOT/Tools/completion/$AP_COMPLETION_SCR";206grep -Fxq "$exportline3" ~/$SHELL_LOGIN 2>/dev/null || {207if maybe_prompt_user "Add ArduPilot Bash Completion to your bash shell [N/y]?" ; then208echo $exportline3 >> ~/$SHELL_LOGIN209eval $exportline3210else211echo "Skipping adding ArduPilot Bash Completion."212fi213}214fi215216exportline4="export PATH=/usr/local/opt/ccache/libexec:\$PATH";217grep -Fxq "$exportline4" ~/$SHELL_LOGIN 2>/dev/null || {218if maybe_prompt_user "Append CCache to your PATH [N/y]?" ; then219echo $exportline4 >> ~/$SHELL_LOGIN220eval $exportline4221else222echo "Skipping appending CCache to PATH."223fi224}225echo "Done!"226227git submodule update --init --recursive228229echo "finished"230231232