Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/environment_install/install-ROS-ubuntu.sh
Views: 1798
#!/usr/bin/env bash1echo "---------- $0 start ----------"2set -e3# set -x45ROS_WS_ROOT=$HOME/ardupilot-ws6AP_GZ_ROOT=$HOME/ardupilot_gz_ws78red=`tput setaf 1`9green=`tput setaf 2`10reset=`tput sgr0`1112sep="##############################################"131415function heading() {16echo "$sep"17echo $*18echo "$sep"19}2021ASSUME_YES=false2223function maybe_prompt_user() {24if $ASSUME_YES; then25return 026else27read -p "$1"28if [[ $REPLY =~ ^[Yy]$ ]]; then29return 030else31return 132fi33fi34}3536function usage37{38echo "Usage: ./installROS.sh [[-p package] | [-h]]"39echo "Install ROS1"40echo "This script will select the ROS distribution according to the OS being used"41echo "Installs desktop-full as default base package; Use -p to override"42echo "-p | --package <packagename> ROS package to install"43echo " Multiple usage allowed"44echo " Must include one of the following:"45echo " ros-base"46echo " desktop"47echo " desktop-full"48echo "-h | --help This message"49}5051function shouldInstallPackages52{53echo "${red}Your package list did not include a recommended base package${reset}"54echo "Please include one of the following:"55echo " ros-base"56echo " desktop"57echo " desktop-full"58echo ""59echo "ROS not installed"60}6162function package_is_installed() {63dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed"64}6566# Iterate through command line inputs67packages=()68while [ "$1" != "" ]; do69case $1 in70-p | --package ) shift71packages+=("$1")72;;73-h | --help ) usage74exit75;;76* ) usage77exit 178esac79shift80done8182# Install lsb-release as it is needed to check Ubuntu version83if ! package_is_installed "lsb-release"; then84heading "Installing lsb-release"85sudo apt install lsb-release -y86echo "Done!"87fi8889# Checking Ubuntu release to adapt software version to install90RELEASE_CODENAME=$(lsb_release -c -s)91PYTHON_V="python3" # starting from ubuntu 20.04, python isn't symlink to default python interpreter929394# echo $RELEASE_CODENAME9596if [ ${RELEASE_CODENAME} == 'bionic' ] ; then97#Ubuntu 18.04 - Melodic98ROS_VERSION="melodic"99PYTHON_V="python2"100heading "${green}Detected Ubuntu 18.04, installing ROS Melodic${reset}"101elif [ ${RELEASE_CODENAME} == 'buster' ]; then102#RPi Buster - Melodic103ROS_VERSION="melodic"104PYTHON_V="python2"105heading "${green}Detected RPi Buster, installing ROS Melodic${reset}"106elif [ ${RELEASE_CODENAME} == 'focal' ]; then107#Ubuntu 20.04 - Noetic108ROS_VERSION="noetic"109PYTHON_V="python3"110heading "${green}Detected Ubuntu 20.04, installing ROS Noetic${reset}"111elif [ ${RELEASE_CODENAME} == 'jammy' ]; then112#Ubuntu 22.04 - unsupported only ROS2113heading "${red}Currently only ROS1 is supported. This Ubuntu release can only be used with ROS2.${reset}"114exit 1115else116# We assume an unsupported OS is being used.117heading "${red}Unsupported OS detected. Please refer to the ROS webpage to find how to install ROS1 on your system if at all possible.${reset}"118exit 1119fi120121# Check to see if other packages were specified122# If not, set the default base package123if [ ${#packages[@]} -eq 0 ] ; then124packages+="desktop-full"125fi126echo "Packages to install: "${packages[@]}127# Check to see if we have a ROS base kinda thingie128hasBasePackage=false129for package in "${packages[@]}"; do130if [[ $package == "ros-base" ]]; then131delete=ros-base132packages=( "${packages[@]/$delete}" )133packages+=" ros-${ROS_VERSION}-ros-base"134hasBasePackage=true135break136elif [[ $package == "desktop" ]]; then137delete=desktop138packages=( "${packages[@]/$delete}" )139packages+=" ros-${ROS_VERSION}-desktop"140hasBasePackage=true141break142elif [[ $package == "desktop-full" ]]; then143delete=desktop-full144packages=( "${packages[@]/$delete}" )145packages+=" ros-${ROS_VERSION}-desktop-full"146hasBasePackage=true147break148fi149done150if [ $hasBasePackage == false ] ; then151shouldInstallPackages152exit 1153fi154155heading "${green}Adding Repositories and source lists${reset}"156#Lets start instaling stuff157sudo apt install software-properties-common -y158sudo apt-add-repository universe159sudo apt-add-repository multiverse160sudo apt-add-repository restricted161162# Setup sources.lst163sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'164# Setup keys165sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654166# If you experience issues connecting to the keyserver, you can try substituting hkp://pgp.mit.edu:80 or hkp://keyserver.ubuntu.com:80 in the previous command.167# Installation168169heading "${green}Updating apt${reset}"170sudo apt update171172heading "${green}Installing ROS${reset}"173# Here we loop through any packages passed on the command line174# Install packages ...175for package in "${packages[@]}"; do176sudo apt install $package -y177done178179# This is where you might start to modify the packages being installed, i.e.# sudo apt install ros-${ROS_VERSION}-{package_name}180# sudo apt install -y setpriv181# sudo apt install -y ros-${ROS_VERSION}-robot-upstart182# sudo apt install -y ros-${ROS_VERSION}-navigation183184# Install MAVROS and the geographic libs185sudo apt install -y ros-${ROS_VERSION}-mavros186187wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh188sudo bash ./install_geographiclib_datasets.sh189190# install other needed packages191sudo apt install build-essential cmake -y192193#194# To find available packages:195# apt-cache search ros-melodic196#197# Initialize rosdep198199heading "${green}Installing rosdep${reset}"200201sudo apt install ${PYTHON_V}-rosdep -y202# Certificates are messed up on earlier version Jetson for some reason203# Do not know if it is an issue with the Xavier, test by commenting out204# sudo c_rehash /etc/ssl/certs205# Initialize rosdep206207heading "${green}Initializaing rosdep${reset}"208209sudo rosdep init || true210# To find available packages, use:211rosdep update212# Use this to install dependencies of packages in a workspace213# rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y214# Environment Setup - Don't add /opt/ros/${ROS_VERSION}/setup.bash if it's already in bashrc215if maybe_prompt_user "Do you want to add ROS_HOSTNAME and ROS_MASTER_URI to your .bashrc [N/y]?" ; then216heading "${green}Adding setup.bash, ROS_MASTER_URI and ROS_HOSTNAME to .bashrc ${reset}"217grep -q -F "ROS_HOSTNAME=$HOSTNAME.local" ~/.bashrc || echo "ROS_HOSTNAME=$HOSTNAME.local" >> ~/.bashrc218grep -q -F "ROS_MASTER_URI=http://$HOSTNAME.local:11311" ~/.bashrc || echo "ROS_MASTER_URI=http://$HOSTNAME.local:11311" >> ~/.bashrc219grep -q -F "source /opt/ros/${ROS_VERSION}/setup.bash" ~/.bashrc || echo "source /opt/ros/${ROS_VERSION}/setup.bash" >> ~/.bashrc220source ~/.bashrc221fi222223heading "${green}Installing rosinstall tools${reset}"224225sudo apt install ${PYTHON_V}-rosinstall ${PYTHON_V}-rosinstall-generator ${PYTHON_V}-wstool ${PYTHON_V}-catkin-tools -y226227heading "${green}Installing Ardupilot-ROS workspace${reset}"228229if maybe_prompt_user "Add ardupilot-ws to your home folder [N/y]?" ; then230if [ ! -d $ROS_WS_ROOT ]; then231mkdir -p $ROS_WS_ROOT/src232pushd $ROS_WS_ROOT233source /opt/ros/${ROS_VERSION}/setup.bash234catkin init235pushd src236git clone https://github.com/ArduPilot/ardupilot_ros.git237popd238sudo apt update239rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y240catkin build241popd242else243heading "${red}ardupilot-ws already exists, skipping...${reset}"244fi245246else247echo "Skipping adding ardupilot_ws to your home folder."248fi249250251if maybe_prompt_user "Add ardupilot_gazebo to your home folder [N/y]?" ; then252if [ ! -d $AP_GZ_ROOT ]; then253sudo apt install gz-garden rapidjson-dev254mkdir -p $AP_GZ_ROOT/src255pushd $AP_GZ_ROOT/src256git clone https://github.com/ArduPilot/ardupilot_gazebo257pushd ardupilot_gazebo258mkdir build && pushd build259cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo260make -j4261popd262popd263popd264echo "export GZ_SIM_SYSTEM_PLUGIN_PATH=${AP_GZ_ROOT}/src/ardupilot_gazebo/build:${GZ_SIM_SYSTEM_PLUGIN_PATH}" >> ~/.bashrc265echo "export GZ_SIM_RESOURCE_PATH=${AP_GZ_ROOT}/src/ardupilot_gazebo/models:${AP_GZ_ROOT}/src/ardupilot_gazebo/worlds:${GZ_SIM_RESOURCE_PATH}" >> ~/.bashrc266else267heading "${red}ardupilot_gazebo already exists, skipping...${reset}"268fi269270else271echo "Skipping adding ardupilot_gazebo to your home folder."272fi273274heading "${green}Adding setup.bash, ROS_MASTER_URI and ROS_HOSTNAME to .bashrc ${reset}"275grep -q -F "source $ROS_WS_ROOT/devel/setup.bash" ~/.bashrc || echo "source $ROS_WS_ROOT/devel/setup.bash" >> ~/.bashrc276source ~/.bashrc277278heading "${green}Installation complete! Please close this terminal and open a new one for changes to take effect!${reset}"279280281