Skip to content

Commit 56f906f

Browse files
christoph-zededaeriknordmark
authored andcommitted
pkg/debug: fix spec.sh to print valid json
`print_usb_devices` now uses the `$COMMA` mechanism to add a comma after every device Signed-off-by: Christoph Ostarek <christoph@zededa.com>
1 parent c7ced58 commit 56f906f

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

pkg/debug/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
120120
# Ensure that the output of spec.sh is valid json
121121
RUN ./usr/bin/spec.sh -v 2>/dev/null | jq . > /dev/null
122122
RUN ./usr/bin/spec.sh 2>/dev/null | jq . > /dev/null
123+
RUN mkdir /tmp/bin
124+
COPY tests/lsusb /tmp/bin
125+
RUN chmod a+x /tmp/bin/lsusb
126+
RUN PATH=/tmp/bin:$PATH /out/usr/bin/spec.sh -u 2>/dev/null | jq .
123127

124128
RUN mkdir -p ./etc/ssh ./root/.ssh
125129
RUN chmod 0700 ./root/.ssh

pkg/debug/spec.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ print_usb_devices() {
383383
fi
384384

385385
cat <<__EOT__
386+
${COMMA}
386387
{
387388
"ztype": "${ztype}",
388389
"phylabel": "${label}",
@@ -395,8 +396,8 @@ print_usb_devices() {
395396
},
396397
"logicallabel": "$label",
397398
"usagePolicy": {}
398-
},
399399
__EOT__
400+
COMMA="},"
400401
done
401402
}
402403

pkg/debug/tests/lsusb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
# Copyright (c) 2026 Zededa, Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
echo "Bus 001 Device 001: ID 1d6b:0002 Linux 6.12.49-linuxkit-core-ef7ccc4d151c xhci-hcd xHCI Host Controller"
7+
echo "Bus 002 Device 002: ID 46f4:0001 QEMU QEMU USB HARDDRIVE"
8+
echo "Bus 002 Device 001: ID 1d6b:0003 Linux 6.12.49-linuxkit-core-ef7ccc4d151c xhci-hcd xHCI Host Controller"

0 commit comments

Comments
 (0)