From 9ac77be9ebb20bdfd485a09642372a70e8d88c64 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Fri, 8 Nov 2024 09:58:31 +0100 Subject: [PATCH] confd: fix scary error message on systems without USB ports Check if the "usb-ports" key exists in /run/system.json before calling jq, otherise we get the following error message: Nov 8 05:11:45 ix bootstrap[3349]: jq: error (at :0): Cannot iterate over null (null) Also, minor whitespace cleanup and bashisms fixes. Signed-off-by: Joachim Wiberg --- src/confd/bin/gen-hardware | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/confd/bin/gen-hardware b/src/confd/bin/gen-hardware index aeff1e48..eec613d3 100755 --- a/src/confd/bin/gen-hardware +++ b/src/confd/bin/gen-hardware @@ -1,19 +1,23 @@ #!/bin/sh set -e -usb_ports=$(cat /run/system.json | jq -r '.["usb-ports"] | map(.name) | unique | join(" ")') +if jq -e '.["usb-ports"]' /run/system.json > /dev/null; then + usb_ports=$(jq -r '.["usb-ports"] | map(.name) | unique | join(" ")' /run/system.json) +else + usb_ports="" +fi gen_port() { - local port="$1" - cat <