-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.sh
executable file
·106 lines (93 loc) · 2.93 KB
/
dev.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
#!/bin/bash
# ----------------------------------------------------------------
# Build docker dev stage and add local code for live development
# ----------------------------------------------------------------
CYCLONE_VOL=""
# Default cyclone_dds.xml path
CYCLONE_DIR=/home/$USER/cyclone_dds.xml
# Default in-vehicle rosbags directory
ROSBAGS_DIR=/recorded_datasets/edinburgh
# Default value for headless
headless=false
# Function to print usage
usage() {
echo "
Usage: dev.sh [-l|--local] [--path | -p ] [--headless] [--help | -h]
Options:
-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
--headless Run the Docker image without X11 forwarding
-h | --help Display this help message and exit.
"
exit 1
}
# Parse command-line options
while [[ "$#" -gt 0 ]]; do
case $1 in
-l|--local)
if [[ -n "$2" && "$2" != -* ]]; then
CYCLONE_DIR="$2"
shift
fi
CYCLONE_VOL="-v $CYCLONE_DIR:/opt/ros_ws/cyclone_dds.xml"
;;
-p|--path)
if [[ -n "$2" && "$2" != -* ]]; then
ROSBAGS_DIR="$2"
shift
else
echo "Error: Argument for $1 is missing."
usage
fi
;;
--headless) headless=true ;;
-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" ]; then
echo "$ROSBAGS_DIR does not exist! Please provide a valid path to store rosbags"
exit 1
fi
MOUNT_X=""
if [ "$headless" = "false" ]; then
MOUNT_X="-e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix"
xhost + >/dev/null
fi
# Build docker image up to dev stage
docker build \
--build-arg USER_ID=$(id -u) \
--build-arg GROUP_ID=$(id -g) \
--build-arg USERNAME=$(whoami) \
-t av_tools:latest-dev \
-f Dockerfile --target dev .
# Get the absolute path of the script
SCRIPT_DIR=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
# Run docker image with local code volumes for development
docker run -it --rm --net host --privileged \
--user "$(id -u):$(id -g)" \
${MOUNT_X} \
-e XAUTHORITY="${XAUTHORITY}" \
-e XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" \
-v /dev:/dev \
-v /tmp:/tmp \
$CYCLONE_VOL \
-v $ROSBAGS_DIR:/opt/ros_ws/rosbags \
-v $SCRIPT_DIR/scripts/container_tools:/opt/ros_ws/container_tools \
-v $SCRIPT_DIR/config:/opt/ros_ws/config \
-v /etc/localtime:/etc/localtime:ro \
av_tools:latest-dev