🔨 Rewrite add-on onto Bashio

This commit is contained in:
Franck Nijhof 2019-04-01 12:35:17 +02:00
parent 7e83b1b5de
commit 836fa1fbdf
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
8 changed files with 32 additions and 102 deletions

View file

@ -1,26 +1,7 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Community Hass.io Add-ons: Glances # Community Hass.io Add-ons: Glances
# This files check if all user configuration requirements are met # This files check if all user configuration requirements are met
# ============================================================================== # ==============================================================================
# shellcheck disable=SC1091 bashio::config.require.ssl
source /usr/lib/hassio-addons/base.sh bashio::require.unprotected
# Check SSL requirements, if enabled
if hass.config.true 'ssl'; then
if ! hass.config.has_value 'certfile'; then
hass.die 'SSL is enabled, but no certfile was specified'
fi
if ! hass.config.has_value 'keyfile'; then
hass.die 'SSL is enabled, but no keyfile was specified'
fi
if ! hass.file_exists "/ssl/$(hass.config.get 'certfile')"; then
hass.die 'The configured certfile is not found'
fi
if ! hass.file_exists "/ssl/$(hass.config.get 'keyfile')"; then
hass.die 'The configured keyfile is not found'
fi
fi

View file

@ -1,33 +0,0 @@
#!/usr/bin/with-contenv bash
# ==============================================================================
# Community Hass.io Add-ons: Glances
# Unprotects this add-on in order to gain access to the Docker socket
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
# Break in case the API is unreachable
if ! hass.api.supervisor.ping; then
hass.die "Could you contact the HassIO API"
fi
# Docker support is enabled!
if [[ -S "/var/run/docker.sock" ]]; then
hass.log.info 'Docker support has been enabled.'
exit "${EX_OK}"
fi
hass.log.fatal "PROTECTION MODE ENABLED!"
hass.log.fatal ""
hass.log.fatal "To be able to use this add-on, you'll need to disable"
hass.log.fatal "protection mode on this add-on. Without it, the add-on"
hass.log.fatal "is unable to access Docker."
hass.log.fatal ""
hass.log.fatal "Steps:"
hass.log.fatal " - Go to the Hass.io Panel."
hass.log.fatal " - Click on the 'Glances' add-on."
hass.log.fatal " - Set the 'Protection mode' switch to off."
hass.log.fatal " - Restart the add-on."
hass.log.fatal ""
exit "${EX_NOK}"

View file

@ -1,19 +1,16 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Community Hass.io Add-ons: Glances # Community Hass.io Add-ons: Glances
# Ensure the configuration exists # Ensure the configuration exists
# ============================================================================== # ==============================================================================
# shellcheck disable=SC1091 if bashio::fs.file_exists '/config/glances/glances.conf'; then
source /usr/lib/hassio-addons/base.sh
if hass.file_exists '/config/glances/glances.conf'; then
cp -f /config/glances/glances.conf /etc/glances.conf cp -f /config/glances/glances.conf /etc/glances.conf
exit "${EX_OK}" exit 0
fi fi
# Ensure configuration exists # Ensure configuration exists
mkdir -p /config/glances \ mkdir -p /config/glances \
|| hass.die "Failed to create the Glances configuration directory" || bashio::exit.nok "Failed to create the Glances configuration directory"
# Copy in template file # Copy in template file
cp /etc/glances.conf /config/glances/ cp /etc/glances.conf /config/glances/

View file

@ -1,22 +1,19 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Community Hass.io Add-ons: Glances # Community Hass.io Add-ons: Glances
# Export Glances data to InfluxDB # Export Glances data to InfluxDB
# ============================================================================== # ==============================================================================
# shellcheck disable=SC1091 if bashio::config.false 'influxdb.enabled'; then
source /usr/lib/hassio-addons/base.sh
if hass.config.false 'influxdb.enabled'; then
exit "${EX_OK}" exit "${EX_OK}"
fi fi
# Modify the configuration # Modify the configuration
{ {
echo "[influxdb]" echo "[influxdb]"
echo "host=$(hass.config.get 'influxdb.host')" echo "host=$(bashio::config 'influxdb.host')"
echo "port=$(hass.config.get 'influxdb.port')" echo "port=$(bashio::config 'influxdb.port')"
echo "user=$(hass.config.get 'influxdb.username')" echo "user=$(bashio::config 'influxdb.username')"
echo "password=$(hass.config.get 'influxdb.password')" echo "password=$(bashio::config 'influxdb.password')"
echo "db=$(hass.config.get 'influxdb.database')" echo "db=$(bashio::config 'influxdb.database')"
echo "prefix=$(hass.config.get 'influxdb.prefix')" echo "prefix=$(bashio::config 'influxdb.prefix')"
} >> /etc/glances.conf } >> /etc/glances.conf

View file

@ -1,14 +1,11 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Community Hass.io Add-ons: Glances # Community Hass.io Add-ons: Glances
# Configure the use of SSL in NGINX # Configure the use of SSL in NGINX
# ============================================================================== # ==============================================================================
# shellcheck disable=SC1091 if bashio::config.true 'ssl'; then
source /usr/lib/hassio-addons/base.sh certfile=$(bashio::config 'certfile')
keyfile=$(bashio::config 'keyfile')
if hass.config.true 'ssl'; then
certfile=$(hass.config.get 'certfile')
keyfile=$(hass.config.get 'keyfile')
sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/nginx-ssl.conf sed -i "s/%%certfile%%/${certfile}/g" /etc/nginx/nginx-ssl.conf
sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/nginx-ssl.conf sed -i "s/%%keyfile%%/${keyfile}/g" /etc/nginx/nginx-ssl.conf

View file

@ -1,26 +1,23 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Community Hass.io Add-ons: Glances # Community Hass.io Add-ons: Glances
# Runs Glances # Runs Glances
# ============================================================================== # ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
declare -a options declare -a options
hass.log.info 'Starting Glances' bashio::log.info 'Starting Glances...'
options+=(-C /etc/glances.conf) options+=(-C /etc/glances.conf)
options+=(-w) options+=(-w)
options+=(--port 61209) options+=(--port 61209)
options+=(--bind 127.0.0.1) options+=(--bind 127.0.0.1)
options+=(--time "$(hass.config.get 'refresh_time')") options+=(--time "$(bashio::config 'refresh_time')")
if hass.config.false 'process_info'; then if bashio::config.false 'process_info'; then
options+=(--disable-process) options+=(--disable-process)
fi fi
if hass.debug; then if bashio::debug; then
options+=(--debug) options+=(--debug)
fi fi

View file

@ -1,14 +1,11 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Community Hass.io Add-ons: Glances # Community Hass.io Add-ons: Glances
# Runs Glances InfluxDB Export # Runs Glances InfluxDB Export
# ============================================================================== # ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
declare -a options declare -a options
if hass.config.false 'influxdb.enabled'; then if bashio::config.false 'influxdb.enabled'; then
exec sleep 86400 exec sleep 86400
fi fi
@ -16,12 +13,12 @@ options+=(-C /etc/glances.conf)
options+=(--export influxdb) options+=(--export influxdb)
options+=(--quiet) options+=(--quiet)
if hass.debug; then if bashio::debug; then
options+=(--debug) options+=(--debug)
fi fi
# Interval # Interval
sleep "$(hass.config.get 'influxdb.interval')" sleep "$(bashio::config 'influxdb.interval')"
# Run Glances # Run Glances
exec glances "${options[@]}" exec glances "${options[@]}"

View file

@ -1,22 +1,19 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bashio
# ============================================================================== # ==============================================================================
# Community Hass.io Add-ons: Glances # Community Hass.io Add-ons: Glances
# Runs the nginx daemon # Runs the nginx daemon
# ============================================================================== # ==============================================================================
# shellcheck disable=SC1091 bashio::log.info 'Starting the NGINX daemon...'
source /usr/lib/hassio-addons/base.sh
hass.log.info 'Starting the NGINX daemon'
# Wait for Glances to become available # Wait for Glances to become available
s6-svwait -u -t 5000 /var/run/s6/services/glances s6-svwait -u -t 5000 /var/run/s6/services/glances
# Disable HA Authentication if front door is open # Disable HA Authentication if front door is open
if hass.config.true 'leave_front_door_open'; then if bashio::config.true 'leave_front_door_open'; then
export DISABLE_HA_AUTHENTICATION=true export DISABLE_HA_AUTHENTICATION=true
fi fi
if hass.config.true 'ssl'; then if bashio::config.true 'ssl'; then
exec nginx -c /etc/nginx/nginx-ssl.conf exec nginx -c /etc/nginx/nginx-ssl.conf
else else
exec nginx -c /etc/nginx/nginx.conf exec nginx -c /etc/nginx/nginx.conf