Siddharth Purohit
4 years ago
committed by
Andrew Tridgell
1 changed files with 192 additions and 26 deletions
@ -1,47 +1,213 @@
@@ -1,47 +1,213 @@
|
||||
#!/bin/bash |
||||
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 |
||||
|
||||
|
||||
echo "Checking homebrew..." |
||||
$(which -s brew) |
||||
if [[ $? != 0 ]] ; then |
||||
$(which -s brew) || |
||||
{ |
||||
echo "installing homebrew..." |
||||
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
||||
else |
||||
echo "Homebrew installed" |
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
||||
} |
||||
echo "Homebrew installed" |
||||
|
||||
#install command line tools |
||||
echo "Checking CLI Tools installed..." |
||||
{ |
||||
ERROR=$(xcode-select --install 2>&1 > /dev/null) |
||||
} || |
||||
{ |
||||
if [[ $ERROR != *"command line tools are already installed"* ]]; then |
||||
echo "$ERROR" 1>&2 |
||||
exit 1 |
||||
fi |
||||
} |
||||
|
||||
# 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) |
||||
ARM_ROOT="gcc-arm-none-eabi-6-2017-q2-update" |
||||
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" |
||||
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!" |
||||
} |
||||
|
||||
#install xconde dependencies |
||||
xcode-select --install |
||||
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 |
||||
} |
||||
|
||||
brew tap ardupilot/homebrew-px4 |
||||
brew update |
||||
brew install gcc-arm-none-eabi |
||||
brew install gawk |
||||
|
||||
echo "Checking pip..." |
||||
$(which -s pip) |
||||
if [[ $? != 0 ]] ; then |
||||
echo "installing pip..." |
||||
sudo easy_install pip |
||||
else |
||||
echo "pip installed" |
||||
brew install gawk curl coreutils wget |
||||
|
||||
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 |
||||
|
||||
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" |
||||
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.9.4 |
||||
pyenv global 3.9.4 |
||||
fi |
||||
|
||||
pip2 install --user pyserial future empy mavproxy pexpect geocoder |
||||
|
||||
SCRIPT_DIR=$(dirname $(realpath ${BASH_SOURCE[0]})) |
||||
ARDUPILOT_ROOT=$(realpath "$SCRIPT_DIR/../../") |
||||
ARDUPILOT_TOOLS="Tools/autotest" |
||||
if [[ -z "${DO_AP_STM_ENV}" ]] && maybe_prompt_user "Install ArduPilot STM32 toolchain [N/y]?" ; then |
||||
DO_AP_STM_ENV=1 |
||||
fi |
||||
|
||||
if [[ $DO_AP_STM_ENV -eq 1 ]]; then |
||||
echo "Checking ccache..." |
||||
{ |
||||
$(which -s ccache) |
||||
} || |
||||
{ |
||||
brew install ccache |
||||
exportline="export PATH=/usr/local/opt/ccache/libexec:\$PATH"; |
||||
echo $exportline >> ~/$SHELL_LOGIN |
||||
eval $exportline |
||||
} |
||||
CCACHE_PATH=$(which ccache) |
||||
install_arm_none_eabi_toolchain |
||||
fi |
||||
|
||||
PYTHON_PKGS="future lxml pymavlink MAVProxy pexpect geocoder flake8" |
||||
# 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/../../") |
||||
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 |
||||
} |
||||
|
||||
SCRIPT_DIR=$(dirname $(grealpath ${BASH_SOURCE[0]})) |
||||
ARDUPILOT_ROOT=$(grealpath "$SCRIPT_DIR/../../") |
||||
|
||||
exportline="export PATH=$ARDUPILOT_ROOT/$ARDUPILOT_TOOLS:\$PATH"; |
||||
grep -Fxq "$exportline" ~/.profile 2>/dev/null || { |
||||
read -p "Add $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to your PATH [N/y]?" -n 1 -r |
||||
if [[ $REPLY =~ ^[Yy]$ ]] ; then |
||||
echo $exportline >> ~/.profile |
||||
grep -Fxq "$exportline" ~/$SHELL_LOGIN 2>/dev/null || { |
||||
if maybe_prompt_user "Add $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to your PATH [N/y]?" ; then |
||||
echo $exportline >> ~/$SHELL_LOGIN |
||||
eval $exportline |
||||
else |
||||
echo "Skipping adding $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to PATH." |
||||
fi |
||||
} |
||||
|
||||
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!" |
||||
|
||||
git submodule update --init --recursive |
||||
|
||||
echo "finished" |
||||
|
Loading…
Reference in new issue