-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrosbash.bash
242 lines (213 loc) · 7.42 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
#!/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;37m\]$(hostname) \[\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='\[\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\]> '
else
export PS1='\[\033[0;31m\]${ROS_DISTRO[@]:0:1} \[\033[0;37m\]$(hostname) \[\033[0;34m\]$ROSPATHNAME\[\033[33m\]$(parse_git_branch)\[\033[0;32m\]@$MASTER\[\033[0m\]:\[\033[0;36m\]\w\[\033[0m\]\[\033[00m\]> '
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" '
ROS_DISTRIBUTIONS="groovy hydro indigo jade kinetic lunac melodic"
for dist in $ROS_DISTRIBUTIONS
do
alias $dist="rosshell source /opt/ros/$dist/setup.bash"
alias rosdep_$dist="rosdep install -r --from-paths src --ignore-src --rosdistro $dist -y"
done
alias devel='rosshell source devel/setup.bash'
alias install='rosshell source install/setup.bash'
alias rosrefresh='(roscd;cd ..; rospack profile)'
alias install_deps="(roscd;cd ..;rosdep install --from-paths src --ignore-src)"
alias catkin_eclipse='(roscd;cd ..; catkin_make --force-cmake -G"Eclipse CDT4 - Unix Makefiles")'
alias make-eclipse-project='cmake -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug'
alias pydev='python $(rospack find mk)/make_pydev_project.py'
# 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'
# 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 $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
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
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 $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
# Return to initial dir for convenience
cd $ORIG_DIR
}