mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-11 02:11:01 +01:00
39 lines
1.5 KiB
Bash
39 lines
1.5 KiB
Bash
#!/usr/bin/with-contenv bashio
|
|
# shellcheck shell=bash
|
|
|
|
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
|
|
echo "... checking if referenced files exist"
|
|
[ ! -f /ssl/"$CERTFILE" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$CERTFILE not found" && bashio::exit.nok
|
|
[ ! -f /ssl/"$KEYFILE" ] && bashio::log.fatal "... use_own_certs is true but certificate /ssl/$KEYFILE not found" && bashio::exit.nok
|
|
|
|
else
|
|
mkdir -p /ssl/nextcloud/keys
|
|
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"
|
|
CERTFILE="nextcloud/keys/cert.crt"
|
|
KEYFILE="nextcloud/keys/cert.key"
|
|
|
|
fi
|
|
|
|
#Sets certificates
|
|
echo "... adding ssl certs in files"
|
|
#Sets certificates
|
|
for NGINXFILE in "/defaults/default" "/config/nginx/site-confs/default" "/data/config/nginx/site-confs/default"; do
|
|
if [ -f $NGINXFILE ]; then
|
|
LINE=$(sed -n "/ssl_certificate /=" $NGINXFILE)
|
|
if [[ -n "$LINE" ]]; then
|
|
sed -i "/ssl_certificate/ d" $NGINXFILE
|
|
sed -i "$LINE i ssl_certificate_key /ssl/$KEYFILE;" $NGINXFILE
|
|
sed -i "$LINE i ssl_certificate /ssl/$CERTFILE;" $NGINXFILE
|
|
fi
|
|
fi
|
|
done
|
|
bashio::log.info "... done"
|