blob: 06f7478c93eba49ad11169763ebcd145a253c32b (
plain)
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
|
#!/bin/bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2026 Open-IOV contributors
# push_gl_tools.sh - push the guest-side GL/GZDoom harness binaries and scripts
# into the running guest's /tmp and chmod +x them. Uses the established QGA
# guest-exec + base64 mechanism from push_guest_tools.sh (scripts/vgpu_vm.py).
#
# Usage:
# bash tools/guest-diag/push_gl_tools.sh # fixed list below
# bash tools/guest-diag/push_gl_tools.sh FILE... # arbitrary host files
# bash tools/guest-diag/push_gl_tools.sh --dry-run # list only, no push
#
# Destination is /tmp/<basename>. The guest's /tmp is wiped on boot; run this
# after every VM start. It does NOT run the pushed programs.
set -u
HERE="$(cd "$(dirname "$0")" && pwd)"
VMEXEC="$HERE/../../scripts/vgpu_vm.py"
BUILD="$HERE/build"
DEST_DIR="${DEST_DIR:-/tmp}"
DRY_RUN=0
if [ "${1:-}" = "--dry-run" ]; then
DRY_RUN=1
shift
fi
# gz_es.so is small and its source is tracked; build it on demand (host gcc,
# same libc family as the guest) so the GZ_EGL=1 path works from a fresh
# checkout. The other shims stay prebuilt in build/.
if [ ! -f "$BUILD/gz_es.so" ] && [ "$DRY_RUN" != "1" ]; then
mkdir -p "$BUILD"
if gcc -shared -fPIC -O2 -o "$BUILD/gz_es.so" "$HERE/gz_es.c" \
-lEGL -lGLESv2 -ldl; then
echo "BUILD $BUILD/gz_es.so"
else
echo "BUILD-FAIL gz_es.so (EGL/GLESv2 dev headers needed)" >&2
fi
fi
# gz_view displays the shim's published frames in an X11 window on the
# guest desktop (capture surface for the real-NVIDIA GZDoom run).
if [ ! -f "$BUILD/gz_view" ] && [ "$DRY_RUN" != "1" ]; then
mkdir -p "$BUILD"
if gcc -O2 -o "$BUILD/gz_view" "$HERE/gz_view.c" -lX11; then
echo "BUILD $BUILD/gz_view"
else
echo "BUILD-FAIL gz_view (X11 dev headers needed)" >&2
fi
fi
FIXED=(
"$BUILD/gl_frames"
"$BUILD/gz_pbuf.so"
"$BUILD/gz_es.so"
"$BUILD/gz_view"
"$BUILD/sdl_cap.so"
"$BUILD/test_tri"
"$HERE/guest_mode.sh"
"$HERE/gzf2_video.py"
"$HERE/gzdoom_pbuf_run.sh"
"$HERE/mission-gz.sh"
"$HERE/10_nvidia.json"
)
if [ "$#" -gt 0 ]; then
FILES=("$@")
else
FILES=("${FIXED[@]}")
fi
if [ ! -x "$VMEXEC" ] && [ ! -f "$VMEXEC" ]; then
echo "push_gl_tools: vgpu_vm.py not found: $VMEXEC" >&2
exit 2
fi
push_b64() { # push_b64 <local file> <remote file>
local src="$1" dst="$2" b64
b64=$(base64 -w0 "$src")
if [ "$DRY_RUN" = "1" ]; then
echo "PUSH-DRY $src -> $dst ($(stat -c%s "$src") bytes)"
return 0
fi
if ! sudo "$VMEXEC" exec --timeout 120 \
"echo '$b64' | base64 -d > '$dst' && chmod +x '$dst'" \
>/dev/null 2>&1; then
echo "PUSH-FAIL $src -> $dst" >&2
return 1
fi
echo "PUSHED $src -> $dst"
}
rc=0
for f in "${FILES[@]}"; do
if [ ! -f "$f" ]; then
echo "PUSH-SKIP missing $f" >&2
rc=1
continue
fi
push_b64 "$f" "$DEST_DIR/$(basename "$f")" || rc=1
done
# The EGL offscreen path (GZ_EGL=1) needs the NVIDIA EGL vendor ICD; some
# guest images lack it. Create it only when missing (never overwrite the
# driver's own file).
EGL_JSON=/usr/share/glvnd/egl_vendor.d/10_nvidia.json
if [ "$DRY_RUN" = "1" ]; then
echo "PUSH-DRY $EGL_JSON (if missing)"
elif sudo "$VMEXEC" exec --timeout 30 "test -f $EGL_JSON" >/dev/null 2>&1; then
echo "PUSH-SKIP existing $EGL_JSON"
elif sudo "$VMEXEC" exec --timeout 30 \
"mkdir -p /usr/share/glvnd/egl_vendor.d && cp '$DEST_DIR/10_nvidia.json' '$EGL_JSON'" \
>/dev/null 2>&1; then
echo "PUSHED $EGL_JSON"
else
echo "PUSH-FAIL $EGL_JSON" >&2
rc=1
fi
exit "$rc"
|