10afa8e06SEd Maste#!/bin/sh -u 20afa8e06SEd Maste 30afa8e06SEd Maste# Copyright (c) 2020 Yubico AB. All rights reserved. 40afa8e06SEd Maste# Use of this source code is governed by a BSD-style 50afa8e06SEd Maste# license that can be found in the LICENSE file. 6*2ccfa855SEd Maste# SPDX-License-Identifier: BSD-2-Clause 70afa8e06SEd Maste 80afa8e06SEd Mastesort_by_id() { 90afa8e06SEd Maste awk '{ printf "%d\n", $3 }' | sort -Cnu 100afa8e06SEd Maste} 110afa8e06SEd Maste 120afa8e06SEd Masteif ! grep '^vendor' "$1" | sort_by_id; then 130afa8e06SEd Maste echo unsorted vendor section 1>&2 140afa8e06SEd Maste exit 1 150afa8e06SEd Mastefi 160afa8e06SEd Maste 170afa8e06SEd MasteVENDORS=$(grep '^vendor' "$1" | awk '{ print $2 }') 180afa8e06SEd MastePRODUCTS=$(grep '^product' "$1" | awk '{ print $2 }' | uniq) 190afa8e06SEd Maste 200afa8e06SEd Masteif [ "${VENDORS}" != "${PRODUCTS}" ]; then 210afa8e06SEd Maste echo vendors: "$(echo "${VENDORS}" | tr '\n' ',')" 1>&2 220afa8e06SEd Maste echo products: "$(echo "${PRODUCTS}" | tr '\n' ',')" 1>&2 230afa8e06SEd Maste echo vendors and products in different order 1>&2 240afa8e06SEd Maste exit 2 250afa8e06SEd Mastefi 260afa8e06SEd Maste 270afa8e06SEd Mastefor v in ${VENDORS}; do 280afa8e06SEd Maste if ! grep "^product ${v}" "$1" | sort_by_id; then 290afa8e06SEd Maste echo "${v}": unsorted product section 1>&2 300afa8e06SEd Maste exit 3 310afa8e06SEd Maste fi 320afa8e06SEd Mastedone 33