Rewrite to use bashio

This commit is contained in:
ludeeus 2019-03-24 10:07:35 +01:00
parent fe2da7e02c
commit c75125fde7
3 changed files with 32 additions and 65 deletions

View file

@ -1,51 +1,22 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: Tautulli
# This files check if all user configuration requirements are met
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
# Require username / password
if ! hass.config.has_value 'username' \
&& ! ( \
hass.config.exists 'leave_front_door_open' \
&& hass.config.true 'leave_front_door_open' \
);
then
hass.die 'You need to set a username!'
fi
if ! hass.config.has_value 'password' \
&& ! ( \
hass.config.exists 'leave_front_door_open' \
&& hass.config.true 'leave_front_door_open' \
);
then
hass.die 'You need to set a password!';
if ! bashio::config.true 'leave_front_door_open'; then
bashio::config.require.username 'username';
bashio::config.require.password 'password';
fi
# Require a secure password
if hass.config.has_value 'password' \
&& ! hass.config.is_safe_password 'password'; then
hass.die "Please choose a different password, this one is unsafe!"
if bashio::config.has_value 'password' \
&& ! bashio::config.true 'i_like_to_be_pwned'; then
bashio::config.require.safe_password 'password'
fi
# 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
# Check SSL cerrificate
bashio::config.require.ssl 'ssl' 'certfile' 'keyfile'

View file

@ -1,10 +1,8 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: Tautulli
# Preparing configuration for Tautulli
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
readonly ADDON=/data/addon.ini
readonly CONFIG=/data/config.ini
@ -12,30 +10,30 @@ readonly DATABASE=/share/tautulli/tautulli.db
readonly SHARE=/share/tautulli
# If config.ini does not exist, create it.
if ! hass.file_exists "/data/config.ini"; then
hass.log.info "Creating default configuration..."
if ! bashio::fs.file_exists "$CONFIG"; then
bashio::log.info "Creating default configuration..."
crudini --set "$CONFIG" General first_run_complete 0
crudini --set "$CONFIG" General update_show_changelog 0
crudini --set "$CONFIG" Advanced system_analytics 0
crudini --set "$ADDON" Addon version "$TAUTULLI_VERSION"
fi
hass.log.info "Updating running configuration..."
bashio::log.info "Updating running configuration..."
# Temporrary changing config.ini to be valid during additions
## This has to be done because Tautulli added a ini header with [[header]]
sed -i "s/\\[\\[get_file_sizes_hold\\]\\]/\\[get_file_sizes_hold\\]/" "$CONFIG"
# Set spesific config if an upgrade
if ! hass.file_exists "/data/addon.ini"; then
if ! bashio::fs.file_exists "/data/addon.ini"; then
crudini --set "$ADDON" Addon version "0"
fi
CURRENT_VERSION=$(crudini --get "$ADDON" Addon version)
if [ "$CURRENT_VERSION" != "$TAUTULLI_VERSION" ]; then
hass.log.debug "This is an upgrade..."
bashio::log.debug "This is an upgrade..."
crudini --set "$CONFIG" General update_show_changelog 1
else
hass.log.debug "This is not an upgrade..."
bashio::log.debug "This is not an upgrade..."
crudini --set "$CONFIG" General update_show_changelog 0
fi
@ -45,14 +43,14 @@ crudini --set "$CONFIG" General check_github 0
crudini --set "$CONFIG" General check_github_on_startup 0
# Update SSL info in configuration
if hass.config.true 'ssl'; then
hass.log.info "Ensure SSL is active in the configuration..."
if bashio::config.true 'ssl'; then
bashio::log.info "Ensure SSL is active in the configuration..."
crudini --set "$CONFIG" General enable_https 1
crudini --set "$CONFIG" General https_cert_chain "\"/ssl/$(hass.config.get 'certfile')\""
crudini --set "$CONFIG" General https_cert "\"/ssl/$(hass.config.get 'certfile')\""
crudini --set "$CONFIG" General https_key "\"/ssl/$(hass.config.get 'keyfile')\""
crudini --set "$CONFIG" General https_cert_chain "\"/ssl/$(bashio::config 'certfile')\""
crudini --set "$CONFIG" General https_cert "\"/ssl/$(bashio::config 'certfile')\""
crudini --set "$CONFIG" General https_key "\"/ssl/$(bashio::config 'keyfile')\""
else
hass.log.info "Ensure SSL is not active in the configuration..."
bashio::log.info "Ensure SSL is not active in the configuration..."
crudini --set "$CONFIG" General enable_https 0
crudini --set "$CONFIG" General https_cert_chain "\"\""
crudini --set "$CONFIG" General https_cert "\"\""
@ -60,12 +58,12 @@ else
fi
# Update username and password in configuration
if hass.config.has_value 'username' && hass.config.has_value 'password'; then
hass.log.info "Ensure authentication is enabled in the configuration..."
crudini --set "$CONFIG" General http_username "\"$(hass.config.get 'username')\""
crudini --set "$CONFIG" General http_password "\"$(hass.config.get 'password')\""
if bashio::config.has_value 'username' && bashio::config.has_value 'password'; then
bashio::log.info "Ensure authentication is enabled in the configuration..."
crudini --set "$CONFIG" General http_username "\"$(bashio::config 'username')\""
crudini --set "$CONFIG" General http_password "\"$(bashio::config 'password')\""
else
hass.log.info "Ensure authentication is not enabled in the configuration..."
bashio::log.info "Ensure authentication is not enabled in the configuration..."
crudini --set "$CONFIG" General http_username "\"\""
crudini --set "$CONFIG" General http_password "\"\""
fi
@ -75,12 +73,12 @@ fi
sed -i "s/\\[get_file_sizes_hold\\]/\\[\\[get_file_sizes_hold\\]\\]/" "$CONFIG"
# Create /share/tautulli if it does not exist.
if ! hass.directory_exists "$SHARE"; then
if ! bashio::fs.directory_exists "$SHARE"; then
mkdir "$SHARE"
fi
# Use databasefile from /share/tautulli if it exist.
if hass.file_exists "$DATABASE"; then
hass.log.info "Using database from $DATABASE"
if bashio::fs.file_exists "$DATABASE"; then
bashio::log.info "Using database from $DATABASE"
ln -sf "$DATABASE" /data/tautulli.db
fi

View file

@ -1,13 +1,11 @@
#!/usr/bin/with-contenv bash
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: Tautulli
# Runs Tautulli
# ==============================================================================
# shellcheck disable=SC1091
source /usr/lib/hassio-addons/base.sh
# Start Tautulli
hass.log.info "Starting Tautulli..."
bashio::log.info "Starting Tautulli..."
exec \
python /opt/Tautulli.py \
--datadir /data \