xref: /freebsd/contrib/libfido2/udev/check.sh (revision 1323ec57)
1#!/bin/sh -u
2
3# Copyright (c) 2020 Yubico AB. All rights reserved.
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file.
6
7sort_by_id() {
8	awk '{ printf "%d\n", $3 }' | sort -Cnu
9}
10
11if ! grep '^vendor' "$1" | sort_by_id; then
12	echo unsorted vendor section 1>&2
13	exit 1
14fi
15
16VENDORS=$(grep '^vendor' "$1" | awk '{ print $2 }')
17PRODUCTS=$(grep '^product' "$1" | awk '{ print $2 }' | uniq)
18
19if [ "${VENDORS}" != "${PRODUCTS}" ]; then
20	echo vendors: "$(echo "${VENDORS}" | tr '\n' ',')" 1>&2
21	echo products: "$(echo "${PRODUCTS}" | tr '\n' ',')" 1>&2
22	echo vendors and products in different order 1>&2
23	exit 2
24fi
25
26for v in ${VENDORS}; do
27	if ! grep "^product ${v}" "$1" | sort_by_id; then
28		echo "${v}": unsorted product section 1>&2
29		exit 3
30	fi
31done
32