From df26e9985680247c6d424a49952d87affc9ce286 Mon Sep 17 00:00:00 2001 From: Michael Honan Date: Sat, 15 Aug 2020 11:03:55 +1000 Subject: [PATCH] Setup script improvements to MacOS / Ubuntu (#2012) * Setup script improvements to MacOS / Ubuntu scons isn't actually required from brew install pyenv init on all envs added installation to .zshrc on macos with better dir logic Using git to detect project root for ubuntu bashrc install Check shell and determine correct RC file Update tools/mac_setup.sh Co-authored-by: Adeeb Shihadeh Sourcing RC file only if it's found Removed unnecessary source of rc file Submodules should never have been bumped... Output the $RC_FILE when successfully installed pyenv init every time, and skip RC install on CI Confused bash conditionals, opposite of what I meant * Was missing libusb on a fresh MacOS 10.15.6 install Co-authored-by: Michael Honan old-commit-hash: 4a9228fcc776d898287ebc015cab0a11fd3cdc64 --- tools/mac_setup.sh | 38 +++++++++++++++++++++++++++++++++----- tools/openpilot_env.sh | 3 +-- tools/ubuntu_setup.sh | 3 ++- 3 files changed, 36 insertions(+), 8 deletions(-) mode change 100644 => 100755 tools/openpilot_env.sh diff --git a/tools/mac_setup.sh b/tools/mac_setup.sh index 5097000196..a795624598 100755 --- a/tools/mac_setup.sh +++ b/tools/mac_setup.sh @@ -1,7 +1,13 @@ #!/bin/bash -e -# install brew -/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" +# Install brew if required. +if [[ $(command -v brew) == "" ]]; then + echo "Installing Hombrew" + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" +else + echo "Updating Homebrew" + brew update +fi brew install capnp \ czmq \ @@ -10,17 +16,39 @@ brew install capnp \ ffmpeg \ glfw \ libarchive \ + libusb \ libtool \ llvm \ pyenv \ zeromq -# install python +# Detect shell and pick correct RC file. +if [[ $SHELL == "/bin/zsh" ]]; then + RC_FILE="$HOME/.zshrc" +elif [[ $SHELL == "/bin/bash" ]]; then + RC_FILE="$HOME/.bash_profile" +else + echo "-------------------------------------------------------------" + echo "Unsupported shell: \"$SHELL\", cannot install to RC file." + echo "Please run: echo \"source $OP_DIR/tools/openpilot_env.sh\" >> %YOUR SHELL's RC file%" + echo "-------------------------------------------------------------" +fi + +# Install to RC file (only non-CI). +if [ -z "$OPENPILOT_ENV" ] && [ -n "$RC_FILE" ] && [ -z "$CI" ]; then + OP_DIR=$(git rev-parse --show-toplevel) + echo "source $OP_DIR/tools/openpilot_env.sh" >> $RC_FILE + source $RC_FILE + echo "Added openpilot_env to RC file: $RC_FILE" +else + echo "Skipped RC file installation" +fi + +# Install python. pyenv install -s 3.8.2 pyenv global 3.8.2 pyenv rehash -eval "$(pyenv init -)" +eval "$(pyenv init -)" # CI doesn't use .bash_profile, and will use python2.7 if this line isn't here. pip install pipenv==2018.11.26 pipenv install --system --deploy - diff --git a/tools/openpilot_env.sh b/tools/openpilot_env.sh old mode 100644 new mode 100755 index 95f3b12ece..ca25706b83 --- a/tools/openpilot_env.sh +++ b/tools/openpilot_env.sh @@ -4,14 +4,13 @@ if [ -z "$OPENPILOT_ENV" ]; then unamestr=`uname` if [[ "$unamestr" == 'Linux' ]]; then export PATH="$HOME/.pyenv/bin:$PATH" - eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)" elif [[ "$unamestr" == 'Darwin' ]]; then # msgq doesn't work on mac export ZMQ=1 export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES fi + eval "$(pyenv init -)" export OPENPILOT_ENV=1 fi - diff --git a/tools/ubuntu_setup.sh b/tools/ubuntu_setup.sh index e46d7b29fe..8de9152175 100755 --- a/tools/ubuntu_setup.sh +++ b/tools/ubuntu_setup.sh @@ -61,7 +61,8 @@ fi # install bashrc source ~/.bashrc if [ -z "$OPENPILOT_ENV" ]; then - echo "source $HOME/openpilot/tools/openpilot_env.sh" >> ~/.bashrc + OP_DIR=$(git rev-parse --show-toplevel) + echo "source $OP_DIR/tools/openpilot_env.sh" >> ~/.bashrc source ~/.bashrc echo "added openpilot_env to bashrc" fi