Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/environment_install/install-prereqs-mac.sh
9688 views
1
#!/usr/bin/env bash
2
echo "---------- $0 start ----------"
3
set -e
4
set -x
5
6
if [ $EUID == 0 ]; then
7
echo "Please do not run this script as root; don't sudo it!"
8
exit 1
9
fi
10
11
if [[ $SHELL == *"zsh"* ]]; then
12
AP_COMPLETION_SCR="completion.zsh"
13
SHELL_LOGIN=".zshrc"
14
elif [[ $SHELL == *"bash"* ]]; then
15
AP_COMPLETION_SCR="completion.bash"
16
SHELL_LOGIN=".bash_profile"
17
else
18
echo "Unsupported shell"
19
exit 1
20
fi
21
22
OPT="/opt"
23
# Ardupilot Tools
24
ARDUPILOT_TOOLS="Tools/autotest"
25
26
ASSUME_YES=false
27
sep="##############################################"
28
29
OPTIND=1 # Reset in case getopts has been used previously in the shell.
30
while getopts "y" opt; do
31
case "$opt" in
32
\?)
33
exit 1
34
;;
35
y) ASSUME_YES=true
36
;;
37
esac
38
done
39
40
41
echo "Checking homebrew..."
42
$(which -s brew) ||
43
{
44
echo "installing homebrew..."
45
/usr/bin/env bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
46
}
47
echo "Homebrew installed"
48
49
# Detect Homebrew prefix (different on Apple Silicon vs Intel)
50
HOMEBREW_PREFIX="$(brew --prefix)"
51
52
#install command line tools
53
echo "Checking CLI Tools installed..."
54
{
55
ERROR=$(xcode-select --install 2>&1 > /dev/null)
56
} ||
57
{
58
if [[ $ERROR != *"ommand line tools are already installed"* ]]; then
59
echo "$ERROR" 1>&2
60
exit 1
61
fi
62
}
63
64
# ArduPilot official Toolchain for STM32 boards
65
function install_arm_none_eabi_toolchain() {
66
# GNU Tools for ARM Embedded Processors
67
# (see https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
68
ARM_ROOT="gcc-arm-none-eabi-10-2020-q4-major"
69
ARM_TARBALL="$ARM_ROOT-mac.tar.bz2"
70
ARM_TARBALL_URL="https://firmware.ardupilot.org/Tools/STM32-tools/$ARM_TARBALL"
71
if [ ! -d $OPT/$ARM_ROOT ]; then
72
(
73
cd $OPT;
74
echo "Installing toolchain for STM32 Boards"
75
echo "Downloading from ArduPilot server"
76
sudo wget $ARM_TARBALL_URL
77
echo "Installing..."
78
sudo tar xjf ${ARM_TARBALL}
79
echo "... Cleaning"
80
sudo rm ${ARM_TARBALL};
81
)
82
fi
83
echo "Registering STM32 Toolchain for ccache"
84
sudo mkdir -p $HOMEBREW_PREFIX/opt/ccache/libexec
85
sudo ln -s -f $CCACHE_PATH $HOMEBREW_PREFIX/opt/ccache/libexec/arm-none-eabi-g++
86
sudo ln -s -f $CCACHE_PATH $HOMEBREW_PREFIX/opt/ccache/libexec/arm-none-eabi-gcc
87
echo "Done!"
88
}
89
90
function maybe_prompt_user() {
91
if $ASSUME_YES; then
92
return 0
93
else
94
read -p "$1"
95
if [[ $REPLY =~ ^[Yy]$ ]]; then
96
return 0
97
else
98
return 1
99
fi
100
fi
101
}
102
103
# delete links installed by github in /usr/local/bin; installing or
104
# upgrading python via brew fails if these links are in place. brew
105
# auto-updates things when you install other packages which depend on
106
# more recent versions.
107
# see https://github.com/orgs/Homebrew/discussions/3895
108
# Note: /usr/local/bin may not exist on Apple Silicon Macs
109
if [ -d /usr/local/bin ]; then
110
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
111
fi
112
113
# brew update randomly failing on CI, so ignore errors:
114
brew update
115
brew install --force --overwrite gawk coreutils wget
116
117
PIP="python3 -m pip"
118
if maybe_prompt_user "Install python using pyenv [N/y]?" ; then
119
echo "Checking pyenv..."
120
{
121
$(which -s pyenv)
122
} ||
123
{
124
echo "Installing pyenv"
125
curl https://pyenv.run | bash
126
127
pushd $HOME/.pyenv
128
git fetch --tags
129
git checkout v2.6.7
130
popd
131
exportline="export PYENV_ROOT=\$HOME/.pyenv"
132
echo $exportline >> ~/$SHELL_LOGIN
133
exportline="export PATH=\$PYENV_ROOT/bin:\$PATH"
134
echo $exportline >> ~/$SHELL_LOGIN
135
evalline="eval \"\$(pyenv init --path)\""
136
echo $evalline >> ~/$SHELL_LOGIN
137
evalline="eval \"\$(pyenv init -)\""
138
echo $evalline >> ~/$SHELL_LOGIN
139
source ~/$SHELL_LOGIN
140
}
141
echo "pyenv installed"
142
{
143
$(pyenv global 3.10.18)
144
} || {
145
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.10.18
146
pyenv global 3.10.18
147
}
148
fi
149
150
151
if [[ -z "${DO_AP_STM_ENV}" ]] && maybe_prompt_user "Install ArduPilot STM32 toolchain [N/y]?" ; then
152
DO_AP_STM_ENV=1
153
fi
154
155
echo "Checking ccache..."
156
{
157
$(which -s ccache)
158
} ||
159
{
160
brew install ccache
161
exportline="export PATH=$HOMEBREW_PREFIX/opt/ccache/libexec:\$PATH";
162
eval $exportline
163
}
164
CCACHE_PATH=$(which ccache)
165
166
if [[ $DO_AP_STM_ENV -eq 1 ]]; then
167
install_arm_none_eabi_toolchain
168
fi
169
170
PYTHON_PKGS="setuptools future lxml matplotlib pymavlink MAVProxy pexpect geocoder flake8 junitparser empy==3.3.4 dronecan"
171
# add some Python packages required for commonly-used MAVProxy modules and hex file generation:
172
if [[ $SKIP_AP_EXT_ENV -ne 1 ]]; then
173
PYTHON_PKGS="$PYTHON_PKGS intelhex gnureadline"
174
fi
175
# add some packages required for commonly-used MAVProxy modules:
176
if [[ $SKIP_AP_GRAPHIC_ENV -ne 1 ]]; then
177
PYTHON_PKGS="$PYTHON_PKGS wxPython billiard"
178
fi
179
180
$PIP install --upgrade pip
181
$PIP install --force-reinstall wheel
182
$PIP install $PYTHON_PKGS
183
184
echo "Adding ArduPilot Tools to environment"
185
186
SCRIPT_DIR=$(dirname $(grealpath ${BASH_SOURCE[0]}))
187
ARDUPILOT_ROOT=$(grealpath "$SCRIPT_DIR/../../")
188
189
if [[ $DO_AP_STM_ENV -eq 1 ]]; then
190
exportline="export PATH=$OPT/$ARM_ROOT/bin:\$PATH";
191
grep -Fxq "$exportline" ~/$SHELL_LOGIN 2>/dev/null || {
192
if maybe_prompt_user "Add $OPT/$ARM_ROOT/bin to your PATH [N/y]?" ; then
193
echo $exportline >> ~/$SHELL_LOGIN
194
eval $exportline
195
else
196
echo "Skipping adding $OPT/$ARM_ROOT/bin to PATH."
197
fi
198
}
199
fi
200
201
exportline2="export PATH=$ARDUPILOT_ROOT/$ARDUPILOT_TOOLS:\$PATH";
202
grep -Fxq "$exportline2" ~/$SHELL_LOGIN 2>/dev/null || {
203
if maybe_prompt_user "Add $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to your PATH [N/y]?" ; then
204
echo $exportline2 >> ~/$SHELL_LOGIN
205
eval $exportline2
206
else
207
echo "Skipping adding $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to PATH."
208
fi
209
}
210
211
if [[ $SKIP_AP_COMPLETION_ENV -ne 1 ]]; then
212
exportline3="source $ARDUPILOT_ROOT/Tools/completion/$AP_COMPLETION_SCR";
213
grep -Fxq "$exportline3" ~/$SHELL_LOGIN 2>/dev/null || {
214
if maybe_prompt_user "Add ArduPilot Bash Completion to your bash shell [N/y]?" ; then
215
echo $exportline3 >> ~/$SHELL_LOGIN
216
eval $exportline3
217
else
218
echo "Skipping adding ArduPilot Bash Completion."
219
fi
220
}
221
fi
222
223
exportline4="export PATH=$HOMEBREW_PREFIX/opt/ccache/libexec:\$PATH";
224
grep -Fxq "$exportline4" ~/$SHELL_LOGIN 2>/dev/null || {
225
if maybe_prompt_user "Append CCache to your PATH [N/y]?" ; then
226
echo $exportline4 >> ~/$SHELL_LOGIN
227
eval $exportline4
228
else
229
echo "Skipping appending CCache to PATH."
230
fi
231
}
232
echo "Done!"
233
234
git submodule update --init --recursive
235
236
echo "finished"
237
238