🔨 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
# This files check if all user configuration requirements are met
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
# 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
bashio::config.require.ssl
bashio::require.unprotected

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
# Ensure the configuration exists
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
if hass.file_exists '/config/glances/glances.conf'; then
if bashio::fs.file_exists '/config/glances/glances.conf'; then
cp -f /config/glances/glances.conf /etc/glances.conf
exit "${EX_OK}"
exit 0
fi
# Ensure configuration exists
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
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
# Export Glances data to InfluxDB
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
if hass.config.false 'influxdb.enabled'; then
if bashio::config.false 'influxdb.enabled'; then
exit "${EX_OK}"
fi
# Modify the configuration
{
echo "[influxdb]"
echo "host=$(hass.config.get 'influxdb.host')"
echo "port=$(hass.config.get 'influxdb.port')"
echo "user=$(hass.config.get 'influxdb.username')"
echo "password=$(hass.config.get 'influxdb.password')"
echo "db=$(hass.config.get 'influxdb.database')"
echo "prefix=$(hass.config.get 'influxdb.prefix')"
echo "host=$(bashio::config 'influxdb.host')"
echo "port=$(bashio::config 'influxdb.port')"
echo "user=$(bashio::config 'influxdb.username')"
echo "password=$(bashio::config 'influxdb.password')"
echo "db=$(bashio::config 'influxdb.database')"
echo "prefix=$(bashio::config 'influxdb.prefix')"
} >> /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
# Configure the use of SSL in NGINX
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
if hass.config.true 'ssl'; then
certfile=$(hass.config.get 'certfile')
keyfile=$(hass.config.get 'keyfile')
if bashio::config.true 'ssl'; then
certfile=$(bashio::config 'certfile')
keyfile=$(bashio::config 'keyfile')
sed -i "s/%%certfile%%/${certfile}/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
# Runs Glances
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
declare -a options
hass.log.info 'Starting Glances'
bashio::log.info 'Starting Glances...'
options+=(-C /etc/glances.conf)
options+=(-w)
options+=(--port 61209)
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)
fi
if hass.debug; then
if bashio::debug; then
options+=(--debug)
fi

View file

@ -1,14 +1,11 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: Glances
# Runs Glances InfluxDB Export
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
declare -a options
if hass.config.false 'influxdb.enabled'; then
if bashio::config.false 'influxdb.enabled'; then
exec sleep 86400
fi
@ -16,12 +13,12 @@ options+=(-C /etc/glances.conf)
options+=(--export influxdb)
options+=(--quiet)
if hass.debug; then
if bashio::debug; then
options+=(--debug)
fi
# Interval
sleep "$(hass.config.get 'influxdb.interval')"
sleep "$(bashio::config 'influxdb.interval')"
# Run Glances
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
# Runs the nginx daemon
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
hass.log.info 'Starting the NGINX daemon'
bashio::log.info 'Starting the NGINX daemon...'
# Wait for Glances to become available
s6-svwait -u -t 5000 /var/run/s6/services/glances
# 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
fi
if hass.config.true 'ssl'; then
if bashio::config.true 'ssl'; then
exec nginx -c /etc/nginx/nginx-ssl.conf
else
exec nginx -c /etc/nginx/nginx.conf