mirror of
https://github.com/hassio-addons/addon-mqtt.git
synced 2025-05-07 12:41:23 +00:00
32 lines
1.1 KiB
Bash
32 lines
1.1 KiB
Bash
#!/usr/bin/with-contenv bash
|
|
# ==============================================================================
|
|
# Community Hass.io Add-ons: MQTT Broker & Web client
|
|
# Configures NGINX for use with MQTT Broker & Web client
|
|
# ==============================================================================
|
|
# shellcheck disable=SC1091
|
|
source /usr/lib/hassio-addons/base.sh
|
|
|
|
declare certfile
|
|
declare keyfile
|
|
|
|
# Enable SSL
|
|
if hass.config.true 'web.ssl'; then
|
|
rm /etc/nginx/nginx.conf
|
|
mv /etc/nginx/nginx-ssl.conf /etc/nginx/nginx.conf
|
|
|
|
certfile=$(hass.config.get 'certfile')
|
|
keyfile=$(hass.config.get 'keyfile')
|
|
|
|
sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/nginx.conf
|
|
sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/nginx.conf
|
|
fi
|
|
|
|
# Handles the HTTP auth part
|
|
if ! hass.config.has_value 'web.username'; then
|
|
hass.log.warning "Username/password protection is disabled!"
|
|
sed -i '/auth_basic.*/d' /etc/nginx/nginx.conf
|
|
else
|
|
username=$(hass.config.get 'web.username')
|
|
password=$(hass.config.get 'web.password')
|
|
htpasswd -bc /etc/nginx/.htpasswd "${username}" "${password}"
|
|
fi
|