update repository references and improve script handling

This commit is contained in:
2025-03-19 14:07:51 +01:00
parent 448bd0f6b8
commit 51b0252b0e
40 changed files with 1135 additions and 134 deletions

View File

@@ -7,22 +7,23 @@ set -e
# INITIALIZATION #
##################
# Exit if /config is not mounted
if [ ! -d /config ]; then
# Disable if config not present
if [ ! -d /config ] || ! bashio::supervisor.ping 2>/dev/null; then
echo "..."
exit 0
fi
# Define slug
slug="${HOSTNAME}"
slug="${HOSTNAME/-/_}"
slug="${slug#*_}"
# Check type of config folder
if [ ! -f /config/configuration.yaml ] && [ ! -f /config/configuration.json ]; then
# New config location
CONFIGLOCATION="/config"
CONFIGFILEBROWSER="/addon_configs/$slug/config.yaml"
CONFIGFILEBROWSER="/addon_configs/${HOSTNAME/-/_}/config.yaml"
else
# Legacy config location
slug="${HOSTNAME#*-}"
CONFIGLOCATION="/config/addons_config/${slug}"
CONFIGFILEBROWSER="/homeassistant/addons_config/$slug/config.yaml"
fi
@@ -35,6 +36,9 @@ CONFIGSOURCE="$CONFIGLOCATION"/config.yaml
if bashio::config.has_value 'CONFIG_LOCATION'; then
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
if [[ "$CONFIGSOURCE" == *.* ]]; then
CONFIGSOURCE=$(dirname "$CONFIGSOURCE")
fi
# If does not end by config.yaml, remove trailing slash and add config.yaml
if [[ "$CONFIGSOURCE" != *".yaml" ]]; then
CONFIGSOURCE="${CONFIGSOURCE%/}"/config.yaml
@@ -89,7 +93,7 @@ else
bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGSOURCE"
fi
bashio::log.green "---------------------------------------------------------"
bashio::log.green "Wiki here on how to use : github.com/Mesteriis/hassio-addons-avm/wiki/Addons-feature-:-add-env-variables"
bashio::log.green "Wiki here on how to use : github.com/alexbelgium/hassio-addons/wiki/Addons-feature-:-add-env-variables"
echo ""
# Check if config file is there, or create one from template
@@ -103,7 +107,7 @@ if [ ! -f "$CONFIGSOURCE" ]; then
cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")"
else
# Download template
TEMPLATESOURCE="https://raw.githubusercontent.com/Mesteriis/hassio-addons-avm/master/.templates/config.template"
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template"
curl -f -L -s -S "$TEMPLATESOURCE" --output "$CONFIGSOURCE"
fi
fi
@@ -111,7 +115,7 @@ fi
# Check if there are lines to read
cp "$CONFIGSOURCE" /tempenv
sed -i '/^#/d' /tempenv
sed -i '/^ /d' /tempenv
sed -i '/^[[:space:]]*$/d' /tempenv
sed -i '/^$/d' /tempenv
# Exit if empty
if [ ! -s /tempenv ]; then
@@ -154,6 +158,10 @@ parse_yaml "$CONFIGSOURCE" "" >/tmpfile
# Escape dollars
sed -i 's|$.|\$|g' /tmpfile
# Look where secrets.yaml is located
SECRETSFILE="/config/secrets.yaml"
if [ -f "$SECRETSFILE" ]; then SECRETSFILE="/homeassistant/secrets.yaml"; fi
while IFS= read -r line; do
# Clean output
line="${line//[\"\']/}"
@@ -162,10 +170,10 @@ while IFS= read -r line; do
echo "secret detected"
secret=${line#*secret }
# Check if single match
secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml)
secretnum=$(sed -n "/$secret:/=" "$SECRETSFILE")
[[ $(echo $secretnum) == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
# Get text
secret=$(sed -n "/$secret:/p" /config/secrets.yaml)
secret=$(sed -n "/$secret:/p" "$SECRETSFILE")
secret=${secret#*: }
line="${line%%=*}='$secret'"
fi