#!/bin/bash

# This script goes through all .crt files in this directory and stores
# them in EFI signature database format.

FLAVORS="openSUSE SLES"

for flavor in ${FLAVORS}; do
	OUTPUT=vendor-dbx-$(echo ${flavor} | tr '[:upper:]' '[:lower:]').bin

	mkdir tmp

	for cert in ${flavor}-*.crt
	do
		BASENAME=`basename $cert .crt`
		openssl x509 -in $cert -outform der -out tmp/${BASENAME}.der
		efisiglist -a -c tmp/${BASENAME}.der -o tmp/${BASENAME}.bin
	done

	cat tmp/*bin > $OUTPUT
	rm -rf tmp
done

# generate a vendor dbx file includes all .der for testing environment
OUTPUT=vendor-dbx.bin
mkdir tmp
for cert in *.crt
do
	BASENAME=`basename $cert .crt`
	openssl x509 -in $cert -outform der -out tmp/${BASENAME}.der
	efisiglist -a -c tmp/${BASENAME}.der -o tmp/${BASENAME}.bin
done
cat tmp/*bin > $OUTPUT
rm -rf tmp
