This commit is contained in:
2023-08-27 17:33:05 +02:00
parent 798a8932af
commit a7c9ca3f2f
9 changed files with 46 additions and 131 deletions

View File

@@ -1,37 +0,0 @@
#!/command/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: Base Images
# Displays a simple add-on banner on startup
# ==============================================================================
if bashio::supervisor.ping; then
bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue " Add-on: $(bashio::addon.name)"
bashio::log.blue " $(bashio::addon.description)"
bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue " Add-on version: $(bashio::addon.version)"
if bashio::var.true "$(bashio::addon.update_available)"; then
bashio::log.magenta ' There is an update available for this add-on!'
bashio::log.magenta \
" Latest add-on version: $(bashio::addon.version_latest)"
bashio::log.magenta ' Please consider upgrading as soon as possible.'
else
bashio::log.green ' You are running the latest version of this add-on.'
fi
bashio::log.blue " System: $(bashio::info.operating_system)" \
" ($(bashio::info.arch) / $(bashio::info.machine))"
bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)"
bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)"
bashio::log.blue \
'-----------------------------------------------------------'
bashio::log.blue \
' Please, share the above information when looking for help'
bashio::log.blue \
' or support in, e.g., GitHub, forums or the Discord chat.'
bashio::log.blue \
'-----------------------------------------------------------'
fi

View File

@@ -1,46 +0,0 @@
#!/command/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: Base Images
# Sets the log level correctly
# ==============================================================================
declare log_level
# Check if the log level configuration option exists
if bashio::config.exists log_level; then
# Find the matching LOG_LEVEL
log_level=$(bashio::string.lower "$(bashio::config log_level)")
case "${log_level}" in
all)
log_level="${__BASHIO_LOG_LEVEL_ALL}"
;;
trace)
log_level="${__BASHIO_LOG_LEVEL_TRACE}"
;;
debug)
log_level="${__BASHIO_LOG_LEVEL_DEBUG}"
;;
info)
log_level="${__BASHIO_LOG_LEVEL_INFO}"
;;
notice)
log_level="${__BASHIO_LOG_LEVEL_NOTICE}"
;;
warning)
log_level="${__BASHIO_LOG_LEVEL_WARNING}"
;;
error)
log_level="${__BASHIO_LOG_LEVEL_ERROR}"
;;
fatal)
log_level="${__BASHIO_LOG_LEVEL_FATAL}"
;;
off)
log_level="${__BASHIO_LOG_LEVEL_OFF}"
;;
*)
bashio::exit.nok "Unknown log_level: ${log_level}"
esac
bashio::log.blue "Log level is set to ${__BASHIO_LOG_LEVELS[$log_level]}"
fi

View File

@@ -1,11 +0,0 @@
#!/command/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: Base Images
# Configures the timezone
# ==============================================================================
if ! bashio::var.is_empty "${TZ}"; then
bashio::log.info "Configuring timezone"
ln --symbolic --no-dereference --force "/usr/share/zoneinfo/${TZ}" /etc/localtime
echo "${TZ}" > /etc/timezone
fi

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bashio
# ==============================================================================
# Take down the S6 supervision tree when telegraf fails
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# ==============================================================================
declare APP_EXIT_CODE=${1}
if [[ "${APP_EXIT_CODE}" -ne 0 ]] && [[ "${APP_EXIT_CODE}" -ne 256 ]]; then
bashio::log.warning "Halt add-on with exit code ${APP_EXIT_CODE}"
echo "${APP_EXIT_CODE}" > /run/s6-linux-init-container-results/exitcode
exec /run/s6/basedir/bin/halt
fi
bashio::log.info "Service restart after closing"

View File

@@ -0,0 +1,27 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Add-on: telegraf
# Runs telegraf
# ==============================================================================
declare log_level
bashio::log.info 'Starting telegraf...'
bashio::require.unprotected
CONFIGURATION=$(bashio::config 'configuration.location')
bashio::log.info "Using configuration file ${CONFIGURATION}"
rm /etc/telegraf/telegraf.conf
cp "${CONFIGURATION}" /etc/telegraf/telegraf.conf
if [ "${1:0:1}" = '-' ]; then
set -- telegraf "$@"
fi
if [ $EUID -ne 0 ]; then
exec "$@"
else
# Allow telegraf to send ICMP packets and bind to privliged ports
setcap cap_net_raw,cap_net_bind_service+ep /usr/bin/telegraf || echo "Failed to set additional capabilities on /usr/bin/telegraf"
exec setpriv --reuid root --init-groups "$@"
fi