-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
994b229
commit 9a5fb8f
Showing
5 changed files
with
328 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,292 @@ | ||
#!/bin/bash | ||
################################################################################ | ||
######## Gazebo Harmonic Installation Script for MacOS (Apple Silicon) ######### | ||
################################################################################ | ||
# Author: Choi Woen-Sug (GithubID: woensug-choi) | ||
# First Created: 2024.6.15 | ||
################################################################################ | ||
# References: | ||
# - https://gazebosim.org/docs/harmonic/install_osx_src | ||
# Assumes that ROS2 Jazzy is already installed. | ||
# | ||
# Also, need to make this script executable | ||
# chmod +x gz_install.sh | ||
################################################################################ | ||
ROS_INSTALL_ROOT_DEFAULT="ros2_jazzy" # you may change with option -r | ||
GZ_INSTALL_ROOT_DEFAULT="gz-harmonic" # you may change with option -d | ||
VIRTUAL_ENV_ROOT_DEFAULT=".ros2_venv" # you may change with option -v | ||
# ------------------------------------------------------------------------------ | ||
# Installation Configuration and Options | ||
# ------------------------------------------------------------------------------ | ||
|
||
# Usage function | ||
usage() { | ||
echo "Usage: [-r ROS_INSTALL_ROOT_DEFAULT] [-d GZ_INSTALL_ROOT_DEFAULT] [-v VIRTUAL_ENV_ROOT_DEFAULT]" | ||
echo " -r Set the ROS installation root directory (default: $ROS_INSTALL_ROOT_DEFAULT)" | ||
echo " -d Set the Python Virtual Environment directory (default: $GZ_INSTALL_ROOT_DEFAULT)" | ||
echo " -v Set the Python Virtual Environment directory (default: $VIRTUAL_ENV_ROOT_DEFAULT)" | ||
exit 1 | ||
} | ||
|
||
# Parse command-line arguments | ||
while getopts "d:r:h:v:" opt; do | ||
case ${opt} in | ||
d) | ||
ROS_INSTALL_ROOT=$OPTARG | ||
;; | ||
r) | ||
GZ_INSTALL_ROOT=$OPTARG | ||
;; | ||
v) | ||
VIRTUAL_ENV_ROOT=$OPTARG | ||
;; | ||
h) | ||
usage | ||
;; | ||
\?) | ||
echo "Invalid option: -$OPTARG" 1>&2 | ||
usage | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND -1)) | ||
|
||
# Set default values if variables are not set | ||
ROS_INSTALL_ROOT=${ROS_INSTALL_ROOT:-$ROS_INSTALL_ROOT_DEFAULT} | ||
GZ_INSTALL_ROOT=${GZ_INSTALL_ROOT:-$GZ_INSTALL_ROOT_DEFAULT} | ||
VIRTUAL_ENV_ROOT=${VIRTUAL_ENV_ROOT:-$VIRTUAL_ENV_ROOT_DEFAULT} | ||
|
||
# Get Current Version hash | ||
LATEST_COMMIT_HASH=$(curl -s "https://api.github.com/repos/IOES-Lab/ROS2_Jazzy_MacOS_Native_AppleSilicon/commits/main" | \ | ||
grep '"sha":' | \ | ||
head -n 1 | \ | ||
awk -F '"' '{print $4}' | \ | ||
cut -c1-7) | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Initiation | ||
# ------------------------------------------------------------------------------ | ||
# Print welcome message | ||
echo -e "\033[32m" | ||
echo "▣-------------------------------------------------------------------------▣" | ||
echo "| ______ ______ ______ ______ ______ ______ " | ||
echo "| /\ ___\/\ __ \/\___ \/\ ___\/\ == \/\ __ \ "; | ||
echo "| \ \ \__ \ \ __ \/_/ /_\ \ __\\ \ __<\ \ \/\ \ "; | ||
echo "| \ \_____\ \_\ \_\/\_____\ \_____\ \_____\ \_____\ "; | ||
echo "| \/_____/\/_/\/_/\/_____/\/_____/\/_____/\/_____/ "; | ||
echo "| __ __ ______ ______ __ __ ______ __ __ __ ______ "; | ||
echo "| /\ \_\ \/\ __ \/\ == \/\ \"-./ \/\ __ \/\ \"-.\ \/\ \/\ ___\ "; | ||
echo "| \ \ __ \ \ __ \ \ __<\ \ \-./\ \ \ \/\ \ \ \-.\ \ \ \ \ \____ "; | ||
echo "| \ \_\ \_\ \_\ \_\ \_\ \_\ \_\ \ \_\ \_____\ \_\\\"\_ \ \_\ \_____\ "; | ||
echo "| \/_/\/_/\/_/\/_/\/_/ /_/\/_/ \/_/\/_____/\/_/ \/_/\/_/\/_____/ "; | ||
echo "| |" | ||
echo "| 👋 Welcome to the Instllation of Gazebo Harmonic on MacOS 🚧 |" | ||
echo "| 🍎 (Apple Silicon)+🤖 = 🚀❤️🤩🎉🥳 |" | ||
echo "| |" | ||
echo "| First created at 2024.6.15 by Choi Woen-Sug(Github:woensug-choi) |" | ||
echo "▣-------------------------------------------------------------------------▣" | ||
echo -e "| Current Installer Version Hash : \033[94m$LATEST_COMMIT_HASH\033[0m \033[32m" | ||
echo -e "| Target Installation Directory :" "\033[94m$HOME/$GZ_INSTALL_ROOT\033[0m" | ||
echo -e "\033[32m|\033[0m Virtual Environment Directory :" "\033[94m$HOME/$VIRTUAL_ENV_ROOT\033[0m" | ||
echo -e "\033[32m▣-------------------------------------------------------------------------▣\033[0m" | ||
echo -e "Source code at: " | ||
echo -e "https://github.com/IOES-Lab/ROS2_Jazzy_MacOS_Native_AppleSilicon/gz_install.sh\n" | ||
echo -e "\033[33mWARNING: The FAN WILL BURST out and make macbook to take off. Be warned!\033[0m" | ||
echo -e "\033[33m To terminate at any process, press Ctrl+C.\033[0m" | ||
# ------------------------------------------------------------------------------ | ||
# Check System | ||
printf '\n\033[34m'; printf '=%.0s' {1..75}; printf '\033[0m\n' | ||
echo -e "\033[34m### [1/6] Checking System Requirements\033[0m" | ||
printf '\033[34m%.0s=\033[0m' {1..75} && echo | ||
# ------------------------------------------------------------------------------ | ||
# Check if Installation dir already exists and warn user | ||
echo -e "\033[34m> Check Installation Directory\033[0m" | ||
if [ -d "$HOME/$GZ_INSTALL_ROOT" ]; then | ||
echo -e "\033[33mWARNING: The directory $GZ_INSTALL_ROOT already exists at home ($HOME)." | ||
echo -e "\033[33m This script will merge and overwrite the existing directory.\033[0m" | ||
echo -e "\033[33mDo you want to continue? [y/n/r/c]\033[0m" | ||
read -p "(y) Merge (n) Cancel (r) Change directory, (c) Force reinstall: " -n 1 -r | ||
echo | ||
if [[ $REPLY =~ ^[Yy]$ ]]; then | ||
echo -e "\033[33mMerging and overwriting existing directory...\033[0m" | ||
elif [[ $REPLY =~ ^[Rr]$ ]]; then | ||
# shellcheck disable=SC2162 | ||
read -p "Enter a new directory name (which will be generated at home): " GZ_INSTALL_ROOT | ||
if [ -d "$HOME/$GZ_INSTALL_ROOT" ]; then | ||
echo -e "\033[31mError: $HOME/$GZ_INSTALL_ROOT already exists. Please choose a different directory.\033[0m" | ||
exit 1 | ||
fi | ||
elif [[ $REPLY =~ ^[Cc]$ ]]; then | ||
echo -e "\033[33mPerforming clean reinstall...\033[0m" | ||
# shellcheck disable=SC2115 | ||
rm -rf "$HOME/$GZ_INSTALL_ROOT" | ||
else | ||
echo -e "\033[31mInstallation aborted.\033[0m" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
# Generate Directory | ||
echo -e "\033[36m> Creating directory $HOME/$GZ_INSTALL_ROOT...\033[0m" | ||
mkdir -p "$HOME/$GZ_INSTALL_ROOT"/src | ||
chown -R "$USER": "$HOME/$GZ_INSTALL_ROOT" > /dev/null 2>&1 | ||
|
||
# Move to working directory | ||
pushd "$HOME/$GZ_INSTALL_ROOT" || { | ||
echo -e "\033[31mError: Failed to change to directory $HOME/$GZ_INSTALL_ROOT. \ | ||
Please check if the directory exists and you have the necessary permissions.\033[0m" | ||
exit 1 | ||
} | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Install Dendencies | ||
printf '\n\n\033[34m'; printf '=%.0s' {1..75}; printf '\033[0m\n' | ||
echo -e "\033[34m### [2/6] Installing Dependencies with Brew and PIP\033[0m" | ||
printf '\033[34m%.0s=\033[0m' {1..75} && echo | ||
# ------------------------------------------------------------------------------ | ||
# Installing Gazebo Harmonic dependencies with brew | ||
echo -e "\033[36m> Installing Gazebo Harmonic dependencies with Brew...\033[0m" | ||
brew update | ||
brew tap osrf/simulation | ||
brew install assimp boost bullet cmake cppzmq [email protected] doxygen \ | ||
eigen fcl ffmpeg flann freeimage freetype gdal gflags google-benchmark \ | ||
gts ipopt jsoncpp libccd libyaml libzzip libzip nlopt ode open-scene-graph \ | ||
ossp-uuid ogre1.9 ogre2.3 pkg-config protobuf qt@5 qwt-qt5 rapidjson ruby \ | ||
tbb tinyxml tinyxml2 urdfdom zeromq | ||
|
||
# Set Environment Variables of Brew packages | ||
echo -e "\033[36m> Setting Environment Variables of Brew packages...\033[0m" | ||
export CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}:/opt/homebrew/opt/[email protected] | ||
export DYLD_FALLBACK_LIBRARY_PATH=${DYLD_FALLBACK_LIBRARY_PATH}:/opt/homoebrew/opt/[email protected]/lib:/opt/homebrew/opt/octomap/local | ||
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/opt/homebrew/opt/[email protected]/lib/pkgconfig | ||
export CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}:/opt/homebrew/opt/qt@5 | ||
|
||
# Install XQuartz | ||
brew install xquartz --cask | ||
|
||
# Confirm message | ||
echo -e "\033[36m\n\n> Packages installation with Brew completed.\033[0m" | ||
|
||
# Activate Python3.11 virtual environment | ||
# shellcheck disable=SC1091,SC1090 | ||
source "$HOME/$VIRTUAL_ENV_ROOT"/bin/activate | ||
|
||
# Confirm message | ||
echo -e "\033[36m> Python Virtual Environment loaded\033[0m" | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Downloading Gazebo Harmonic Source Code | ||
printf '\n\n\033[34m'; printf '=%.0s' {1..75}; printf '\033[0m\n' | ||
echo -e "\033[34m### [3/6] Downloading Gazebo Harmonic Source Code\033[0m" | ||
printf '\033[34m%.0s=\033[0m' {1..75} && echo | ||
# ------------------------------------------------------------------------------ | ||
# Get Gazebo Harmonic Source Code | ||
echo -e "\033[36m> Getting Gazebo Harmonic Code...\033[0m" | ||
echo -e "As long as the spinner at of the terminal is running, it is downloading the source code. It does take long." | ||
echo -e "If you see 'E' in the progress, it means the download failed (slow connection does this), it will try again." | ||
echo -e "If it takes too long, please check your network connection and try again. To cancel, Ctrl+C." | ||
echo -e "\033[33mSTART---------------------------------- DOWNLOADING... ---------------------------------------------END\033[0m" | ||
|
||
|
||
# Define maximum number of retries | ||
max_retries=3 | ||
# Start loop | ||
for ((i=1;i<=max_retries;i++)); do | ||
# Try to import the repositories | ||
if vcs import --shallow --retry 0 \ | ||
--input https://raw.githubusercontent.com/gazebo-tooling/gazebodistro/master/collection-harmonic.yaml src; | ||
then | ||
echo -e "\033[36m\n>Gazebo Harmonic Code Import Successful\033[0m" | ||
break | ||
else | ||
echo -e "\033[31m\nGazebo Harmonic Source Code Import failed, retrying ($i/$max_retries)\033[0m" | ||
fi | ||
# If we've reached the max number of retries, exit the script | ||
if [ $i -eq $max_retries ]; then | ||
echo -e "\033[31m\nGazebo Harmonic Source Code Import failed after $max_retries attempts, terminating script.\033[0m" | ||
exit 1 | ||
fi | ||
# Wait before retrying | ||
sleep 5 | ||
done | ||
|
||
# Fix brew linking of qt5 | ||
echo -e "\033[36m> Fixing brew linking of qt5...\033[0m" | ||
brew unlink qt && brew link qt@5 | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Building Gazebo Harmonic | ||
printf '\n\n\033[34m'; printf '=%.0s' {1..75}; printf '\033[0m\n' | ||
echo -e "\033[34m### [5/6] Building Gazebo Harmonic (This may take about 10 minutes)\033[0m" | ||
printf '\033[34m%.0s=\033[0m' {1..75} && echo | ||
# ------------------------------------------------------------------------------ | ||
# if ! colcon build --symlink-install --cmake-args -DBUILD_TESTING=OFF -Wno-dev --packages-skip-by-dep python_qt_binding; | ||
if ! python3.11 -m colcon build --cmake-args -DBUILD_TESTING=OFF -DCMAKE_MACOSX_RPATH=FALSE \ | ||
-DCMAKE_INSTALL_NAME_DIR="$HOME/$GZ_INSTALL_ROOT/install/lib" \ | ||
--merge-install -Wno-dev --event-handlers console_cohesion+; | ||
then | ||
echo -e "\033[31mError: Build failed, aborting script.\033[0m" | ||
exit 1 | ||
fi | ||
|
||
# ------------------------------------------------------------------------------ | ||
# Post Installation Configuration | ||
printf '\n\n\033[34m'; printf '=%.0s' {1..75}; printf '\033[0m\n' | ||
echo -e "\033[34m### [6/6] Post Installation Configuration\033[0m" | ||
printf '\033[34m%.0s=\033[0m' {1..75} && echo | ||
# ------------------------------------------------------------------------------ | ||
# save GZ_INSTALL_ROOT in a file | ||
if [ -f config ]; then | ||
rm config | ||
fi | ||
echo "GZ_INSTALL_ROOT=$GZ_INSTALL_ROOT" > "$HOME/$ROS_INSTALL_ROOT/config" | ||
|
||
# Download sentenv.sh | ||
if [ -f setenv.sh ]; then | ||
rm setenv.sh | ||
fi | ||
if [ -f setenv_gz.sh ]; then | ||
rm setenv_gz.sh | ||
fi | ||
curl -s -O https://raw.githubusercontent.com/IOES-Lab/ROS2_Jazzy_MacOS_Native_AppleSilicon/main/setenv_gz.sh | ||
|
||
# Replace string inside sentenv.sh | ||
sed -i '' "s|ROS_INSTALL_ROOT|$ROS_INSTALL_ROOT|g" setenv_gz.sh | ||
sed -i '' "s|VIRTUAL_ENV_ROOT|$VIRTUAL_ENV_ROOT|g" setenv_gz.sh | ||
sed -i '' "s|GZ_INSTALL_ROOT|$GZ_INSTALL_ROOT|g" setenv_gz.sh | ||
|
||
# Rename sentenv.sh to activate_ros | ||
if [ -f activate_ros ]; then | ||
rm activate_ros | ||
fi | ||
mv setenv_gz.sh activate_ros | ||
|
||
# Print post messages | ||
printf '\033[32m%.0s=\033[0m' {1..75} && echo | ||
echo -e "\033[32mDone. Hurray! 🍎 (Apple Silicon) + 🤖 = 🚀❤️🤩🎉🥳 \033[0m" | ||
echo | ||
echo "To activate the new ROS2 Jazzy - Gazebo Harmonic framework, run the following command:" | ||
echo -e "\033[32msource $HOME/$ROS_INSTALL_ROOT/activate_ros\033[0m" | ||
echo -e "\nThen, try '\033[32mros2\033[0m' or '\033[32mrviz2\033[0m' in the terminal to start ROS2 Jazzy." | ||
printf '\033[32m%.0s=\033[0m' {1..75} && echo | ||
echo "To make alias for fast start, run the following command to add to ~/.zprofile:" | ||
echo -e "\033[34mecho 'alias jazzy=\"source $HOME/$ROS_INSTALL_ROOT/activate_ros\"' >> ~/.zprofile && source ~/.zprofile\033[0m" | ||
echo | ||
echo -e "Then, you can start ROS2 Jazzy by typing '\033[34mjazzy\033[0m' in the terminal (new terminal)." | ||
echo | ||
echo "To deactivate this workspace, run:" | ||
echo -e "\033[33mdeactivate\033[0m" | ||
|
||
# Ask if user wants to install Gazebo Harmonic too (gz_install.sh) | ||
echo -e "\n\033[33mDo you want to install Gazebo Harmonic too? (y/n)\033[0m" | ||
read -r response | ||
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then | ||
echo -e "\033[36m> Installing Gazebo Harmonic...\033[0m" | ||
curl -s -O https://raw.githubusercontent.com/IOES-Lab/ROS2_Jazzy_MacOS_Native_AppleSilicon/main/gz_install.sh | ||
chmod +x gz_install.sh | ||
# shellcheck disable=SC1090 | ||
source "$HOME/$ROS_INSTALL_ROOT/activate_ros" | ||
./gz_install.sh | ||
fi | ||
|
||
popd || exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
# Source Virtual Environment | ||
|
||
# shellcheck disable=SC1091 | ||
source "$HOME/VIRTUAL_ENV_ROOT/bin/activate" | ||
|
||
# Source ROS | ||
if [[ $SHELL == *"bash"* ]]; then | ||
# shellcheck disable=SC1091 | ||
source "$HOME/ROS_INSTALL_ROOT/install/setup.bash" | ||
# shellcheck disable=SC1091 | ||
source "$HOME/ROS_INSTALL_ROOT/GZ_INSTALL_ROOT/install/setup.bash" | ||
elif [[ $SHELL == *"zsh"* ]]; then | ||
# shellcheck disable=SC1091 | ||
source "$HOME/ROS_INSTALL_ROOT/install/setup.zsh" | ||
# shellcheck disable=SC1091 | ||
source "$HOME/ROS_INSTALL_ROOT/GZ_INSTALL_ROOT/install/setup.zsh" | ||
else | ||
echo "Unsupported shell. Please use bash or zsh." | ||
exit 1 | ||
fi |