-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime.sh
executable file
·101 lines (91 loc) · 2.78 KB
/
runtime.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
#!/bin/bash
# ---------------------------------------------------------------------------
# Build docker image and run ROS code for runtime or interactively with bash
# ---------------------------------------------------------------------------
CYCLONE_VOL=""
BASH_CMD=""
# Default cyclone_dds.xml path
CYCLONE_DIR=/home/$USER/cyclone_dds.xml
# Default in-vehicle rosbags directory
ROSBAGS_DIR=/recorded_datasets/edinburgh
CHECK_PATH=true
# Function to print usage
usage() {
echo "
Usage: runtime.sh [-b|bash] [-l|--local] [--path | -p ] [--help | -h]
Options:
-b | bash Open bash in docker container
-f | --foxglove Run Foxglove bridge instead of recording a bag
-l | --local Use default local cyclone_dds.xml config
Optionally point to absolute -l /path/to/cyclone_dds.xml
-p | --path ROSBAGS_DIR_PATH
Specify path to store recorded rosbags
-h | --help Display this help message and exit.
"
exit 1
}
# Parse command-line options
while [[ "$#" -gt 0 ]]; do
case $1 in
-b|bash)
BASH_CMD=bash
;;
# Option to specify path
-l|--local)
if [[ -n "$2" && "$2" != -* && "$2" != "bash" ]]; then
CYCLONE_DIR="$2"
shift
fi
CYCLONE_VOL="-v $CYCLONE_DIR:/opt/ros_ws/cyclone_dds.xml"
;;
-f|--foxglove)
BASH_CMD=/opt/ros_ws/container_tools/foxglove_bridge.sh
CHECK_PATH=false
;;
-p|--path)
if [[ -n "$2" && "$2" != -* ]]; then
ROSBAGS_DIR="$2"
shift
else
echo "Error: Argument for $1 is missing."
usage
fi
;;
-h|--help)
usage
;;
*)
echo "Unknown option: $1"
usage
;;
esac
shift
done
# Verify CYCLONE_DIR exists
if [ -n "$CYCLONE_VOL" ]; then
if [ ! -f "$CYCLONE_DIR" ]; then
echo "$CYCLONE_DIR does not exist! Please provide a valid path to cyclone_dds.xml"
exit 1
fi
fi
# Verify ROSBAGS_DIR exists
if [ ! -d "$ROSBAGS_DIR" -a "$CHECK_PATH" = true ]; then
echo "$ROSBAGS_DIR does not exist! Please provide a valid path to store rosbags"
exit 1
fi
# Build docker image only up to runtime stage
docker build \
--build-arg USER_ID=$(id -u) \
--build-arg GROUP_ID=$(id -g) \
--build-arg USERNAME=$(whoami) \
-t av_tools:latest \
-f Dockerfile --target runtime .
# Run docker image
docker run -it --rm --net host --privileged \
--user "$(id -u):$(id -g)" \
-v /dev:/dev \
-v /tmp:/tmp \
$CYCLONE_VOL \
-v $ROSBAGS_DIR:/opt/ros_ws/rosbags \
-v /etc/localtime:/etc/localtime:ro \
av_tools:latest $BASH_CMD