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

View file

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

View file

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