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",
|
"name": "NGINX Home Assistant SSL proxy",
|
||||||
"version": "2.4",
|
"version": "2.5",
|
||||||
"slug": "nginx_proxy",
|
"slug": "nginx_proxy",
|
||||||
"description": "An SSL/TLS proxy",
|
"description": "An SSL/TLS proxy",
|
||||||
"url": "https://home-assistant.io/addons/nginx_proxy/",
|
"url": "https://home-assistant.io/addons/nginx_proxy/",
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bashio
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
CONFIG_PATH=/data/options.json
|
|
||||||
DHPARAMS_PATH=/data/dhparams.pem
|
DHPARAMS_PATH=/data/dhparams.pem
|
||||||
|
|
||||||
SNAKEOIL_CERT=/data/ssl-cert-snakeoil.pem
|
SNAKEOIL_CERT=/data/ssl-cert-snakeoil.pem
|
||||||
@@ -9,29 +8,27 @@ SNAKEOIL_KEY=/data/ssl-cert-snakeoil.key
|
|||||||
|
|
||||||
CLOUDFLARE_CONF=/data/cloudflare.conf
|
CLOUDFLARE_CONF=/data/cloudflare.conf
|
||||||
|
|
||||||
DOMAIN=$(jq --raw-output ".domain" $CONFIG_PATH)
|
DOMAIN=$(bashio::config 'domain')
|
||||||
KEYFILE=$(jq --raw-output ".keyfile" $CONFIG_PATH)
|
KEYFILE=$(bashio::config 'keyfile')
|
||||||
CERTFILE=$(jq --raw-output ".certfile" $CONFIG_PATH)
|
CERTFILE=$(bashio::config 'certfile')
|
||||||
HSTS=$(jq --raw-output ".hsts // empty" $CONFIG_PATH)
|
HSTS=$(bashio::config 'hsts')
|
||||||
CUSTOMIZE_ACTIVE=$(jq --raw-output ".customize.active" $CONFIG_PATH)
|
|
||||||
CLOUDFLARE=$(jq --raw-output ".cloudflare" $CONFIG_PATH)
|
|
||||||
|
|
||||||
# Generate dhparams
|
# Generate dhparams
|
||||||
if [ ! -f "$DHPARAMS_PATH" ]; then
|
if ! bashio::fs.file_exists "${DHPARAMS_PATH}"; then
|
||||||
echo "[INFO] Generating dhparams (this will take some time)..."
|
bashio::log.info "Generating dhparams (this will take some time)..."
|
||||||
openssl dhparam -dsaparam -out "$DHPARAMS_PATH" 4096 > /dev/null
|
openssl dhparam -dsaparam -out "$DHPARAMS_PATH" 4096 > /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -f "$SNAKEOIL_CERT" ]; then
|
if ! bashio::fs.file_exists "${SNAKEOIL_CERT}"; then
|
||||||
echo "[INFO] Creating 'snakeoil' self-signed certificate..."
|
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'
|
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout $SNAKEOIL_KEY -out $SNAKEOIL_CERT -subj '/CN=localhost'
|
||||||
fi
|
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
|
sed -i "s|#include /data/cloudflare.conf;|include /data/cloudflare.conf;|" /etc/nginx.conf
|
||||||
# Generate cloudflare.conf
|
# Generate cloudflare.conf
|
||||||
if [ ! -f "$CLOUDFLARE_CONF" ]; then
|
if ! bashio::fs.file_exists "${CLOUDFLARE_CONF}"; then
|
||||||
echo "[INFO] Creating 'cloudflare.conf' for real visitor IP address..."
|
bashio::log.info "Creating 'cloudflare.conf' for real visitor IP address..."
|
||||||
echo "# Cloudflare IP addresses" > $CLOUDFLARE_CONF;
|
echo "# Cloudflare IP addresses" > $CLOUDFLARE_CONF;
|
||||||
echo "" >> $CLOUDFLARE_CONF;
|
echo "" >> $CLOUDFLARE_CONF;
|
||||||
|
|
||||||
@@ -39,13 +36,13 @@ if [ "$CLOUDFLARE" == "true" ]; then
|
|||||||
for i in $(curl https://www.cloudflare.com/ips-v4); do
|
for i in $(curl https://www.cloudflare.com/ips-v4); do
|
||||||
echo "set_real_ip_from ${i};" >> $CLOUDFLARE_CONF;
|
echo "set_real_ip_from ${i};" >> $CLOUDFLARE_CONF;
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "" >> $CLOUDFLARE_CONF;
|
echo "" >> $CLOUDFLARE_CONF;
|
||||||
echo "# - IPv6" >> $CLOUDFLARE_CONF;
|
echo "# - IPv6" >> $CLOUDFLARE_CONF;
|
||||||
for i in $(curl https://www.cloudflare.com/ips-v6); do
|
for i in $(curl https://www.cloudflare.com/ips-v6); do
|
||||||
echo "set_real_ip_from ${i};" >> $CLOUDFLARE_CONF;
|
echo "set_real_ip_from ${i};" >> $CLOUDFLARE_CONF;
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "" >> $CLOUDFLARE_CONF;
|
echo "" >> $CLOUDFLARE_CONF;
|
||||||
echo "real_ip_header CF-Connecting-IP;" >> $CLOUDFLARE_CONF;
|
echo "real_ip_header CF-Connecting-IP;" >> $CLOUDFLARE_CONF;
|
||||||
fi
|
fi
|
||||||
@@ -60,13 +57,13 @@ sed -i "s/%%DOMAIN%%/$DOMAIN/g" /etc/nginx.conf
|
|||||||
sed -i "s/%%HSTS%%/$HSTS/g" /etc/nginx.conf
|
sed -i "s/%%HSTS%%/$HSTS/g" /etc/nginx.conf
|
||||||
|
|
||||||
# Allow customize configs from share
|
# Allow customize configs from share
|
||||||
if [ "$CUSTOMIZE_ACTIVE" == "true" ]; then
|
if bashio::config.true 'customize.active'; then
|
||||||
CUSTOMIZE_DEFAULT=$(jq --raw-output ".customize.default" $CONFIG_PATH)
|
CUSTOMIZE_DEFAULT=$(bashio::config 'customize.default')
|
||||||
sed -i "s|#include /share/nginx_proxy_default.*|include /share/$CUSTOMIZE_DEFAULT;|" /etc/nginx.conf
|
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
|
sed -i "s|#include /share/nginx_proxy/.*|include /share/$CUSTOMIZE_SERVERS;|" /etc/nginx.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# start server
|
# start server
|
||||||
echo "[INFO] Running nginx..."
|
bashio::log.info "Running nginx..."
|
||||||
exec nginx -c /etc/nginx.conf < /dev/null
|
exec nginx -c /etc/nginx.conf < /dev/null
|
||||||
|
|||||||
Reference in New Issue
Block a user