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

SUBJECT="/C=US/ST=CA/L=Carlsbad/O=Linuxserver.io/OU=LSIO Server/CN=*"
if [[ -f /config/keys/cert.key && -f /config/keys/cert.crt ]]; then
    echo "using keys found in /config/keys"
else
    echo "generating self-signed keys in /config/keys, you can replace these with your own keys if required"
    rm -f \
        /config/keys/cert.key \
        /config/keys/cert.crt || true
    openssl req -new -x509 -days 3650 -nodes -out /config/keys/cert.crt -keyout /config/keys/cert.key -subj "$SUBJECT" -addext "subjectAltName = DNS:localhost"
fi
