mirror of
https://github.com/aljazceru/addons.git
synced 2025-12-17 05:04:21 +01:00
Update nginx_proxy add-on to use Bashio (#784)
* Update nginx_proxy add-on to use Bashio Closes #731 * Fixing shellcheck issues. * Rev version number * Use bashio::config.true where needed
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "NGINX Home Assistant SSL proxy",
|
||||
"version": "2.4",
|
||||
"version": "2.5",
|
||||
"slug": "nginx_proxy",
|
||||
"description": "An SSL/TLS proxy",
|
||||
"url": "https://home-assistant.io/addons/nginx_proxy/",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bashio
|
||||
set -e
|
||||
|
||||
CONFIG_PATH=/data/options.json
|
||||
DHPARAMS_PATH=/data/dhparams.pem
|
||||
|
||||
SNAKEOIL_CERT=/data/ssl-cert-snakeoil.pem
|
||||
@@ -9,29 +8,27 @@ SNAKEOIL_KEY=/data/ssl-cert-snakeoil.key
|
||||
|
||||
CLOUDFLARE_CONF=/data/cloudflare.conf
|
||||
|
||||
DOMAIN=$(jq --raw-output ".domain" $CONFIG_PATH)
|
||||
KEYFILE=$(jq --raw-output ".keyfile" $CONFIG_PATH)
|
||||
CERTFILE=$(jq --raw-output ".certfile" $CONFIG_PATH)
|
||||
HSTS=$(jq --raw-output ".hsts // empty" $CONFIG_PATH)
|
||||
CUSTOMIZE_ACTIVE=$(jq --raw-output ".customize.active" $CONFIG_PATH)
|
||||
CLOUDFLARE=$(jq --raw-output ".cloudflare" $CONFIG_PATH)
|
||||
DOMAIN=$(bashio::config 'domain')
|
||||
KEYFILE=$(bashio::config 'keyfile')
|
||||
CERTFILE=$(bashio::config 'certfile')
|
||||
HSTS=$(bashio::config 'hsts')
|
||||
|
||||
# Generate dhparams
|
||||
if [ ! -f "$DHPARAMS_PATH" ]; then
|
||||
echo "[INFO] Generating dhparams (this will take some time)..."
|
||||
if ! bashio::fs.file_exists "${DHPARAMS_PATH}"; then
|
||||
bashio::log.info "Generating dhparams (this will take some time)..."
|
||||
openssl dhparam -dsaparam -out "$DHPARAMS_PATH" 4096 > /dev/null
|
||||
fi
|
||||
|
||||
if [ ! -f "$SNAKEOIL_CERT" ]; then
|
||||
echo "[INFO] Creating 'snakeoil' self-signed certificate..."
|
||||
if ! bashio::fs.file_exists "${SNAKEOIL_CERT}"; then
|
||||
bashio::log.info "Creating 'snakeoil' self-signed certificate..."
|
||||
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout $SNAKEOIL_KEY -out $SNAKEOIL_CERT -subj '/CN=localhost'
|
||||
fi
|
||||
|
||||
if [ "$CLOUDFLARE" == "true" ]; then
|
||||
if bashio::config.true 'cloudflare'; then
|
||||
sed -i "s|#include /data/cloudflare.conf;|include /data/cloudflare.conf;|" /etc/nginx.conf
|
||||
# Generate cloudflare.conf
|
||||
if [ ! -f "$CLOUDFLARE_CONF" ]; then
|
||||
echo "[INFO] Creating 'cloudflare.conf' for real visitor IP address..."
|
||||
if ! bashio::fs.file_exists "${CLOUDFLARE_CONF}"; then
|
||||
bashio::log.info "Creating 'cloudflare.conf' for real visitor IP address..."
|
||||
echo "# Cloudflare IP addresses" > $CLOUDFLARE_CONF;
|
||||
echo "" >> $CLOUDFLARE_CONF;
|
||||
|
||||
@@ -60,13 +57,13 @@ sed -i "s/%%DOMAIN%%/$DOMAIN/g" /etc/nginx.conf
|
||||
sed -i "s/%%HSTS%%/$HSTS/g" /etc/nginx.conf
|
||||
|
||||
# Allow customize configs from share
|
||||
if [ "$CUSTOMIZE_ACTIVE" == "true" ]; then
|
||||
CUSTOMIZE_DEFAULT=$(jq --raw-output ".customize.default" $CONFIG_PATH)
|
||||
if bashio::config.true 'customize.active'; then
|
||||
CUSTOMIZE_DEFAULT=$(bashio::config 'customize.default')
|
||||
sed -i "s|#include /share/nginx_proxy_default.*|include /share/$CUSTOMIZE_DEFAULT;|" /etc/nginx.conf
|
||||
CUSTOMIZE_SERVERS=$(jq --raw-output ".customize.servers" $CONFIG_PATH)
|
||||
CUSTOMIZE_SERVERS=$(bashio::config 'customize.servers')
|
||||
sed -i "s|#include /share/nginx_proxy/.*|include /share/$CUSTOMIZE_SERVERS;|" /etc/nginx.conf
|
||||
fi
|
||||
|
||||
# start server
|
||||
echo "[INFO] Running nginx..."
|
||||
bashio::log.info "Running nginx..."
|
||||
exec nginx -c /etc/nginx.conf < /dev/null
|
||||
|
||||
Reference in New Issue
Block a user