#!/bin/bash

# module-assistant and dkms nowadays automatically want to sign the module
# this has to be prepared, so /usr/share/modass/module-assistant-autopkgtest
# can not be called directly anymore

ls -l /usr/src
HEADERDIR=/usr/src/`ls -1 /usr/src/|grep linux-headers|grep -v common`
echo "I: HEADERDIR=$HEADERDIR"

# these two directories are expected
mkdir -p $HEADERDIR/certs
mkdir -p $HEADERDIR/output

echo -e "[ req ] \n\
default_bits = 4096 \n\
distinguished_name = debian-autopkgtest \n\
prompt = no \n\
x509_extensions = myexts \n\
\n\
[ debian-autopkgtest ] \n\
CN = Modules \n\
\n\
[ myexts ] \n\
basicConstraints=critical,CA:FALSE \n\
keyUsage=digitalSignature \n\
subjectKeyIdentifier=hash \n\
authorityKeyIdentifier=keyid" > x509.genkey

/usr/bin/openssl req -new -nodes -utf8 -sha512 -days 36500 -batch -x509 -config x509.genkey -outform DER -out signing_key.x509 -keyout signing_key.pem

# I have no idea why the key has to be in both, but this is working now
cp signing_key.pem signing_key.x509 $HEADERDIR/output
mv signing_key.pem signing_key.x509 $HEADERDIR/certs

/usr/share/modass/module-assistant-autopkgtest dahdi

exit 0
