This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,115 @@ | ||
#!/usr/bin/with-contenv bash | ||
#!/usr/bin/with-contenv bashio | ||
# ============================================================================== | ||
# Community Hass.io Add-ons: MQTT Server & Web client | ||
# This files check if all user configuration requirements are met | ||
# ============================================================================== | ||
# shellcheck disable=SC1091 | ||
source /usr/lib/hassio-addons/base.sh | ||
|
||
# Checks for broker | ||
if hass.config.true 'broker.enabled' \ | ||
&& hass.config.false 'broker.allow_anonymous' \ | ||
&& ! ( \ | ||
hass.config.exists 'leave_front_door_open' \ | ||
&& hass.config.true 'leave_front_door_open' \ | ||
); then | ||
if ! hass.config.has_value 'mqttusers[0].username'; then | ||
hass.die 'Missing username for MQTT User' | ||
fi | ||
if ! hass.config.has_value 'mqttusers[0].password'; then | ||
hass.die 'Missing password for MQTT User' | ||
fi | ||
|
||
# Ensure not both web & mqtt are disabled | ||
if bashio::config.false 'web.enable' && bashio::config.false 'broker.enable'; then | ||
bashio::exit.nok 'Both Web & MQTT are disabled. Aborting.' | ||
fi | ||
|
||
# Check SSL requirements, if enabled | ||
if hass.config.true 'broker.enable_ws_ssl' \ | ||
|| hass.config.true 'broker.enable_mqtt_ssl' \ | ||
|| (hass.config.true 'web.enabled' && hass.config.true 'web.ssl'); then | ||
if ! hass.config.has_value 'certfile'; then | ||
hass.die 'SSL is enabled, but no certfile was specified' | ||
# Notify user if web is disabled | ||
if bashio::config.false 'web.enable'; then | ||
bashio::log.notice 'The Web client has been disabled!' | ||
fi | ||
|
||
# Notify user if mqtt is disabled | ||
if bashio::config.false 'broker.enable'; then | ||
bashio::log.notice 'The MQTT Broker has been disabled!' | ||
fi | ||
|
||
# Checks for the web client | ||
if bashio::config.true 'web.enable'; then | ||
|
||
if ! bashio::config.true 'leave_front_door_open'; then | ||
bashio::config.require.username 'web.username'; | ||
bashio::config.require.password 'web.password'; | ||
fi | ||
|
||
if ! hass.config.has_value 'keyfile'; then | ||
hass.die 'SSL is enabled, but no keyfile was specified' | ||
# We need a username to go with the password | ||
if bashio::config.is_empty 'web.username' \ | ||
&& bashio::config.has_value 'web.password'; | ||
then | ||
bashio::log.fatal | ||
bashio::log.fatal 'You have set a Web client password using the' | ||
bashio::log.fatal '"web.password" option, but the "web.username" option' | ||
bashio::log.fatal 'is left empty. Login without a username but with a' | ||
bashio::log.fatal 'password is not possible.' | ||
bashio::log.fatal | ||
bashio::log.fatal 'Please set a username in the "web.username" option.' | ||
bashio::log.fatal | ||
bashio::exit.nok | ||
fi | ||
|
||
if ! hass.file_exists "/ssl/$(hass.config.get 'certfile')"; then | ||
hass.die 'The configured certfile is not found' | ||
# We need a password to go with the username | ||
if bashio::config.has_value 'web.username' \ | ||
&& bashio::config.is_empty 'web.password'; | ||
then | ||
bashio::log.fatal | ||
bashio::log.fatal 'You have set a Web client username using the' | ||
bashio::log.fatal '"web.username" option, but the "web.password" option' | ||
bashio::log.fatal 'is left empty. Login without a password but with a' | ||
bashio::log.fatal 'username is not possible.' | ||
bashio::log.fatal | ||
bashio::log.fatal 'Please set a password in the "web.password" option.' | ||
bashio::log.fatal | ||
bashio::exit.nok | ||
fi | ||
|
||
if ! hass.file_exists "/ssl/$(hass.config.get 'keyfile')"; then | ||
hass.die 'The configured keyfile is not found' | ||
# Require a secure password | ||
if bashio::config.has_value 'web.password' \ | ||
&& ! bashio::config.true 'i_like_to_be_pwned'; then | ||
bashio::config.require.safe_password 'web.password' | ||
fi | ||
|
||
bashio::config.require.ssl 'web.ssl' 'certfile' 'keyfile' | ||
fi | ||
|
||
# Checks for the mqtt broker | ||
if bashio::config.true 'broker.enable'; then | ||
|
||
if ! bashio::config.true 'leave_front_door_open'; then | ||
bashio::config.require.username 'broker.username'; | ||
bashio::config.require.password 'broker.password'; | ||
fi | ||
|
||
# We need a username to go with the password | ||
if bashio::config.is_empty 'mqttusers[0].username' \ | ||
&& bashio::config.has_value 'broker.password'; | ||
then | ||
bashio::log.fatal | ||
bashio::log.fatal 'You have set a password using the' | ||
bashio::log.fatal '"mqttusers" option, but the username for it' | ||
bashio::log.fatal 'is left empty. Login without a username but with a' | ||
bashio::log.fatal 'password is not possible.' | ||
bashio::log.fatal | ||
bashio::log.fatal 'Please set a username in the "mqttusers" option.' | ||
bashio::log.fatal | ||
bashio::exit.nok | ||
fi | ||
|
||
# We need a password to go with the username | ||
if bashio::config.has_value 'broker.username' \ | ||
&& bashio::config.is_empty 'broker.password'; | ||
then | ||
bashio::log.fatal | ||
bashio::log.fatal 'You have set a password using the' | ||
bashio::log.fatal '"mqttusers" option, but the password for it' | ||
bashio::log.fatal 'is left empty. Login without a password but with a' | ||
bashio::log.fatal 'username is not possible.' | ||
bashio::log.fatal | ||
bashio::log.fatal 'Please set a password in the "mqttusers" option.' | ||
bashio::log.fatal | ||
bashio::exit.nok | ||
fi | ||
|
||
# Require a secure password | ||
if bashio::config.has_value 'mqttusers[0].password' \ | ||
&& ! bashio::config.true 'i_like_to_be_pwned'; then | ||
bashio::config.require.safe_password 'mqttusers[0].password' | ||
fi | ||
|
||
bashio::config.require.ssl 'broker.enable_ws_ssl' 'certfile' 'keyfile' | ||
bashio::config.require.ssl 'broker.enable_ssl' 'certfile' 'keyfile' | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
#!/usr/bin/with-contenv bash | ||
#!/usr/bin/with-contenv bashio | ||
# ============================================================================== | ||
# Community Hass.io Add-ons: MQTT Server & Web client | ||
# Runs the MQTT Server | ||
# ============================================================================== | ||
# shellcheck disable=SC1091 | ||
source /usr/lib/hassio-addons/base.sh | ||
|
||
declare -a options | ||
|
||
if hass.config.false 'broker.enabled'; then | ||
if bashio::config.false 'broker.enabled'; then | ||
while true; do | ||
hass.log.debug 'MQTT Server are not enabled...' | ||
bashio::log.debug 'MQTT Server are not enabled...' | ||
exec sleep 86400 | ||
done | ||
fi | ||
|
||
options+=(-c /opt/mosquitto.conf) | ||
|
||
if hass.debug; then | ||
if bashio::debug; then | ||
options+=(-v) | ||
fi | ||
|
||
hass.log.info "Starting mosquitto MQTT Server..." | ||
bashio::log.info "Starting mosquitto MQTT Server..." | ||
exec mosquitto "${options[@]}" |
Oops, something went wrong.