-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_docker_gui.sh
More file actions
executable file
·180 lines (161 loc) · 6.03 KB
/
Copy pathrun_docker_gui.sh
File metadata and controls
executable file
·180 lines (161 loc) · 6.03 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
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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
IMAGE_NAME=${OPENHDMAP_DOCKER_IMAGE:-openhdmap:22.04}
SMOKE_TEST=0
GUI_USER=${SUDO_USER:-$USER}
GUI_UID=$(id -u "$GUI_USER")
GUI_HOME=$HOME
if [[ -n "${SUDO_USER:-}" ]]; then
GUI_HOME=$(getent passwd "$GUI_USER" | cut -d: -f6)
fi
CONFIG_DIR=${OPENHDMAP_CONFIG_DIR:-"$GUI_HOME/.config/openHDMap-docker"}
DATA_DIR=${OPENHDMAP_DATA_DIR:-"$GUI_HOME/openHDMap-data"}
HOST_DISPLAY=${DISPLAY:-}
HOST_XAUTHORITY=${XAUTHORITY:-}
DOCKER_XAUTH_ARGS=()
DOCKER_XAUTH_FILE=
if [[ "${1:-}" == "--smoke-test" ]]; then
SMOKE_TEST=1
fi
mkdir -p "$CONFIG_DIR"
mkdir -p "$DATA_DIR"
if [[ -z "$HOST_XAUTHORITY" ]]; then
if [[ -f "/run/user/$GUI_UID/gdm/Xauthority" ]]; then
HOST_XAUTHORITY="/run/user/$GUI_UID/gdm/Xauthority"
elif [[ -f "/home/$GUI_USER/.Xauthority" ]]; then
HOST_XAUTHORITY="/home/$GUI_USER/.Xauthority"
fi
fi
if ! docker image inspect "$IMAGE_NAME" >/dev/null 2>&1; then
echo "Docker image $IMAGE_NAME missing, building it now"
docker build -f "$SCRIPT_DIR/Dockerfile.22.04" -t "$IMAGE_NAME" "$SCRIPT_DIR"
fi
if [[ $SMOKE_TEST -eq 1 ]]; then
echo "Running Docker smoke test via virtual framebuffer"
exec docker run --rm \
--name openhdmap-smoke \
-e QTWEBENGINE_DISABLE_SANDBOX=1 \
-e QTWEBENGINE_CHROMIUM_FLAGS="--disable-gpu --disable-software-rasterizer --no-sandbox" \
-e XDG_RUNTIME_DIR=/tmp/runtime-root \
-v "$CONFIG_DIR:/root/.config/openHDMap" \
-v "$DATA_DIR:/root/openHDMap" \
--security-opt seccomp=unconfined \
--shm-size=1gb \
-w /app/build \
"$IMAGE_NAME" \
bash -lc 'mkdir -p /tmp/runtime-root && chmod 700 /tmp/runtime-root && timeout 20s xvfb-run -a -s "-screen 0 1280x800x24" ./openHDMap >/tmp/openhdmap-smoke.log 2>&1; status=$?; cat /tmp/openhdmap-smoke.log; [[ $status -eq 0 || $status -eq 124 ]]'
fi
if [[ -z "$HOST_DISPLAY" ]]; then
echo "DISPLAY is not set. Use ./run_docker_gui.sh --smoke-test or ./run_docker_virtual.sh"
exit 1
fi
if ! command -v xhost >/dev/null 2>&1; then
echo "xhost is required for GUI Docker runs"
exit 1
fi
run_gui_user_command() {
if [[ -n "${SUDO_USER:-}" ]]; then
sudo -u "$GUI_USER" env DISPLAY="$HOST_DISPLAY" XAUTHORITY="$HOST_XAUTHORITY" "$@"
return
fi
env DISPLAY="$HOST_DISPLAY" XAUTHORITY="$HOST_XAUTHORITY" "$@"
}
if [[ -n "$HOST_XAUTHORITY" && -f "$HOST_XAUTHORITY" ]]; then
DOCKER_XAUTH_FILE=$(mktemp /tmp/openhdmap-docker-xauth-XXXXXX)
touch "$DOCKER_XAUTH_FILE"
chmod 600 "$DOCKER_XAUTH_FILE"
if run_gui_user_command xauth nlist "$HOST_DISPLAY" | sed 's/^..../ffff/' | xauth -f "$DOCKER_XAUTH_FILE" nmerge -; then
DOCKER_XAUTH_ARGS=(-e XAUTHORITY=/tmp/.docker.xauth -v "$DOCKER_XAUTH_FILE:/tmp/.docker.xauth:ro")
else
rm -f "$DOCKER_XAUTH_FILE"
DOCKER_XAUTH_FILE=
echo "Warning: failed to export Xauthority cookie, falling back to xhost-only access"
fi
fi
cleanup() {
if [[ -n "$HOST_XAUTHORITY" && -f "$HOST_XAUTHORITY" ]]; then
run_gui_user_command xhost -SI:localuser:root >/dev/null 2>&1 || true
else
env DISPLAY="$HOST_DISPLAY" xhost -SI:localuser:root >/dev/null 2>&1 || true
fi
env DISPLAY="$HOST_DISPLAY" xhost -local: >/dev/null 2>&1 || true
[[ -n "$DOCKER_XAUTH_FILE" ]] && rm -f "$DOCKER_XAUTH_FILE"
}
trap cleanup EXIT
if [[ -n "$HOST_XAUTHORITY" && -f "$HOST_XAUTHORITY" ]]; then
run_gui_user_command xhost +SI:localuser:root >/dev/null
else
echo "Warning: XAUTHORITY not found, falling back to xhost-only access"
env DISPLAY="$HOST_DISPLAY" xhost +SI:localuser:root >/dev/null
fi
env DISPLAY="$HOST_DISPLAY" xhost +local: >/dev/null
echo "Starting openHDMap in Docker with host X11 for interactive use"
exec docker run --rm -it \
--name openhdmap-gui \
--network=host \
-e DISPLAY="$HOST_DISPLAY" \
-e QT_X11_NO_MITSHM=1 \
-e QTWEBENGINE_DISABLE_SANDBOX=1 \
-e QT_QPA_PLATFORM=xcb \
-e QT_AUTO_SCREEN_SCALE_FACTOR=0 \
-e QT_SCALE_FACTOR=1 \
-e QT_SCREEN_SCALE_FACTORS=1 \
-e QT_LOGGING_RULES="${QT_LOGGING_RULES:-}" \
-e XDG_RUNTIME_DIR=/tmp/runtime-root \
-e QTWEBENGINE_CHROMIUM_FLAGS="--disable-gpu --disable-gpu-sandbox --disable-software-rasterizer --no-sandbox" \
-v /tmp/.X11-unix:/tmp/.X11-unix:rw \
-v "$CONFIG_DIR:/root/.config/openHDMap" \
-v "$DATA_DIR:/root/openHDMap" \
"${DOCKER_XAUTH_ARGS[@]}" \
--device /dev/dri \
--security-opt seccomp=unconfined \
--shm-size=1gb \
-w /app/build \
"$IMAGE_NAME" \
bash -lc '
mkdir -p /root/.config/openHDMap /tmp/runtime-root /root/openHDMap
chmod 700 /tmp/runtime-root
cat > /root/.config/openHDMap/openHDMap.ini <<EOF
[%General]
defaultsVersion=4
workingDir=/root/openHDMap
[plugins]
PointCloudExportPlugin\surfaceSampling=false
PointCloudExportPlugin\voxelSize=1
[terrain]
batchSize=20
[vegetation]
classification=20
dbscan_enabled=true
dbscan_eps=2.0
dbscan_min_points=10
delaunay_alpha=1.5
delaunay_offset=2.5
delaunay_tolerance=0.001
max_intensity=65535
max_returns=10
min_intensity=30
min_returns=3
[workerPool]
maxThreads=8
EOF
if command -v xdpyinfo >/dev/null 2>&1; then
if ! xdpyinfo >/tmp/openhdmap-x11.log 2>&1; then
if [[ "$DISPLAY" == :* ]]; then
alt_display="unix${DISPLAY}"
DISPLAY="$alt_display" xdpyinfo >/tmp/openhdmap-x11.log 2>&1 && export DISPLAY="$alt_display"
fi
fi
if ! grep -q "name of display" /tmp/openhdmap-x11.log 2>/dev/null; then
echo "X11 preflight failed"
echo "DISPLAY=$DISPLAY"
ls -l /tmp/.X11-unix || true
ls -l /tmp/.docker.xauth || true
xauth -f /tmp/.docker.xauth list || true
cat /tmp/openhdmap-x11.log
exit 1
fi
fi
./openHDMap
'