#!/usr/bin/with-contenv bash
# shellcheck shell=bash

SUBJECT="/C=DE/ST=HH/L=Hamburg/O=openems.io/OU=OPENEMS Server/CN=*"
if [[ -f /etc/nginx/keys/cert.key && -f /etc/nginx/keys/cert.crt ]]; then
    echo "using keys found in /etc/nginx/keys"
else
    echo "generating self-signed keys in /etc/nginx/keys, you can replace these with your own keys if required"
    rm -f \
        /etc/nginx/keys/cert.key \
        /etc/nginx/keys/cert.crt || true
    openssl req -new -x509 -days 3650 -nodes -out /etc/nginx/keys/cert.crt -keyout /etc/nginx/keys/cert.key -subj "$SUBJECT"
fi
