2023-12-04 05:55:08 -04:00
|
|
|
#!/usr/bin/env bash
|
2021-06-25 04:28:14 -03:00
|
|
|
echo "---------- $0 start ----------"
|
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
|
|
|
|
if [ $EUID == 0 ]; then
|
|
|
|
echo "Please do not run this script as root; don't sudo it!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $SHELL == *"zsh"* ]]; then
|
|
|
|
AP_COMPLETION_SCR="completion.zsh"
|
|
|
|
SHELL_LOGIN=".zshrc"
|
|
|
|
elif [[ $SHELL == *"bash"* ]]; then
|
|
|
|
AP_COMPLETION_SCR="completion.bash"
|
|
|
|
SHELL_LOGIN=".bash_profile"
|
|
|
|
else
|
|
|
|
echo "Unsupported shell"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
OPT="/opt"
|
|
|
|
# Ardupilot Tools
|
|
|
|
ARDUPILOT_TOOLS="Tools/autotest"
|
|
|
|
|
|
|
|
ASSUME_YES=false
|
|
|
|
sep="##############################################"
|
|
|
|
|
|
|
|
OPTIND=1 # Reset in case getopts has been used previously in the shell.
|
|
|
|
while getopts "y" opt; do
|
|
|
|
case "$opt" in
|
|
|
|
\?)
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
y) ASSUME_YES=true
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
2018-02-24 04:15:23 -04:00
|
|
|
echo "Checking homebrew..."
|
2021-06-25 04:28:14 -03:00
|
|
|
$(which -s brew) ||
|
|
|
|
{
|
2018-02-24 04:15:23 -04:00
|
|
|
echo "installing homebrew..."
|
2023-12-04 05:55:08 -04:00
|
|
|
/usr/bin/env bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
2021-06-25 04:28:14 -03:00
|
|
|
}
|
|
|
|
echo "Homebrew installed"
|
|
|
|
|
|
|
|
#install command line tools
|
|
|
|
echo "Checking CLI Tools installed..."
|
|
|
|
{
|
|
|
|
ERROR=$(xcode-select --install 2>&1 > /dev/null)
|
|
|
|
} ||
|
|
|
|
{
|
2024-02-24 14:05:38 -04:00
|
|
|
if [[ $ERROR != *"ommand line tools are already installed"* ]]; then
|
2021-06-25 04:28:14 -03:00
|
|
|
echo "$ERROR" 1>&2
|
|
|
|
exit 1
|
2018-02-24 04:15:23 -04:00
|
|
|
fi
|
2021-06-25 04:28:14 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
# ArduPilot official Toolchain for STM32 boards
|
|
|
|
function install_arm_none_eabi_toolchain() {
|
|
|
|
# GNU Tools for ARM Embedded Processors
|
|
|
|
# (see https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
|
2021-07-25 19:06:40 -03:00
|
|
|
ARM_ROOT="gcc-arm-none-eabi-10-2020-q4-major"
|
2021-06-25 04:28:14 -03:00
|
|
|
ARM_TARBALL="$ARM_ROOT-mac.tar.bz2"
|
|
|
|
ARM_TARBALL_URL="https://firmware.ardupilot.org/Tools/STM32-tools/$ARM_TARBALL"
|
|
|
|
if [ ! -d $OPT/$ARM_ROOT ]; then
|
|
|
|
(
|
|
|
|
cd $OPT;
|
|
|
|
echo "Installing toolchain for STM32 Boards"
|
|
|
|
echo "Downloading from ArduPilot server"
|
|
|
|
sudo wget $ARM_TARBALL_URL
|
|
|
|
echo "Installing..."
|
|
|
|
sudo tar xjf ${ARM_TARBALL}
|
|
|
|
echo "... Cleaning"
|
|
|
|
sudo rm ${ARM_TARBALL};
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
echo "Registering STM32 Toolchain for ccache"
|
2024-01-13 03:19:58 -04:00
|
|
|
sudo mkdir -p /usr/local/opt/ccache/libexec
|
2021-06-25 04:28:14 -03:00
|
|
|
sudo ln -s -f $CCACHE_PATH /usr/local/opt/ccache/libexec/arm-none-eabi-g++
|
|
|
|
sudo ln -s -f $CCACHE_PATH /usr/local/opt/ccache/libexec/arm-none-eabi-gcc
|
|
|
|
echo "Done!"
|
|
|
|
}
|
2018-02-24 04:15:23 -04:00
|
|
|
|
2021-06-25 04:28:14 -03:00
|
|
|
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
|
|
|
|
}
|
2018-02-24 04:15:23 -04:00
|
|
|
|
2022-12-25 17:42:10 -04:00
|
|
|
# delete links installed by github in /usr/local/bin; installing or
|
|
|
|
# upgrading python via brew fails if these links are in place. brew
|
|
|
|
# auto-updates things when you install other packages which depend on
|
|
|
|
# more recent versions.
|
|
|
|
# see https://github.com/orgs/Homebrew/discussions/3895
|
|
|
|
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
|
|
|
|
|
2023-12-09 21:32:27 -04:00
|
|
|
# brew update randomly failing on CI, so ignore errors:
|
2023-12-11 21:44:11 -04:00
|
|
|
brew update
|
|
|
|
brew install --force --overwrite gawk curl coreutils wget
|
2021-06-25 04:28:14 -03:00
|
|
|
|
|
|
|
PIP=pip
|
|
|
|
if maybe_prompt_user "Install python using pyenv [N/y]?" ; then
|
|
|
|
echo "Checking pyenv..."
|
|
|
|
{
|
|
|
|
$(which -s pyenv)
|
|
|
|
} ||
|
|
|
|
{
|
|
|
|
echo "Installing pyenv"
|
|
|
|
curl https://pyenv.run | bash
|
|
|
|
|
2021-08-20 04:16:16 -03:00
|
|
|
pushd $HOME/.pyenv
|
|
|
|
git fetch --tags
|
2023-02-03 09:53:29 -04:00
|
|
|
git checkout v2.3.12
|
2021-08-20 04:16:16 -03:00
|
|
|
popd
|
2021-06-25 04:28:14 -03:00
|
|
|
exportline="export PYENV_ROOT=\$HOME/.pyenv"
|
|
|
|
echo $exportline >> ~/$SHELL_LOGIN
|
|
|
|
exportline="export PATH=\$PYENV_ROOT/bin:\$PATH"
|
|
|
|
echo $exportline >> ~/$SHELL_LOGIN
|
|
|
|
evalline="eval \"\$(pyenv init --path)\""
|
|
|
|
echo $evalline >> ~/$SHELL_LOGIN
|
|
|
|
evalline="eval \"\$(pyenv init -)\""
|
|
|
|
echo $evalline >> ~/$SHELL_LOGIN
|
|
|
|
source ~/$SHELL_LOGIN
|
|
|
|
}
|
|
|
|
echo "pyenv installed"
|
2022-07-21 12:22:42 -03:00
|
|
|
{
|
2023-01-07 08:42:51 -04:00
|
|
|
$(pyenv global 3.10.4)
|
2022-07-21 12:22:42 -03:00
|
|
|
} || {
|
2023-01-07 08:42:51 -04:00
|
|
|
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.10.4
|
|
|
|
pyenv global 3.10.4
|
2022-07-21 12:22:42 -03:00
|
|
|
}
|
2018-02-24 04:15:23 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
2021-06-25 04:28:14 -03:00
|
|
|
if [[ -z "${DO_AP_STM_ENV}" ]] && maybe_prompt_user "Install ArduPilot STM32 toolchain [N/y]?" ; then
|
|
|
|
DO_AP_STM_ENV=1
|
|
|
|
fi
|
|
|
|
|
2021-06-28 07:37:55 -03:00
|
|
|
echo "Checking ccache..."
|
|
|
|
{
|
|
|
|
$(which -s ccache)
|
|
|
|
} ||
|
|
|
|
{
|
|
|
|
brew install ccache
|
|
|
|
exportline="export PATH=/usr/local/opt/ccache/libexec:\$PATH";
|
|
|
|
eval $exportline
|
|
|
|
}
|
|
|
|
CCACHE_PATH=$(which ccache)
|
|
|
|
|
2021-06-25 04:28:14 -03:00
|
|
|
if [[ $DO_AP_STM_ENV -eq 1 ]]; then
|
|
|
|
install_arm_none_eabi_toolchain
|
|
|
|
fi
|
|
|
|
|
2023-12-02 20:47:37 -04:00
|
|
|
PYTHON_PKGS="future lxml pymavlink MAVProxy pexpect geocoder flake8 junitparser empy==3.3.4 dronecan"
|
2021-06-25 04:28:14 -03:00
|
|
|
# add some Python packages required for commonly-used MAVProxy modules and hex file generation:
|
|
|
|
if [[ $SKIP_AP_EXT_ENV -ne 1 ]]; then
|
|
|
|
PYTHON_PKGS="$PYTHON_PKGS intelhex gnureadline"
|
|
|
|
fi
|
|
|
|
# add some packages required for commonly-used MAVProxy modules:
|
|
|
|
if [[ $SKIP_AP_GRAPHIC_ENV -ne 1 ]]; then
|
|
|
|
PYTHON_PKGS="$PYTHON_PKGS wxPython billiard"
|
|
|
|
fi
|
|
|
|
|
|
|
|
$PIP install --upgrade pip
|
|
|
|
$PIP install wheel
|
|
|
|
$PIP install $PYTHON_PKGS
|
|
|
|
|
|
|
|
echo "Adding ArduPilot Tools to environment"
|
|
|
|
|
|
|
|
SCRIPT_DIR=$(dirname $(grealpath ${BASH_SOURCE[0]}))
|
|
|
|
ARDUPILOT_ROOT=$(grealpath "$SCRIPT_DIR/../../")
|
2021-06-28 07:37:55 -03:00
|
|
|
|
|
|
|
if [[ $DO_AP_STM_ENV -eq 1 ]]; then
|
2021-06-25 04:28:14 -03:00
|
|
|
exportline="export PATH=$OPT/$ARM_ROOT/bin:\$PATH";
|
|
|
|
grep -Fxq "$exportline" ~/$SHELL_LOGIN 2>/dev/null || {
|
|
|
|
if maybe_prompt_user "Add $OPT/$ARM_ROOT/bin to your PATH [N/y]?" ; then
|
|
|
|
echo $exportline >> ~/$SHELL_LOGIN
|
|
|
|
eval $exportline
|
|
|
|
else
|
|
|
|
echo "Skipping adding $OPT/$ARM_ROOT/bin to PATH."
|
|
|
|
fi
|
|
|
|
}
|
2021-06-28 07:37:55 -03:00
|
|
|
fi
|
2021-06-25 04:28:14 -03:00
|
|
|
|
2021-06-28 07:37:55 -03:00
|
|
|
exportline2="export PATH=$ARDUPILOT_ROOT/$ARDUPILOT_TOOLS:\$PATH";
|
|
|
|
grep -Fxq "$exportline2" ~/$SHELL_LOGIN 2>/dev/null || {
|
2021-06-25 04:28:14 -03:00
|
|
|
if maybe_prompt_user "Add $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to your PATH [N/y]?" ; then
|
2021-06-28 07:37:55 -03:00
|
|
|
echo $exportline2 >> ~/$SHELL_LOGIN
|
|
|
|
eval $exportline2
|
2018-02-24 04:15:23 -04:00
|
|
|
else
|
|
|
|
echo "Skipping adding $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to PATH."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-06-25 04:28:14 -03:00
|
|
|
if [[ $SKIP_AP_COMPLETION_ENV -ne 1 ]]; then
|
|
|
|
exportline3="source $ARDUPILOT_ROOT/Tools/completion/$AP_COMPLETION_SCR";
|
|
|
|
grep -Fxq "$exportline3" ~/$SHELL_LOGIN 2>/dev/null || {
|
|
|
|
if maybe_prompt_user "Add ArduPilot Bash Completion to your bash shell [N/y]?" ; then
|
|
|
|
echo $exportline3 >> ~/$SHELL_LOGIN
|
|
|
|
eval $exportline3
|
|
|
|
else
|
|
|
|
echo "Skipping adding ArduPilot Bash Completion."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
|
|
|
exportline4="export PATH=/usr/local/opt/ccache/libexec:\$PATH";
|
|
|
|
grep -Fxq "$exportline4" ~/$SHELL_LOGIN 2>/dev/null || {
|
|
|
|
if maybe_prompt_user "Append CCache to your PATH [N/y]?" ; then
|
|
|
|
echo $exportline4 >> ~/$SHELL_LOGIN
|
|
|
|
eval $exportline4
|
|
|
|
else
|
|
|
|
echo "Skipping appending CCache to PATH."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
echo "Done!"
|
|
|
|
|
2018-02-24 04:15:23 -04:00
|
|
|
git submodule update --init --recursive
|
|
|
|
|
|
|
|
echo "finished"
|