mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-30 08:27:40 +01:00
44 lines
1.6 KiB
Bash
44 lines
1.6 KiB
Bash
#!/usr/bin/with-contenv bashio
|
|
|
|
#Check if files exist
|
|
if bashio::config.true 'use_own_certs'; then
|
|
bashio::log.info "Using referenced ssl certificates..."
|
|
CERTFILE=$(bashio::config 'certfile')
|
|
KEYFILE=$(bashio::config 'keyfile')
|
|
|
|
#Check if files exist
|
|
[ ! -f /ssl/$CERTFILE ] && bashio::log.fatal "... Certificate /ssl/$CERTFILE not found" && exit 1
|
|
[ ! -f /ssl/$KEYFILE ] && bashio::log.fatal "... Certificate /ssl/$KEYFILE not found" && exit 1
|
|
|
|
#Sets certificates
|
|
NGINXFILE="/defaults/default"
|
|
LINE=$(sed -n '/cert.crt/=' $NGINXFILE)
|
|
sed -i "$LINE a ssl_certificate ${CERTFILE};" $NGINXFILE
|
|
sed -i "$LINE d" $NGINXFILE
|
|
|
|
LINE=$(sed -n '/cert.key/=' $NGINXFILE)
|
|
sed -i "$LINE a ssl_certificate_key ${CERTFILE};" $NGINXFILE
|
|
sed -i "$LINE d" $NGINXFILE
|
|
|
|
#Sets certificates
|
|
NGINXFILE="/config/nginx/site-confs/default"
|
|
if [ -f $NGINXFILE ]; then
|
|
LINE=$(sed -n '/cert.crt/=' $NGINXFILE) && \
|
|
sed -i "$LINE a ssl_certificate ${CERTFILE};" $NGINXFILE && \
|
|
sed -i "$LINE d" $NGINXFILE || true
|
|
fi || true
|
|
|
|
if [ -f $NGINXFILE ]; then
|
|
LINE=$(sed -n '/cert.key/=' $NGINXFILE) && \
|
|
sed -i "$LINE a ssl_certificate_key ${CERTFILE};" $NGINXFILE && \
|
|
sed -i "$LINE d" $NGINXFILE || true
|
|
fi || true
|
|
|
|
bashio::log.info "... done"
|
|
echo "#!/bin/bash" > /etc/cont-init.d/30-keygen
|
|
else
|
|
bashio::log.info "No ssl certificates set. Auto generating ones."
|
|
SUBJECT="/C=US/ST=CA/L=Carlsbad/O=Linuxserver.io/OU=LSIO Server/CN=*"
|
|
openssl req -new -x509 -days 3650 -nodes -out /ssl/nextcloud/keys/cert.crt -keyout /ssl/nextcloud/keys/cert.key -subj "$SUBJECT"
|
|
fi
|