Skip to content

Instantly share code, notes, and snippets.

@KaoruNishikawa
Last active August 25, 2022 10:43
Show Gist options
  • Save KaoruNishikawa/d13bcdc2d304d64797868bbd47f2ae84 to your computer and use it in GitHub Desktop.
Save KaoruNishikawa/d13bcdc2d304d64797868bbd47f2ae84 to your computer and use it in GitHub Desktop.
NECST installation script for non-docker environment (never tested)
function get_ros2_workspace() {
# Look up environment variables.
# If the value isn't actually a directory, this will create it.
candidate=($ROS2_WS $ROS_WS)
for __value in $candidate; do
if [ ! -z $__value ]; then
echo $__value
[ ! -d $__value ] && mkdir -p $__value
return 0
fi
done
# Infer common names (ensuring it's not a ROS 1 workspace).
candidate=($HOME/ros2_ws $HOME/ros2 $HOME/ros_ws $HOME/ros $HOME/ros1 $HOME/catkin_ws)
for __path in $candidate; do
if [ -d $__path ] && [ ! -d $__path/devel ]; then
echo $__path
return 0
fi
done
# Fallback.
echo $HOME/ros2_ws
mkdir $HOME/ros2_ws
return 0
}
function get_shell_name() {
echo $(basename $SHELL)
}
function check_required_commands() {
ret=0
for __cmd in $@; do
if [ ! $(command -v $__cmd) ]; then
echo "Required command '$__cmd' not found"
ret=1
fi
done
return $ret
}
function write_rc_file() {
rc_file_path=$HOME/.${__shell}rc
if ! grep -q "$*" $rc_file_path; then
echo -e "$*" >> $rc_file_path
fi
}
. /opt/ros/$ROS_DISTRO/setup.$__shell 2>/dev/null || :
__required=(colcon git)
[ $(check_required_commands $__required) ] || exit 1
__shell=${$(get_shell_name):-bash} # Fallback is bash.
WORKSPACE=$(get_ros2_workspace)
[ ! -d $WORKSPACE/src ] && mkdir $WORKSPACE/src
git clone https://github.com/necst-telescope/necst.git $WORKSPACE/src/necst
git clone https://github.com/necst-telescope/necst-msgs.git $WORKSPACE/src/necst-msgs
( cd $WORKSPACE && colcon build --symlink-install )
. $WORKSPACE/install/setup.$__shell
if [ $(id -g) = 0 ] && __apt_command="apt-get" || __apt_command="sudo apt-get"
$__apt_command update
$__apt_command -y install rmw_cyclonedds_cpp
write_rc_file ". /opt/ros/$ROS_DISTRO/setup.$__shell"
write_rc_file ". $WORKSPACE/install/setup.$__shell"
write_rc_file "export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment