Created
April 8, 2024 04:59
-
-
Save rwbot/46963bfa6459bfcf8ff6b6fa502c0e88 to your computer and use it in GitHub Desktop.
dotfiles
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
#! /bin/bash | |
#------------------------------------------------------------------ | |
#------------------------------------------------------------------ | |
# file: bl_install_ros.sh | |
# date: 01/24/2019 | |
# author: Mark Cass | |
# description: Instal robot operating system and additional | |
# resources required for development. | |
# | |
# change log: | |
# 01/24/2019 - Initial Release | |
# 01/31/2019 - changed installed version of gazebo, on xenial to version | |
# gazebo7. added additional gazebo dependencies. fixed rosdep | |
# so it is no longer run as root. added package check for ros | |
# qt plugin. added version string and set to 1.3 | |
# 02/11/2019 - Removed package check for qt creator install | |
# Removed Gazebo install (installing ROS installs Gazebo) | |
# Added alias 'sws' to .bashrc | |
#------------------------------------------------------------------ | |
#------------------------------------------------------------------ | |
INSTALLER_VERSION=1.5 | |
LOG_FILE="install_ros" | |
ROS_KEY_SERVER="hkp://keyserver.ubuntu.com:80" | |
ROS_INSTALL_KEY="C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654" | |
function show_help() | |
{ | |
echo " | |
NAME | |
install_ros.sh | |
VERSION: | |
$INSTALLER_VERSION | |
SYNOPSIS | |
Install Robot Operating System development environment. | |
DESCRIPTION | |
This script installs the Robot Operating System development | |
and deployment SDK's tools and environment. The script | |
will install the Melodic version of ROS on Ubuntu 18.04.x hosts | |
and the Kinetic version on Ubuntu 16.x.x hosts. | |
This script requires root privileges to run. | |
COMMAND LINE | |
sudo ./install_ros.sh [OPTIONS] | |
OPTIONS | |
--reinstall | |
This option will cause all ROS packages to be reinstalled if they are | |
currently installed. | |
--no_qt_creator | |
Do not install QT Creator or QT Creator ROS plugin. | |
OUTPUT FILES | |
A log is generated is generated when an operation other than | |
help specified. | |
" | |
} | |
# convert a list of comma separated values to a list of space separated values. | |
# args: | |
# arg1: string with comma separated list | |
# echo return | |
# string with space seaparted list | |
function comma_list_to_space_list() | |
{ | |
local comma_list="$1" | |
local space_list="$(printf "%s" "$comma_list" | sed 's#\,#\ #g')" | |
printf "%s" "$space_list" | |
} | |
# parse a string of command line arguments and look for a specific option | |
# that is without a corresponding value. | |
# args: | |
# arg1: option to find | |
# arg2: command line arguement string | |
# echo return | |
# true : the options was found | |
# false: the option was not found | |
function has_option_novalue() | |
{ | |
local options="$1" | |
local args="$2" | |
local option_list="$(comma_list_to_space_list "$options")" | |
local option="" | |
local grep_option="" | |
local option_arg="" | |
local return_value="false" | |
for option in $option_list; do | |
grep_option="$(printf "%s" "$option" | sed "s@\-@\\\\-@g")" | |
option_arg="$(printf "%s" "$args" | grep -oE "$grep_option"'([\ ]{1}|$)')" | |
if [[ "$option_arg" != "" ]]; then | |
return_value="true" | |
break | |
fi | |
done | |
printf "%s" "$return_value" | |
} | |
# parse a string of command line arguments and look for | |
# option whose form is option=value. | |
# args: | |
# arg1: option for which a value is needed | |
# arg2: command line arguement string | |
# echo return | |
# true if option value was found | |
# false if not found | |
function has_option_value() | |
{ | |
local options="$1" | |
local args="$2" | |
local option_list="$(comma_list_to_space_list "$options")" | |
local option="" | |
local grep_option="" | |
local option_arg="" | |
local return_value="false" | |
for option in $option_list; do | |
grep_option="$(printf "%s" "$option" | sed "s@\-@\\\\-@g")" | |
option_arg="$(printf "%s" "$args" | grep -oE "$grep_option="'([^\ ]+|$)')" | |
if [[ "$option_arg" != "" ]]; then | |
return_value="true" | |
break | |
fi | |
done | |
echo "$return_value" | |
} | |
# parse a string of command line arguments and retieve the value of an | |
# option whose form is option=value. | |
# args: | |
# arg1: option for which a value is needed | |
# arg2: command line arguement string | |
# echo return | |
# the options value. | |
# empty string if option not found or no value specified. | |
function get_option_value() | |
{ | |
local options="$1" | |
local args="$2" | |
local option_list="$(comma_list_to_space_list "$options")" | |
local option="" | |
local grep_option="" | |
local option_arg="" | |
local option_value="" | |
for option in $option_list; do | |
if [[ "$(has_option_value "$option" "$args")" == false ]]; then | |
continue | |
fi | |
grep_option="$(printf "%s" "$option" | sed "s@\-@\\\\-@g")" | |
option_arg="$(printf "%s" "$args" | grep -oE "$grep_option="'([^\ ]+|$)')" | |
option_value="$(printf "%s" "$option_arg" | grep -oE '[^=]+$')" | |
break | |
done | |
printf "%s" "$option_value" | |
} | |
# parse help text string and extract list of valid command line args and options | |
# args: | |
# arg1: string containing help text | |
# echo return | |
# space separated list of valid arguments and options. Each option will have '-' | |
# or '--' prefix. valid options and arguments may be repeated. | |
function valid_args_from_help() | |
{ | |
local help_text="$1" | |
local valid_args="" | |
while read help_line; do | |
help_line="$(printf "%s" "$help_line" | grep -oE '^[-]{1,2}[^=^.]+')" | |
if [[ "$help_line" != "" ]]; then | |
help_line="$(printf "%s" "$help_line" | tr ',' ' ' )" | |
valid_args+=" $(printf "%s" "$help_line" | tr '\n' ' ')" | |
fi | |
done <<< "$help_text" | |
echo "$valid_args" | |
} | |
# parse command line args and check for invalid arguments. | |
# args: | |
# arg1: string of command line args and options | |
# arg2: space separated list of valid command line arguments. | |
# echo return | |
# invalid argument if found else empty string | |
function validate_cmdline_args() | |
{ | |
local cmd_line="$1" | |
local valid_args="$2" | |
local invalid_arg="" | |
local cmd_args="$(printf "%s" "$cmd_line" | grep -oE '(^|[\ ])[-]{1,2}[^=^.]+' | tr '\n' ' ')" | |
local cmd_arg_array=( $cmd_args ) | |
if [[ "$cmd_line" != "" && "$cmd_args" == "" ]]; then | |
cmd_arg_array=( $cmd_line ) | |
printf "%s" "${cmd_arg_array[0]}" | |
return | |
fi | |
local arg="" | |
local grepable_arg="" | |
local matching_arg="" | |
for arg in "${cmd_arg_array[@]}"; do | |
grepable_arg="$(printf "%s" "$arg" | sed "s@\-@\\\\-@g")" | |
matching_arg="$(printf "%s" "$valid_args" | grep -oE "$grepable_arg(\ |\$)" | head -n1)" | |
if [[ "$matching_arg" == "" ]]; then | |
invalid_arg="$arg" | |
break | |
fi | |
done | |
printf "%s" "$invalid_arg" | |
} | |
function install_apt_package () | |
{ | |
local package="$1" | |
local reinstall="$2" | |
local result_code=0 | |
dpkg -s $package &> /dev/null | |
result_code=$? | |
if [[ $result_code -eq 0 && $reinstall != "reinstall" ]]; then | |
echo " *** Skipping : $package is already installed" | |
else | |
echo " *** Installing: $package" | |
local reinstall_flag="" | |
if [[ "$reinstall" == "reinstall" ]]; then | |
reinstall_flag="--reinstall" | |
fi | |
sudo apt install $reinstall_flag $package -y | |
fi | |
} | |
function install_apt_package_list () | |
{ | |
local package_list=("$1") | |
local reinstall="$2" | |
for pkg in ${package_list[@]}; do | |
install_apt_package $pkg $reinstall | |
done | |
} | |
function install_ros_key() | |
{ | |
local result_code=0 | |
sudo apt-key adv --keyserver $ROS_KEY_SERVER --recv-key $ROS_INSTALL_KEY | |
sudo apt update -y | |
} | |
#------------------------------------------------------- | |
#------------------------------------------------------- | |
#------------------------------------------------------- | |
#------------------------------------------------------- | |
#------------------------------------------------------- | |
# Script entry point | |
#------------------------------------------------------- | |
#------------------------------------------------------- | |
#------------------------------------------------------- | |
#------------------------------------------------------- | |
#------------------------------------------------------- | |
if [[ "$(has_option_novalue "--help,-h,-help,help" "$*")" == true ]]; then | |
show_help | |
exit 0 | |
fi | |
#------------------------------------------------------------- | |
#------------------------------------------------------------- | |
# validate arguments and options | |
# ------------------------------------------------------------ | |
valid_args="$(valid_args_from_help "$(show_help)")" | |
invalid_arg="$(validate_cmdline_args "$*" "$valid_args")" | |
if [[ "$invalid_arg" != "" ]]; then | |
show_help | |
echo " " | |
echo "Error: invalid command line option: $invalid_arg" | |
echo " " | |
exit 1 | |
fi | |
#------------------------------------------------------------- | |
#------------------------------------------------------------- | |
#------------------------------------------------------------- | |
# start logging | |
# ------------------------------------------------------------ | |
date_format="%Y_%m_%d-%H_%M_%S" | |
LOG_FILE+="_"$(date +"$date_format")".log" | |
echo " " | |
echo "~~~~~~~~~~~~~~" | |
echo "logging to file: $LOG_FILE" | |
echo "~~~~~~~~~~~~~~" | |
exec > >(tee -ia $LOG_FILE) 2>&1 | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Setting up command line options" | |
echo "-------------------------------------------------------------" | |
REINSTALL="" | |
if [[ "$(has_option_novalue "--reinstall" "$*")" == true ]]; then | |
echo "~~~~~~~~~~~~~~" | |
echo "reinstall option enabled. all installed packages will be reinstalled" | |
echo "~~~~~~~~~~~~~~" | |
REINSTALL="reinstall" | |
fi | |
QT_CREATOR="true" | |
if [[ "$(has_option_novalue "--no_qt_creator" "$*")" == true ]]; then | |
echo "~~~~~~~~~~~~~~" | |
echo "no_qt_creator option enabled. QT Creator ROS plugin will not be installed." | |
echo "~~~~~~~~~~~~~~" | |
QT_CREATOR="false" | |
fi | |
cd $HOME | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Checking for root privileges" | |
echo "-------------------------------------------------------------" | |
if [[ "$(whoami)" != "root" ]]; then | |
echo " " | |
echo "Error: Script must be run as super user or with sudo." | |
exit 1 | |
else | |
echo " " | |
echo "Installing for user $SUDO_USER with root priviliges" | |
echo " " | |
fi | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Determining ROS version to install" | |
echo "-------------------------------------------------------------" | |
UBUNTU_RELEASE="$(lsb_release -c | cut -f 2)" | |
ROS_RELEASE="" | |
if [[ "$UBUNTU_RELEASE" == "xenial" ]]; then | |
ROS_RELEASE="kinetic" | |
elif [[ "$UBUNTU_RELEASE" == "bionic" ]]; then | |
ROS_RELEASE="melodic" | |
elif [[ "$UBUNTU_RELEASE" == "focal" ]]; then | |
ROS_RELEASE="noetic" | |
elif [[ "$UBUNTU_RELEASE" == "" ]]; then | |
echo "Error: Could not determine the required ROS release version to install." | |
echo " For Ubuntu release: $UBUNTU_RELEASE" | |
exit 1 | |
fi | |
echo " " | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Bastian Solutions Research and Development - ROS development environment installer" | |
echo " Installer version: $INSTALLER_VERSION" | |
echo " Detected Ubuntu release: $UBUNTU_RELEASE" | |
echo " Installing ROS release : $ROS_RELEASE" | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo " " | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Installing non-ROS support packages" | |
echo "-------------------------------------------------------------" | |
echo "------- Installing ubuntu base packages" | |
UBUNTUBASE_PACKAGES="git meld build-essential libfontconfig1 mesa-common-dev libglu1-mesa-dev" | |
install_apt_package_list "$UBUNTUBASE_PACKAGES" | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Adding ROS repository keys" | |
echo "-------------------------------------------------------------" | |
sh -c 'echo "deb http://packages.ros.org/ros/ubuntu '"$UBUNTU_RELEASE"' main" > /etc/apt/sources.list.d/ros-latest.list' | |
key_result="$(install_ros_key)" | |
echo "$key_result" | |
key_check="$(echo "$key_result" | grep "NO_PUBKEY")" | |
if [[ "$key_check" != "" ]]; then | |
echo " " | |
echo "Error: ROS has changed the key server address and/or its PGP key." | |
echo "Please refer to the website: http://wiki.ros.org/melodic/Installation/Ubuntu" | |
echo "Under the section \"Setting up your Keys\" for the new server and/or key" | |
echo "then edit the script variables ROS_KEY_SERVER and ROS_INSTALL_KEY to update" | |
echo "this script." | |
exit 1 | |
fi | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Updating Ubuntu packages to include latest ROS packages" | |
echo "-------------------------------------------------------------" | |
apt update -y | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Installing ROS $ROS_RELEASE base packages" | |
echo "-------------------------------------------------------------" | |
ROS_PACKAGES="ros-$ROS_RELEASE-desktop-full" | |
install_apt_package_list "$ROS_PACKAGES" "$REINSTALL" | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Installing ROS $ROS_RELEASE support packages" | |
echo "-------------------------------------------------------------" | |
ROS_SUPPORT_PACKAGES="python-rosdep python-rosinstall python-rosinstall-generator python-wstool python-catkin-tools" | |
ROS_SUPPORT_PACKAGES+=" ros-$ROS_RELEASE-urdf-tutorials ros-$ROS_RELEASE-moveit" | |
ROS_SUPPORT_PACKAGES+=" ros-$ROS_RELEASE-openni-camera ros-$ROS_RELEASE-openni-launch ros-$ROS_RELEASE-openni2-camera ros-$ROS_RELEASE-openni2-launch" | |
ROS_SUPPORT_PACKAGES+=" pcl-tools" | |
install_apt_package_list "$ROS_SUPPORT_PACKAGES" "$REINSTALL" | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Configuring ROS environment" | |
echo "-------------------------------------------------------------" | |
ROS_ENV_COMMAND="source /opt/ros/$ROS_RELEASE/setup.bash" | |
if [[ "$(cat $HOME/.bashrc | grep -oE "^$ROS_ENV_COMMAND")" == "" ]]; then | |
echo "$ROS_ENV_COMMAND" >> $HOME/.bashrc | |
else | |
echo "Skipping: ROS environment already in .bashrc" | |
fi | |
SOURCE_WS_COMMAND="alias sws='source ./devel/setup.bash'" | |
if [[ "$(cat $HOME/.bashrc | grep -oE "^$SOURCE_WS_COMMAND")" == "" ]]; then | |
echo "$SOURCE_WS_COMMAND" >> $HOME/.bashrc | |
else | |
echo "Skipping: Source Workspace alias, already in .bashrc" | |
fi | |
source $HOME/.bashrc | |
rosdep init | |
sudo -u $SUDO_USER rosdep update | |
echo "-------------------------------------------------------------" | |
echo "-------------------------------------------------------------" | |
echo "Installing ROS QT Creator plugin" | |
echo "-------------------------------------------------------------" | |
if [[ "$QT_CREATOR" == "true" ]]; then | |
echo "------- Installing ROS QT Creator plugin" | |
QTPATH="https://qtcreator-ros.datasys.swri.edu/downloads/installers/$UBUNTU_RELEASE" | |
QTFILE="qtcreator-ros-$UBUNTU_RELEASE-latest-online-installer.run" | |
sudo -u $SUDO_USER wget $QTPATH/$QTFILE | |
sudo -u $SUDO_USER chmod u+x ./$QTFILE | |
sudo -u $SUDO_USER ./$QTFILE | |
sudo -u $SUDO_USER rm ./$QTFILE | |
else | |
echo "****** Skipping ROS QT Creator plugin install per command line option" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment