mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 12:33:02 +02:00
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 <stdin>:0): Cannot iterate over null (null) Also, minor whitespace cleanup and bashisms fixes. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+15
-11
@@ -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 <<EOF
|
||||
{
|
||||
"class": "infix-hardware:usb",
|
||||
"name": "$port",
|
||||
"state": {
|
||||
"admin-state": "unlocked"
|
||||
}
|
||||
}
|
||||
port="$1"
|
||||
cat <<EOF
|
||||
{
|
||||
"class": "infix-hardware:usb",
|
||||
"name": "$port",
|
||||
"state": {
|
||||
"admin-state": "unlocked"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
}
|
||||
first=1
|
||||
@@ -24,7 +28,7 @@ cat <<EOF
|
||||
EOF
|
||||
for port in $usb_ports; do
|
||||
if [ $first -eq 0 ]; then
|
||||
echo -n ','
|
||||
echo -n ','
|
||||
fi
|
||||
first=0;
|
||||
gen_port "$port"
|
||||
|
||||
Reference in New Issue
Block a user