-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
227 lines (189 loc) · 7.29 KB
/
setup.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/sh
# TODO: enable the framework for ssh connections
# TODO: poder configurar system de forma simple. con lo elemental solamente.
# TODO: system multirobot
# TODO: check user vars are defined or use defaults
## SYSTEM PRE CONFIGURATION CHECKS
## ##########################################
# prevent multiple executions
_currshell=$(ps -p$$ -ocmd=)
if [ "$UCHILE_FRAMEWORK_TWICE_LOAD_CHECK" = true ]; then
if [ "$_currshell" = "$UCHILE_FRAMEWORK_LOADED_SHELL" ]; then
echo "You are loading this script twice. Please update your"
echo ".bashrc/.zshrc files and fix this problem. See the "
echo "system/README.md file to reconfigure your shell environment."
unset _currshell
return 0
fi
fi
export UCHILE_FRAMEWORK_TWICE_LOAD_CHECK=true
export UCHILE_FRAMEWORK_LOADED_SHELL="$_currshell"
# OBS: Some configurations are meant for outdated machines
# NOTE FOR FUTURE ADMINS: Update this configuration loading for
# release 2.0.
if [ -z "$CATKIN_SHELL" ]; then
# WARNING: THIS BEHAVIOR IS VALID FOR SSH CONNECTIONS!.
# OBS: THIS WARNING IS BENDER SPECIFIC!. This problem should only arise on
# pre MAQUI installations
echo "Sorry, the CATKIN_SHELL env variable is not set. I assume you are "
echo "loading this script as setup.sh. Please, modify your *rc file or "
echo "the uchile.sh file to source the proper shell script:"
echo "setup.bash or setup.zsh, for bash or zsh users."
echo ""
echo ""
echo "THE UCHILE ROS WORKSPACE WILL NOT BE LOADED. PLEASE, UPDATE YOUR SETTINGS"
echo "AS FOLLOWS:"
echo "$ cp $HOME/uchile.sh $HOME/uchile.sh.bkp"
echo "$ cp $HOME/uchile_ws/system/templates/uchile.sh $HOME/uchile.sh"
echo ""
echo "Then edit your .bashrc:"
echo "----------------------------------------------------------------"
echo '# UChile ROS Workspace settings: location, configs and setup script.'
echo 'export UCHILE_WS="$HOME"/uchile_ws'
echo 'export UCHILE_SHELL_CFG="$HOME"/uchile.sh'
echo '. "$UCHILE_WS"/system/setup.bash'
echo "----------------------------------------------------------------"
echo ""
echo "For zsh shells, edit your .zshrc and use the system/setup.zsh file."
echo "More info on the system/README.md file."
echo ""
echo "Bye."
unset _currshell
return 0
fi
if [ ! "$CATKIN_SHELL" = "bash" ] && [ ! "$CATKIN_SHELL" = "zsh" ]; then
echo "Sorry, but the UChile ROS Framework is only designed for bash and zsh shells."
echo "The framework will not be loaded. Bye"
unset _currshell
return 0
fi
# prevent running with an incorrect shell environment
if [ "$_currshell" = "bash" ] && [ ! "$CATKIN_SHELL" = "bash" ]; then
echo "Attempt to load the UChile ROS Framework for zsh shells on bash."
echo "Please, source the correct file: setup.bash"
echo "See also: system/README.md"
unset _currshell
return 0
fi
if [ "$_currshell" = "/usr/bin/zsh" ] && [ ! "$CATKIN_SHELL" = "zsh" ]; then
echo "Attempt to load the UChile ROS Framework for bash shells on zsh."
echo "Please, source the correct file: setup.zsh"
echo "See also: system/README.md"
unset _currshell
return 0
fi
unset _currshell
## SYSTEM USER CONFIGURATIONS
## ########################################################
# load configs
if [ -z "$UCHILE_SHELL_CFG" ]; then
echo "Sorry, the UCHILE_SHELL_CFG env variable is not set."
echo "Please, set this to the path of the uchile.sh script."
echo "e.g: \"$HOME/uchile.sh\""
echo "UChile ROS Framework will not be configured."
return 0
else
# mode for v1.0 and newer
if [ -e "$UCHILE_SHELL_CFG" ]; then
. "$UCHILE_SHELL_CFG"
else
echo "Sorry, the UCHILE_SHELL_CFG is set, but the configuration file cannot be read."
echo "Configuration file: $UCHILE_SHELL_CFG"
echo "Please, set this to the path of the uchile.sh script."
echo "e.g: \"$HOME/uchile.sh\""
echo "UChile ROS Framework will not be configured."
return 0
fi
fi
## checks
## -----------------------------------------
# ROBOT
if [ -z "$UCHILE_ROBOT" ]; then
echo "Sorry, the UCHILE_ROBOT env variable is not set."
return 0
fi
# UCHILE_WS
if [ -z "$UCHILE_WS" ]; then
echo "Sorry, the UCHILE_WS env variable is not set."
return 0
fi
if [ ! -d "$UCHILE_WS" ]; then
echo "Sorry, the UCHILE_WS env variable is set. But is not a valid directory."
echo "Found UCHILE_WS=\'$UCHILE_WS\'"
return 0
fi
## SYSTEM DEFS
## ##########################################
# paths
export UCHILE_SYSTEM="$UCHILE_WS"/system
export UCHILE_ROS_WS="$UCHILE_WS/ros/$UCHILE_ROBOT"
export UCHILE_DEPS_WS="$UCHILE_WS"/deps
export UCHILE_MISC_WS="$UCHILE_WS"/misc
export UCHILE_PKGS_WS="$UCHILE_WS"/pkgs
# contact
export UCHILE_SYSTEM_ADMIN="mpavezb (matias pavez)"
export UCHILE_EMAIL_CONTACT="[email protected]"
export UCHILE_EMAIL_DEVELOP="[email protected]"
# git hooks
export GITHOOKS_PATH="$UCHILE_SYSTEM/hooks"
# ros console output format
export ROSCONSOLE_FORMAT='[${severity}] [${node}]: ${message}'
# --------------------------------------------------------
# (compatibility with repos which depend on v1.9 env vars)
export BENDER_WS="$UCHILE_ROS_WS"
export BENDER_SYSTEM="$UCHILE_SYSTEM"
# --------------------------------------------------------
## ROS
## ##########################################
# manage network configurations
# ----------------------------------------
if [ "$UCHILE_NET_BY_SSH" = true ]; then
. "$UCHILE_SYSTEM"/env/network-defs.sh
fi
if [ "$UCHILE_NET_ENABLE" = true ]; then
. "$UCHILE_SYSTEM"/env/network-defs.sh
elif [ "$UCHILE_NET_WARN" = true ]; then
_caller_script=
if command -v caller >/dev/null 2>&1 ; then
_caller_script=" on the framework setup file ($(caller | awk '{print $2}'))"
fi
printf "\e[33m[WARNING]: The UChile ROS Framework has been launched in offline mode.
Maybe you should set 'UCHILE_NET_ENABLE=true'%s
and run another shell.
If you want to stop this and all network warnings,
set: 'UCHILE_NET_WARN=false'%s.\e[0m\n\n" "$_caller_script" "$_caller_script"
_sound_file="$UCHILE_SYSTEM"/assets/network_false.wav
if [ -f "$_sound_file" ]; then
aplay "$_sound_file" >/dev/null 2>&1
else
printf "\e[33m[WARNING]: I was supposed to play a sound, but the required .wav file is missing:
%s\e[0m\n\n" "$_sound_file"
fi
unset _sound_file
unset _caller_script
fi
# manage ros framework
# ---------------------------------------
#
# it's very very important to source the setup.sh files and not the setup.bash ones!
# this way, the configuration is not messed up when dealing with ssh.
setup_file="$UCHILE_ROS_WS"/high_ws/devel/setup.sh
if [ -e "${setup_file}" ]; then
. "${setup_file}"
else
printf "[UChile ROS Framework]: Error: Missing setup.sh file on high_ws.\n"
printf " - Required file: %s\n" "${setup_file}"
printf " - My advice is to run the workspace installer script:\n"
printf "\n"
printf " bash $UCHILE_SYSTEM/install/ws_installer.bash\n"
printf "\n"
printf "Then reopen the terminal and try again.\n"
printf "\n"
printf "ROS Will not be sourced.\n"
return 1
fi
unset setup_file
## UChile ROS Framework Tools
## ##########################################
# shell functionalities
. "$UCHILE_SYSTEM"/shell/setup.sh