forked from HumaRobotics/rosbash
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrosbash.bash
295 lines (267 loc) · 9.15 KB
/
rosbash.bash
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/bin/bash
# ROS NETWORK CONFIGURATION
rosnetwork() {
env | egrep "ROS_MASTER_URI|ROS_IP|ROS_HOSTNAME"
}
rosmaster() {
if [ $# -eq 0 ]
then
echo "Setting localhost"
export ROS_MASTER_URI=http://localhost:11311
unset ROS_IP
unset ROS_HOSTNAME
else
export ROS_MASTER_URI=http://$1:11311
fi
rosnetwork
rosprompt
}
rosip() {
export ROS_IP=$1
unset ROS_HOSTNAME
rosnetwork
}
roshostname() {
export ROS_HOSTNAME=$1
unset ROS_IP
rosnetwork
}
# PROMPT AND SHELL
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
rosprompt() {
MASTER=`echo $ROS_MASTER_URI | sed 's/http:\/\///' | sed 's/:11311//'`
# Extract top folder last componentent
ROSPATHNAME=`(roscd;cd ..; pwd | sed -e "s/.*\///g" )`
export PS1='\[\033[0;31m\]${ROS_DISTRO[@]:0:1} \[\033[0;34m\]$ROSPATHNAME\[\033[33m\]$(parse_git_branch)\[\033[0;32m\]@$MASTER\[\033[0m\]:\[\033[0;36m\]\w\[\033[0m\]\[\033[00m\]> '
}
toggle-hostname() {
local PATTERN='^\$\(hostname\) .+$'
if [[ $PS1 =~ $PATTERN ]]; then
export PS1=${PS1#\$(hostname) }
else
export PS1="\$(hostname) $PS1"
fi
}
# Loads child Bash environment with bashrc, prompt, and any start command as a parameter
rosshell() {
F=`mktemp`
echo source ~/.bashrc >> $F
echo "$* || exit 1" >> $F
echo rosprompt >> $F
echo "env | grep ROS_PACKAGE_PATH" >> $F
bash --rcfile $F
}
urdf_display() {
roslaunch urdf_tutorial display.launch gui:=True model:=$1
}
xacro_display() {
rosrun xacro xacro "$1" >"$1.urdf"
roslaunch urdf_tutorial display.launch gui:=True model:="$1.urdf"
}
# ENVIRONMENT AND SOURCING
alias ros=' env | egrep "ROS_.*=|PYTHONPATH|LD_LIBRARY" '
alias melodic='rosshell source /opt/ros/melodic/setup.bash'
alias lunar='rosshell source /opt/ros/lunar/setup.bash'
alias kinetic='rosshell source /opt/ros/kinetic/setup.bash'
alias jade='rosshell source /opt/ros/jade/setup.bash'
alias indigo='rosshell source /opt/ros/indigo/setup.bash'
alias hydro='rosshell source /opt/ros/hydro/setup.bash'
alias groovy='rosshell source /opt/ros/groovy/setup.bash'
alias kinetic='rosshell source /opt/ros/kinetic/setup.bash'
alias lunar='rosshell source /opt/ros/lunar/setup.bash'
alias melodic='rosshell source /opt/ros/melodic/setup.bash'
alias devel='rosshell source devel/setup.bash'
alias install='rosshell source install/setup.bash'
alias rosrefresh='(roscd;cd ..; rospack profile)'
alias catkin_eclipse='(roscd;cd ..; catkin_make --force-cmake -G"Eclipse CDT4 - Unix Makefiles")'
alias install_deps="(roscd;cd ..;rosdep install --from-paths src --ignore-src -y)"
alias pydev='python $(rospack find mk)/make_pydev_project.py'
alias rosdep_indigo='rosdep install -r --from-paths src --ignore-src --rosdistro indigo -y'
alias rosdep_kinetic='rosdep install -r --from-paths src --ignore-src --rosdistro kinetic -y'
alias rosdep_lunar='rosdep install -r --from-paths src --ignore-src --rosdistro lunar -y'
alias rosdep_melodic='rosdep install -r --from-paths src --ignore-src --rosdistro melodic -y'
# SHORTCUTS
alias cm='(roscd && cd ..; catkin_make)'
alias rn='rosnode list'
alias rni='rosnode info'
alias rte='rostopic echo'
alias rtl='rostopic list'
alias rti='rostopic info'
alias gkill='killall gzserver ; killall gzclient ; killall rosout ; pkill -9 -f "python /opt/ros/" '
alias rkill='killall rosout ; pkill -9 -f "python /opt/ros/" ; gkill'
alias make-eclipse-project='cmake -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug'
# Generates debian package from ROS package name
todeb() {
# Get OS name and codename
local OS_VERSION="$(lsb_release -c | cut -f2)"
local OS_NAME="$(lsb_release -i | cut -f2 | tr "[:upper:]" "[:lower:]")"
# Remember current dir
local ORIG_DIR="$(pwd)"
# Create deb dir if necessary and store path
local DEB_DIR="deb"
roscd && cd ..
if [ ! -d "$DEB_DIR" ]; then
mkdir $DEB_DIR
fi
local DEB_DIR="$(cd $DEB_DIR && pwd)"
# Install public deps
rosdep install -i -y $1
# Generate debian package
roscd $1 &&
# Remove old debian and obj-* dirs
rm -rf debian obj-*
# Inject private package key resolutions into rosdep
inject-rosdeps &&
# Generate and build .deb
local EXIT_STATUS=0
bloom-generate rosdebian --os-name $OS_NAME --os-version $OS_VERSION --ros-distro $ROS_DISTRO &&
fakeroot debian/rules binary
if (( $? )); then
local EXIT_STATUS=1
else
LAST_BUILT_PKG=$(basename ../*.deb)
# Stores deb package in deb directory.
mv ../*.deb $DEB_DIR
fi
# Remove rosdep injections
withdraw-rosdeps
# Remove new debian and obj-* dirs
rm -rf debian obj-*
# Return to initial dir for convenience
cd $ORIG_DIR
return $EXIT_STATUS
}
# Inject dependency key resolutions in rosdep for private packages in a catkin workspace
inject-rosdeps() {
# Remember current dir
local ORIG_DIR="$(pwd)"
# Remove any old injections
withdraw-rosdeps
# Get OS name and codename
local OS_VERSION="$(lsb_release -c | cut -f2)"
local OS_NAME="$(lsb_release -i | cut -f2 | tr "[:upper:]" "[:lower:]")"
# Get packages
roscd
cd ..
local PACKS=$(catkin list --quiet -u)
# Go to rosdep sources location
cd /etc/ros/rosdep/sources.list.d/
# Create list file
sudo touch 50-injections.list
echo "yaml file:///etc/ros/rosdep/sources.list.d/injected-keys.yaml" | sudo tee -a 50-injections.list
# Create key resolution yaml
sudo touch injected-keys.yaml
for pack in $PACKS; do
key="ros-${ROS_DISTRO}-$(echo $pack | sed 's/_/-/g')"
echo -e "${pack}:\n $OS_NAME:\n $OS_VERSION: [$key]" | sudo tee -a injected-keys.yaml
done
# Add user-defined keys
roscd
cd ../src/
if [ -e rosdep_keys.yaml ]; then
cat rosdep_keys.yaml | sudo tee -a /etc/ros/rosdep/sources.list.d/injected-keys.yaml
fi
rosdep update
# Return to initial dir for convenience
cd $ORIG_DIR
}
# Remove injected dependencies from rosdep
withdraw-rosdeps() {
# Remember current dir
local ORIG_DIR="$(pwd)"
# Go to rosdep sources location
cd /etc/ros/rosdep/sources.list.d/
# Remote injected files
sudo rm -f 50-injections.list injected-keys.yaml
# Return to initial dir for convenience
cd $ORIG_DIR
}
install-rosbash() {
## Install dependencies for some rosbash functions
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" > /etc/apt/sources.list.d/ros-latest.list'
wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
sudo apt-get update
sudo apt-get install python-catkin-tools python-bloom dpkg-dev debhelper -y
}
# Generate deb files for all private packages in repo; installs them
all-todeb() {
# Remember current dir
local ORIG_DIR="$(pwd)"
roscd && cd ..
rm -rf deb/
local ALL_BUILT=0
local SUCCESS=1
sudo rm -f /run/built_pkgs.txt
sudo touch /run/built_pkgs.txt
# Inject private package key resolutions into rosdep
inject-rosdeps &&
while (( ! $ALL_BUILT )); do
local NUM_BUILT=$(wc -l < /run/built_pkgs.txt)
ALL_BUILT=1
for p in $(catkin list --quiet -u | grep -Fxv -f /run/built_pkgs.txt); do
todeb-noinject $p
if (( $? )); then
ALL_BUILT=0
else
cd deb
sudo dpkg -i $LAST_BUILT_PKG &&
echo $p | sudo tee -a /run/built_pkgs.txt
cd -
fi
done
if [ $NUM_BUILT -eq $(wc -l < /run/built_pkgs.txt) ]; then
echo All packages cannot be built. Ending construction...
SUCCESS=0
break
fi
done
if (( $SUCCESS )); then
echo All packages built and installed successfully.
else
echo The following packages were not built or failed installation:
echo $(catkin list --quiet -u | grep -Fxv -f /run/built_pkgs.txt)
fi
sudo rm /run/built_pkgs.txt
# Remove rosdep injections
withdraw-rosdeps
# Return to initial dir for convenience
cd $ORIG_DIR
}
todeb-noinject() {
# Get OS name and codename
local OS_VERSION="$(lsb_release -c | cut -f2)"
local OS_NAME="$(lsb_release -i | cut -f2 | tr "[:upper:]" "[:lower:]")"
# Remember current dir
local ORIG_DIR="$(pwd)"
# Create deb dir if necessary and store path
local DEB_DIR="deb"
roscd && cd ..
if [ ! -d "$DEB_DIR" ]; then
mkdir $DEB_DIR
fi
local DEB_DIR="$(cd $DEB_DIR && pwd)"
# Install public deps
rosdep install -i $1
# Generate debian package
roscd $1 &&
# Remove old debian and obj-* dirs
rm -rf debian obj-*
# Generate and build .deb
local EXIT_STATUS=0
bloom-generate rosdebian --os-name $OS_NAME --os-version $OS_VERSION --ros-distro $ROS_DISTRO &&
fakeroot debian/rules binary
if (( $? )); then
local EXIT_STATUS=1
else
LAST_BUILT_PKG=$(basename ../*.deb)
# Stores deb package in deb directory.
mv ../*.deb $DEB_DIR
fi
# Remove new debian and obj-* dirs
rm -rf debian obj-*
# Return to initial dir for convenience
cd $ORIG_DIR
return $EXIT_STATUS
}