CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/environment_install/install-prereqs-mac.sh
Views: 1798
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
#install command line tools
50
echo "Checking CLI Tools installed..."
51
{
52
ERROR=$(xcode-select --install 2>&1 > /dev/null)
53
} ||
54
{
55
if [[ $ERROR != *"ommand line tools are already installed"* ]]; then
56
echo "$ERROR" 1>&2
57
exit 1
58
fi
59
}
60
61
# ArduPilot official Toolchain for STM32 boards
62
function install_arm_none_eabi_toolchain() {
63
# GNU Tools for ARM Embedded Processors
64
# (see https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)
65
ARM_ROOT="gcc-arm-none-eabi-10-2020-q4-major"
66
ARM_TARBALL="$ARM_ROOT-mac.tar.bz2"
67
ARM_TARBALL_URL="https://firmware.ardupilot.org/Tools/STM32-tools/$ARM_TARBALL"
68
if [ ! -d $OPT/$ARM_ROOT ]; then
69
(
70
cd $OPT;
71
echo "Installing toolchain for STM32 Boards"
72
echo "Downloading from ArduPilot server"
73
sudo wget $ARM_TARBALL_URL
74
echo "Installing..."
75
sudo tar xjf ${ARM_TARBALL}
76
echo "... Cleaning"
77
sudo rm ${ARM_TARBALL};
78
)
79
fi
80
echo "Registering STM32 Toolchain for ccache"
81
sudo mkdir -p /usr/local/opt/ccache/libexec
82
sudo ln -s -f $CCACHE_PATH /usr/local/opt/ccache/libexec/arm-none-eabi-g++
83
sudo ln -s -f $CCACHE_PATH /usr/local/opt/ccache/libexec/arm-none-eabi-gcc
84
echo "Done!"
85
}
86
87
function maybe_prompt_user() {
88
if $ASSUME_YES; then
89
return 0
90
else
91
read -p "$1"
92
if [[ $REPLY =~ ^[Yy]$ ]]; then
93
return 0
94
else
95
return 1
96
fi
97
fi
98
}
99
100
# delete links installed by github in /usr/local/bin; installing or
101
# upgrading python via brew fails if these links are in place. brew
102
# auto-updates things when you install other packages which depend on
103
# more recent versions.
104
# see https://github.com/orgs/Homebrew/discussions/3895
105
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
106
107
# brew update randomly failing on CI, so ignore errors:
108
brew update
109
brew install --force --overwrite gawk coreutils wget
110
111
PIP=pip
112
if maybe_prompt_user "Install python using pyenv [N/y]?" ; then
113
echo "Checking pyenv..."
114
{
115
$(which -s pyenv)
116
} ||
117
{
118
echo "Installing pyenv"
119
curl https://pyenv.run | bash
120
121
pushd $HOME/.pyenv
122
git fetch --tags
123
git checkout v2.3.12
124
popd
125
exportline="export PYENV_ROOT=\$HOME/.pyenv"
126
echo $exportline >> ~/$SHELL_LOGIN
127
exportline="export PATH=\$PYENV_ROOT/bin:\$PATH"
128
echo $exportline >> ~/$SHELL_LOGIN
129
evalline="eval \"\$(pyenv init --path)\""
130
echo $evalline >> ~/$SHELL_LOGIN
131
evalline="eval \"\$(pyenv init -)\""
132
echo $evalline >> ~/$SHELL_LOGIN
133
source ~/$SHELL_LOGIN
134
}
135
echo "pyenv installed"
136
{
137
$(pyenv global 3.10.4)
138
} || {
139
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.10.4
140
pyenv global 3.10.4
141
}
142
fi
143
144
145
if [[ -z "${DO_AP_STM_ENV}" ]] && maybe_prompt_user "Install ArduPilot STM32 toolchain [N/y]?" ; then
146
DO_AP_STM_ENV=1
147
fi
148
149
echo "Checking ccache..."
150
{
151
$(which -s ccache)
152
} ||
153
{
154
brew install ccache
155
exportline="export PATH=/usr/local/opt/ccache/libexec:\$PATH";
156
eval $exportline
157
}
158
CCACHE_PATH=$(which ccache)
159
160
if [[ $DO_AP_STM_ENV -eq 1 ]]; then
161
install_arm_none_eabi_toolchain
162
fi
163
164
PYTHON_PKGS="future lxml pymavlink MAVProxy pexpect geocoder flake8 junitparser empy==3.3.4 dronecan"
165
# add some Python packages required for commonly-used MAVProxy modules and hex file generation:
166
if [[ $SKIP_AP_EXT_ENV -ne 1 ]]; then
167
PYTHON_PKGS="$PYTHON_PKGS intelhex gnureadline"
168
fi
169
# add some packages required for commonly-used MAVProxy modules:
170
if [[ $SKIP_AP_GRAPHIC_ENV -ne 1 ]]; then
171
PYTHON_PKGS="$PYTHON_PKGS wxPython billiard"
172
fi
173
174
$PIP install --upgrade pip
175
$PIP install wheel
176
$PIP install $PYTHON_PKGS
177
178
echo "Adding ArduPilot Tools to environment"
179
180
SCRIPT_DIR=$(dirname $(grealpath ${BASH_SOURCE[0]}))
181
ARDUPILOT_ROOT=$(grealpath "$SCRIPT_DIR/../../")
182
183
if [[ $DO_AP_STM_ENV -eq 1 ]]; then
184
exportline="export PATH=$OPT/$ARM_ROOT/bin:\$PATH";
185
grep -Fxq "$exportline" ~/$SHELL_LOGIN 2>/dev/null || {
186
if maybe_prompt_user "Add $OPT/$ARM_ROOT/bin to your PATH [N/y]?" ; then
187
echo $exportline >> ~/$SHELL_LOGIN
188
eval $exportline
189
else
190
echo "Skipping adding $OPT/$ARM_ROOT/bin to PATH."
191
fi
192
}
193
fi
194
195
exportline2="export PATH=$ARDUPILOT_ROOT/$ARDUPILOT_TOOLS:\$PATH";
196
grep -Fxq "$exportline2" ~/$SHELL_LOGIN 2>/dev/null || {
197
if maybe_prompt_user "Add $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to your PATH [N/y]?" ; then
198
echo $exportline2 >> ~/$SHELL_LOGIN
199
eval $exportline2
200
else
201
echo "Skipping adding $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to PATH."
202
fi
203
}
204
205
if [[ $SKIP_AP_COMPLETION_ENV -ne 1 ]]; then
206
exportline3="source $ARDUPILOT_ROOT/Tools/completion/$AP_COMPLETION_SCR";
207
grep -Fxq "$exportline3" ~/$SHELL_LOGIN 2>/dev/null || {
208
if maybe_prompt_user "Add ArduPilot Bash Completion to your bash shell [N/y]?" ; then
209
echo $exportline3 >> ~/$SHELL_LOGIN
210
eval $exportline3
211
else
212
echo "Skipping adding ArduPilot Bash Completion."
213
fi
214
}
215
fi
216
217
exportline4="export PATH=/usr/local/opt/ccache/libexec:\$PATH";
218
grep -Fxq "$exportline4" ~/$SHELL_LOGIN 2>/dev/null || {
219
if maybe_prompt_user "Append CCache to your PATH [N/y]?" ; then
220
echo $exportline4 >> ~/$SHELL_LOGIN
221
eval $exportline4
222
else
223
echo "Skipping appending CCache to PATH."
224
fi
225
}
226
echo "Done!"
227
228
git submodule update --init --recursive
229
230
echo "finished"
231
232