#!/bin/sh
set -e

usb_ports=$(cat /run/system.json | jq -r '.["usb-ports"] | map(.name) | unique | join(" ")')

gen_port()
{
	local port="$1"
	cat <<EOF
    	{
		"class": "infix-hardware:usb",
		"name": "$port",
		"state": {
    			"admin-state": "unlocked"
  			}
    	}
EOF
}
first=1
cat <<EOF
{
  "ietf-hardware:hardware": {
    "component": [
EOF
for port in $usb_ports; do
    if [ $first -eq 0 ]; then
       echo -n ','
    fi
    first=0;
    gen_port "$port"
done
cat <<EOF
]}
}
EOF
