#!/usr/bin/env bash

set -e

baseDir=$(cd $(dirname $0) && pwd)
dataDir="/opt/boulder/labca/certs/webpki"

export PKI_ROOT_CERT_BASE="$dataDir/root-01-cert"
export PKI_INT_CERT_BASE="$dataDir/issuer-01-cert"

cd /opt/boulder/labca
$baseDir/apply-boulder

cd /var/www/html

PKI_ROOT_CRL_FILE=${PKI_ROOT_CERT_BASE/-cert/-crl}.pem
if [ -e "$PKI_ROOT_CRL_FILE" ]; then
    cp $PKI_ROOT_CRL_FILE crl/
else
    echo "WARNING: no Root CRL file present - please upload one from the manage page"
fi
cp $PKI_ROOT_CERT_BASE.pem certs/
cp $PKI_INT_CERT_BASE.pem certs/

$baseDir/apply-nginx
