# apache2 - postinst
#!/bin/sh
set -e
if true && type update-rc.d >/dev/null 2>/dev/null; then
	if [ -n "$D" ]; then
		OPT="-f -r $D"
	else
		OPT="-f -s"
	fi
	update-rc.d $OPT apache2 defaults 91 20
fi

if [ -n "$D" ]; then
    $INTERCEPT_DIR/postinst_intercept delay_to_first_boot apache2 mlprefix=
    exit 0
fi
    SSLCERT=/etc/pki/tls/certs/localhost.crt
    SSLKEY=/etc/pki/tls/private/localhost.key
    mkdir -p `dirname $SSLCERT`
    mkdir -p `dirname $SSLKEY`

    if ! [ -f $SSLKEY -o -f $SSLCERT ] ; then
        openssl genrsa -rand /proc/cpuinfo:/proc/filesystems:/proc/interrupts:/proc/ioports:/proc/uptime \
            1024 > $SSLKEY 2> /dev/null

        FQDN=`hostname`
        if [ "x${FQDN}" = "x" ]; then
            FQDN=localhost.localdomain
        fi

        openssl req -new -key $SSLKEY \
            -x509 -days 365 -set_serial $RANDOM -extensions v3_req \
            -subj "/C=US/ST=California/L=Milpitas/O=Viavi Solutions/CN=$FQDN" -out $SSLCERT 2>/dev/null
    fi