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:
Nathan W
2019-10-20 04:22:52 -06:00
committed by Pascal Vizeli
parent 7f4696df8a
commit a980fdfa54
2 changed files with 19 additions and 22 deletions

View File

@@ -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/",

View File

@@ -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