-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvease.sh
186 lines (159 loc) · 6.24 KB
/
envease.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
############################################################################################
# Copyright : Copyright© The University of Texas at Austin, 2023. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of python-odmltables nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
############################################################################################
####################
### DO NOT TOUCH ###
####################
# Directory of this script (normally /opt/EnvEase)
script_dir=$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")
# Various functions
source $script_dir/functions.sh
# Look up our currently active EnvEase environment
source $HOME/.envease/cur_env.sh
if [ -z $ENVEASE_ENV ]; then
echo "Error: Variable ENVEASE_ENV not found in $HOME/.envease/cur_env.sh. The file is deformed."
return
fi
if [ -z $ENVEASE_VERBOSE ]; then
echo "Error: Variable ENVEASE_VERBOSE not found in $HOME/.envease/cur_env.sh. The file is deformed."
return
fi
export ENVEASE_ENV
export ENVEASE_VERBOSE
if [ "$ENVEASE_VERBOSE" == true ]; then
echo "Active environment configuration: $ENVEASE_ENV"
fi
# Enables tab completion in bash for our envease script
eval "$(register-python-argcomplete3 envease)"
# Source the active EnvEase environment config
if [ $ENVEASE_ENV == none ]; then
echo "No EnvEase configuration set. Use the envease command to set one."
return
fi
source $HOME/.envease/configs/$ENVEASE_ENV.sh
# If the GitHub repo is not specified, set all the Gitub variables to empty string.
if [ -z $alias_repo_owner ] || [ -z $alias_repo_name ]; then
alias_repo_owner=""
alias_repo_name=""
repo_auth_token=""
fi
# Get our common aliases
handle_alias_file "" "common" $alias_repo_owner $alias_repo_name $repo_auth_token
for k in "${platform_aliases[@]}"; do
handle_alias_file "platform" $k $alias_repo_owner $alias_repo_name $repo_auth_token
done
for k in "${project_aliases[@]}"; do
handle_alias_file "project" $k $alias_repo_owner $alias_repo_name $repo_auth_token
done
for k in "${tool_aliases[@]}"; do
handle_alias_file "tool" $k $alias_repo_owner $alias_repo_name $repo_auth_token
done
unset k
# If we have specified both ROS1 and ROS2 distributions,
# then set the extra environment variables needed by ros1_bridge
if [ ! -z $ros1_distribution ] && [ ! -z $ros2_distribution ]; then
export ROS1_INSTALL_PATH=/opt/ros/${ros1_distribution}/setup.bash
export ROS2_INSTALL_PATH=/opt/ros/${ros2_distribution}/setup.bash
if [ "$ENVEASE_VERBOSE" == true ]; then
echo "Using ros1_bridge from $ros1_distribution to $ros2_distribution"
fi
else
unset ROS1_INSTALL_PATH
unset ROS2_INSTALL_PATH
fi
# clear any pre-existing variables
unset ROS_DISTRO
unset ROS_IP
unset ROS_MASTER_URI
unset RMW_IMPLEMENTATION
unset FASTRTPS_DEFAULT_PROFILES_FILE
unset ROS_DISCOVERY_SERVER
unset ROS_DOMAIN_ID
unset ROS_PACKAGE_PATH
# ROS1
if [ ! -z $ros1_distribution ]; then
if [ -z $ros_master_uri ]; then
ros_master_uri=http://localhost:11311/
elif [ -z $network_interface ]; then
network_interface=lo
else
if [ "$ENVEASE_VERBOSE" == true ]; then
echo "Using ROS 1 distribution: $ros1_distribution"
echo " Workspaces: $ros1_workspaces"
echo " ros_master_uri: $ros_master_uri"
fi
source $script_dir/ros.sh $ros1_distribution $ros_master_uri $network_interface $ros1_workspaces
fi
fi
# suppresses an annoying warning when using a mixed-distribution environment
unset ROS_DISTRO
# ROS2
if [ ! -z $ros2_distribution ]; then
if [ "$ENVEASE_VERBOSE" == true ]; then
echo "Using ROS 2 distribution: $ros2_distribution"
echo " Workspaces: $ros2_workspaces"
fi
if [ ! -z $ros_domain_id ]; then
# Input validation
if [ $ros_domain_id -lt 0 ] || [ $ros_domain_id -gt 232 ] || [[ $ros_domain_id -gt 101 && $ros_domain_id -lt 215 ]]; then
echo "Invalid ROS_DOMAIN_ID value of $ros_domain_id. Must be in ranges [0,101] or [215,232]."
return
fi
# Use normal ROS2 discovery using multicasting
source $script_dir/ros.sh $ros2_distribution $ros_domain_id "" $ros2_workspaces
if [ "$ENVEASE_VERBOSE" == true ]; then
echo " ROS_DOMAIN_ID: $ros_domain_id"
fi
elif [ ! -z $ros_discovery_server ]; then
# Use discovery server with FastDDS
source $script_dir/ros.sh $ros2_distribution $ros_discovery_server "" $ros2_workspaces --discovery_server
if [ "$ENVEASE_VERBOSE" == true ]; then
echo " FastDDS discovery server at: $ros_discovery_server"
fi
else
echo "Error: ros_domain_id or ros_discovery_server must be provided for a ROS2 distribution."
fi
fi
# cleanup
unset script_dir
unset ros1_distribution
unset ros2_distribution
unset ros1_workspaces
unset ros2_workspaces
unset ros_master_uri
unset ros_domain_id
unset ros_discovery_server
unset platform_aliases
unset project_aliases
unset tool_aliases
unset network_interface
unset use_ros1_bridge
unset alias_repo_owner
unset alias_repo_name
unset repo_auth_token