-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathdeb-install-test.sh
More file actions
executable file
·270 lines (222 loc) · 11.1 KB
/
deb-install-test.sh
File metadata and controls
executable file
·270 lines (222 loc) · 11.1 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
# ──────────────────────────────────────────────────────────────────────────────
# DEB Package Installation Test for Devolutions Gateway
#
# Runs inside an Ubuntu container to validate:
# - Package installs correctly via dpkg/apt
# - Expected files and directories are present
# - Binary is functional (--help, --config-init-only)
# - systemd unit file is installed (part of the .deb package)
# - Default configuration file is generated
#
# LIMITATION — systemd in containers:
# Docker containers do not normally run systemd, so the postinst script
# skips config initialization and service enablement (both gated on
# /run/systemd/system). This script compensates by running
# --config-init-only manually. Full service start/stop validation is
# best-effort and only attempted when systemd is detected.
# ──────────────────────────────────────────────────────────────────────────────
set -euo pipefail
# ── Test bookkeeping ─────────────────────────────────────────────────────────
TESTS_PASSED=0
TESTS_FAILED=0
pass() {
echo "✅ PASS: $1"
TESTS_PASSED=$((TESTS_PASSED + 1))
}
fail() {
echo "❌ FAIL: $1"
TESTS_FAILED=$((TESTS_FAILED + 1))
}
info() {
echo "ℹ️ $1"
}
warn() {
echo "⚠️ WARN: $1"
}
diagnostics() {
echo ""
echo "── Diagnostics ──────────────────────────────────────────────"
echo ""
echo "Package metadata:"
dpkg -s "$PACKAGE_NAME" 2>/dev/null || echo " (not installed)"
echo ""
echo "Package file list:"
dpkg -L "$PACKAGE_NAME" 2>/dev/null || echo " (not installed)"
echo ""
echo "Config directory:"
ls -la /etc/devolutions-gateway/ 2>/dev/null || echo " (not found)"
echo ""
echo "Binary info:"
ls -la /usr/bin/devolutions-gateway 2>/dev/null || echo " (not found)"
file /usr/bin/devolutions-gateway 2>/dev/null || true
echo ""
echo "Webapp directory:"
ls -laR /usr/share/devolutions-gateway/webapp/ 2>/dev/null | head -40 || echo " (not found)"
echo ""
echo "Library directory:"
ls -la /usr/lib/devolutions-gateway/ 2>/dev/null || echo " (not found)"
echo ""
echo "systemd unit files:"
find /lib/systemd /usr/lib/systemd /etc/systemd -name '*devolutions*' 2>/dev/null || echo " (none found)"
echo "────────────────────────────────────────────────────────────"
}
summary() {
echo ""
echo "════════════════════════════════════════════════════════════════"
echo " Test Summary: $TESTS_PASSED passed, $TESTS_FAILED failed"
echo "════════════════════════════════════════════════════════════════"
if [ "$TESTS_FAILED" -gt 0 ]; then
exit 1
fi
}
# ── Validate environment ─────────────────────────────────────────────────────
: "${PACKAGE_FILE:?PACKAGE_FILE must be set}"
: "${VERSION:?VERSION must be set}"
: "${PACKAGE_NAME:?PACKAGE_NAME must be set}"
echo "════════════════════════════════════════════════════════════════"
echo " DEB Package Installation Test"
echo " Package: $(basename "$PACKAGE_FILE")"
echo " Version: $VERSION"
echo " Container: $(cat /etc/os-release 2>/dev/null | grep PRETTY_NAME | cut -d= -f2 | tr -d '\"')"
echo "════════════════════════════════════════════════════════════════"
echo ""
# ── Install the package ──────────────────────────────────────────────────────
info "Updating apt and installing prerequisites…"
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
apt-get install -y -qq file > /dev/null 2>&1
info "Installing package: $(basename "$PACKAGE_FILE")"
# Use apt-get install with the .deb path; this resolves dependencies
# automatically. Show output only on failure.
INSTALL_LOG=$(mktemp)
if apt-get install -y "$PACKAGE_FILE" > "$INSTALL_LOG" 2>&1; then
pass "Package installation succeeded"
else
echo "Installation output:"
cat "$INSTALL_LOG"
fail "Package installation failed"
diagnostics
summary
fi
rm -f "$INSTALL_LOG"
# ── Package metadata ─────────────────────────────────────────────────────────
info "Checking package metadata…"
if dpkg -s "$PACKAGE_NAME" > /dev/null 2>&1; then
pass "Package is registered in dpkg database"
else
fail "Package not found in dpkg database"
fi
INSTALLED_VERSION=$(dpkg -s "$PACKAGE_NAME" 2>/dev/null | grep '^Version:' | awk '{print $2}')
if echo "$INSTALLED_VERSION" | grep -q "$VERSION"; then
pass "Installed version ($INSTALLED_VERSION) contains expected version ($VERSION)"
else
fail "Version mismatch: installed=$INSTALLED_VERSION expected contains=$VERSION"
fi
# ── File existence checks ────────────────────────────────────────────────────
info "Checking expected files and directories…"
# Main binary.
if [ -x /usr/bin/devolutions-gateway ]; then
pass "Main binary exists and is executable: /usr/bin/devolutions-gateway"
else
fail "Main binary missing or not executable: /usr/bin/devolutions-gateway"
fi
# Native library.
if [ -f /usr/lib/devolutions-gateway/libxmf.so ]; then
pass "Native library exists: /usr/lib/devolutions-gateway/libxmf.so"
else
fail "Native library missing: /usr/lib/devolutions-gateway/libxmf.so"
fi
# Webapp directory.
if [ -d /usr/share/devolutions-gateway/webapp ]; then
pass "Webapp directory exists: /usr/share/devolutions-gateway/webapp/"
else
fail "Webapp directory missing: /usr/share/devolutions-gateway/webapp/"
fi
# Webapp client — expect at least an index.html.
if find /usr/share/devolutions-gateway/webapp/client -name 'index.html' 2>/dev/null | grep -q .; then
pass "Webapp client contains index.html"
else
fail "Webapp client missing index.html"
fi
# Config directory (the postinst creates this unconditionally).
if [ -d /etc/devolutions-gateway ]; then
pass "Config directory exists: /etc/devolutions-gateway/"
else
fail "Config directory missing: /etc/devolutions-gateway/"
fi
# ── systemd unit file ────────────────────────────────────────────────────────
# The .deb package installs the unit file via dh_installsystemd,
# so it should be present regardless of whether systemd is running.
info "Checking systemd unit file…"
UNIT_FILE=""
for path in \
/lib/systemd/system/devolutions-gateway.service \
/usr/lib/systemd/system/devolutions-gateway.service; do
if [ -f "$path" ]; then
UNIT_FILE="$path"
break
fi
done
if [ -n "$UNIT_FILE" ]; then
pass "systemd unit file installed: $UNIT_FILE"
if grep -q '/usr/bin/devolutions-gateway' "$UNIT_FILE"; then
pass "Unit file references correct binary path"
else
fail "Unit file does not reference /usr/bin/devolutions-gateway"
fi
else
fail "systemd unit file not found in expected locations"
fi
# ── Binary functionality ─────────────────────────────────────────────────────
info "Checking binary functionality…"
HELP_OUTPUT=$(/usr/bin/devolutions-gateway --help 2>&1) && HELP_RC=$? || HELP_RC=$?
if [ "$HELP_RC" -eq 0 ] || echo "$HELP_OUTPUT" | grep -qi 'gateway\|usage\|help'; then
pass "Binary responds to --help"
else
fail "Binary does not respond to --help (exit code: $HELP_RC)"
fi
# ── Config initialization ────────────────────────────────────────────────────
# The postinst runs --config-init-only only when systemd is present.
# In a container without systemd we run it manually.
info "Checking config initialization…"
if [ ! -f /etc/devolutions-gateway/gateway.json ]; then
info "Config file not generated by postinst (expected without systemd)."
info "Running config initialization manually…"
if /usr/bin/devolutions-gateway --config-init-only > /dev/null 2>&1; then
pass "Config initialization command succeeded"
else
fail "Config initialization command failed"
fi
fi
if [ -f /etc/devolutions-gateway/gateway.json ]; then
pass "Default config file exists: /etc/devolutions-gateway/gateway.json"
else
fail "Default config file missing after initialization: /etc/devolutions-gateway/gateway.json"
fi
# ── Package file list completeness ───────────────────────────────────────────
info "Checking package file list completeness…"
FILE_COUNT=$(dpkg -L "$PACKAGE_NAME" | wc -l)
if [ "$FILE_COUNT" -gt 5 ]; then
pass "Package file list contains $FILE_COUNT entries"
else
fail "Package file list suspiciously small ($FILE_COUNT entries)"
fi
# ── Best-effort: service startup ─────────────────────────────────────────────
info "[Best-effort] Checking service startup…"
warn "systemd service startup testing is best-effort in containers."
warn "Full service validation requires a real systemd environment."
if [ -d /run/systemd/system ]; then
info "systemd detected; attempting service start…"
if systemctl start devolutions-gateway 2>&1; then
pass "[Best-effort] Service started successfully"
systemctl status devolutions-gateway 2>&1 || true
else
warn "Service start failed (expected in some container environments)."
fi
else
info "No systemd detected; skipping service startup test."
fi
# ── Final output ─────────────────────────────────────────────────────────────
diagnostics
summary