-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathros.sh
More file actions
executable file
·153 lines (138 loc) · 4.37 KB
/
ros.sh
File metadata and controls
executable file
·153 lines (138 loc) · 4.37 KB
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
#!/bin/bash
export UID=$(id -u)
export GID=$(id -g)
imageTag=ros:kinetic_darknet #as described at the docker-build-process
imageName=ros_perception_docker #name of the Docker-container
isRunning="$(docker inspect -f '{{.State.Running}}' $imageName)" > /dev/null 2>&1 #suppress console output
imageStatus="$(docker inspect -f '{{.State.Status}}' $imageName)" > /dev/null 2>&1
detectMaster="$(docker inspect -f '{{.State.Running}}' ros_kinetic_master)" > /dev/null 2>&1
if [ $detectMaster ]
then
read -p "Rosmaster detected. Would you like to connect to ROS-Network (y/n)? " answer
case ${answer:0:1} in
y|Y )
#Start with ROS-Network
if [ ! $isRunning ]
then
echo "Starting new container..."
sudo docker run \
-it \
--gpus all \
--name=$imageName \
--net ros_network \
--user=$UID:$GID \
--env ROS_HOSTNAME=$imageName \
--env ROS_MASTER_URI=http://ros_kinetic_master:11311 \
--env DISPLAY=$DISPLAY \
--env="QT_X11_NO_MITSHM=1" \
--volume="/etc/group:/etc/group:ro" \
--volume="/etc/passwd:/etc/passwd:ro" \
--volume="/etc/shadow:/etc/shadow:ro" \
--volume="/etc/sudoers.d:/etc/sudoers.d:ro" \
--volume="/home/$USER/.ros:/home/$USER/.ros:rw" \
--volume="/home/$USER/.bashrc:/home/$USER/.bashrc:ro" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
--device="/dev/video0:/dev/video0" \
--volume="/home/$USER/Object_detection/weights:/home/$USER/darknet/weights:ro" \
--volume="/home/$USER/Object_detection/darknet_konsti:/home/$USER/Object_detection/darknet_konsti:ro" \
--workdir="/home/$USER/catkin_ws" \
$imageTag
fi
;;
* )
#Start Container without ROS-Network
if [ ! $isRunning ]
then
echo "Starting new container with roscore in background"
echo "Please kill docker container after use"
sudo docker run \
-d \
--gpus all \
--name=$imageName \
--user=$UID:$GID \
--env DISPLAY=$DISPLAY \
--env="QT_X11_NO_MITSHM=1" \
--volume="/etc/group:/etc/group:ro" \
--volume="/etc/passwd:/etc/passwd:ro" \
--volume="/etc/shadow:/etc/shadow:ro" \
--volume="/etc/sudoers.d:/etc/sudoers.d:ro" \
--volume="/home/$USER/.ros:/home/$USER/.ros:rw" \
--volume="/home/$USER/.bashrc:/home/$USER/.bashrc:ro" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
--device="/dev/video0:/dev/video0" \
--volume="/home/$USER/Object_detection/weights:/home/$USER/darknet/weights:ro" \
--volume="/home/$USER/Object_detection/darknet_konsti:/home/$USER/Object_detection/darknet_konsti:ro" \
--workdir="/home/$USER/catkin_ws" \
$imageTag \
/bin/bash -c "catkin_make -DCMAKE_BUILD_TYPE=Release; roscore"
echo "Starting interactive terminal..."
xhost +
sudo docker exec \
-it \
$imageName \
bash
xhost -
fi
;;
esac
if [ "$imageStatus" == "exited" ]
then
xhost +
sudo docker start \
$imageName
xhost -
else
xhost +
sudo docker exec \
-it \
$imageName \
bash
xhost -
fi
else #if Master is not detected -> just launch container as usual
if [ ! $isRunning ]
then
echo "Starting new container with roscore in background"
echo "Please kill docker container after use"
sudo docker run \
-d \
--gpus all \
--name=$imageName \
--user=$UID:$GID \
--env DISPLAY=$DISPLAY \
--env="QT_X11_NO_MITSHM=1" \
--volume="/etc/group:/etc/group:ro" \
--volume="/etc/passwd:/etc/passwd:ro" \
--volume="/etc/shadow:/etc/shadow:ro" \
--volume="/etc/sudoers.d:/etc/sudoers.d:ro" \
--volume="/home/$USER/.ros:/home/$USER/.ros:rw" \
--volume="/home/$USER/.bashrc:/home/$USER/.bashrc:ro" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
--device="/dev/video0:/dev/video0" \
--volume="/home/$USER/Object_detection/weights:/home/$USER/darknet/weights:ro" \
--volume="/home/$USER/Object_detection/darknet_konsti:/home/$USER/Object_detection/darknet_konsti:ro" \
--workdir="/home/$USER/catkin_ws" \
$imageTag \
/bin/bash -c "catkin_make -DCMAKE_BUILD_TYPE=Release; roscore"
echo "Starting interactive terminal..."
xhost +
sudo docker exec \
-it \
$imageName \
bash
xhost -
elif [ "$imageStatus" == "exited" ]
then
xhost +
sudo docker start \
$imageName
xhost -
else
xhost +
sudo docker exec \
-it \
$imageName \
bash
xhost -
fi
fi