This commit is contained in:
Alexandre
2025-07-07 08:09:56 +02:00
committed by GitHub
parent f99b24eb2d
commit d5854da450

View File

@@ -32,7 +32,6 @@ CONFIGSOURCE="$CONFIGLOCATION"/config.yaml
# Is there a custom path # Is there a custom path
if bashio::config.has_value 'CONFIG_LOCATION'; then if bashio::config.has_value 'CONFIG_LOCATION'; then
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
if [[ "$CONFIGSOURCE" == *.* ]]; then if [[ "$CONFIGSOURCE" == *.* ]]; then
CONFIGSOURCE=$(dirname "$CONFIGSOURCE") CONFIGSOURCE=$(dirname "$CONFIGSOURCE")
@@ -49,7 +48,7 @@ if bashio::config.has_value 'CONFIG_LOCATION'; then
fi fi
done done
if [ -z "$LOCATIONOK" ]; then if [ -z "$LOCATIONOK" ]; then
bashio::log.red "Watch-out : your CONFIG_LOCATION values can only be set in /share, /config or /data (internal to addon). It will be reset to the default location : $CONFIGLOCATION/config.yaml" bashio::log.red "Watch-out: your CONFIG_LOCATION values can only be set in /share, /config or /data (internal to addon). It will be reset to the default location: $CONFIGLOCATION/config.yaml"
CONFIGSOURCE="$CONFIGLOCATION"/config.yaml CONFIGSOURCE="$CONFIGLOCATION"/config.yaml
fi fi
fi fi
@@ -59,7 +58,7 @@ if [[ "$CONFIGLOCATION" == "/config" ]]; then
# Migrate file # Migrate file
if [ -f "/homeassistant/addons_config/${slug}/config.yaml" ] && [ ! -L "/homeassistant/addons_config/${slug}" ]; then if [ -f "/homeassistant/addons_config/${slug}/config.yaml" ] && [ ! -L "/homeassistant/addons_config/${slug}" ]; then
echo "Migrating config.yaml to new config location" echo "Migrating config.yaml to new config location"
mv /homeassistant/addons_config/"${slug}"/config.yaml /config/config.yaml mv "/homeassistant/addons_config/${slug}/config.yaml" /config/config.yaml
fi fi
# Migrate option # Migrate option
if [[ "$(bashio::config "CONFIG_LOCATION")" == "/config/addons_config"* ]] && [ -f /config/config.yaml ]; then if [[ "$(bashio::config "CONFIG_LOCATION")" == "/config/addons_config"* ]] && [ -f /config/config.yaml ]; then
@@ -70,6 +69,7 @@ fi
if [[ "$CONFIGSOURCE" != *".yaml" ]]; then if [[ "$CONFIGSOURCE" != *".yaml" ]]; then
bashio::log.error "Something is going wrong in the config location, quitting" bashio::log.error "Something is going wrong in the config location, quitting"
exit 1
fi fi
# Permissions # Permissions
@@ -91,7 +91,7 @@ else
bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGSOURCE" bashio::log.green "If accessing the file with filebrowser it should be mapped to $CONFIGSOURCE"
fi fi
bashio::log.green "---------------------------------------------------------" bashio::log.green "---------------------------------------------------------"
bashio::log.green "Wiki here on how to use : github.com/alexbelgium/hassio-addons/wiki/Addons-feature-:-add-env-variables" bashio::log.green "Wiki here on how to use: github.com/alexbelgium/hassio-addons/wiki/Add-ons-feature:-add-env-variables"
echo "" echo ""
# Check if config file is there, or create one from template # Check if config file is there, or create one from template
@@ -115,6 +115,7 @@ cp "$CONFIGSOURCE" /tempenv
sed -i '/^#/d' /tempenv sed -i '/^#/d' /tempenv
sed -i '/^[[:space:]]*$/d' /tempenv sed -i '/^[[:space:]]*$/d' /tempenv
sed -i '/^$/d' /tempenv sed -i '/^$/d' /tempenv
# Exit if empty # Exit if empty
if [ ! -s /tempenv ]; then if [ ! -s /tempenv ]; then
bashio::log.green "... no env variables found, exiting" bashio::log.green "... no env variables found, exiting"
@@ -137,6 +138,11 @@ SECRETSFILE="/config/secrets.yaml"
if [ -f "$SECRETSFILE" ]; then SECRETSFILE="/homeassistant/secrets.yaml"; fi if [ -f "$SECRETSFILE" ]; then SECRETSFILE="/homeassistant/secrets.yaml"; fi
while IFS= read -r line; do while IFS= read -r line; do
# Skip empty lines
if [[ -z "$line" ]]; then
continue
fi
# Check if secret # Check if secret
if [[ "${line}" == *'!secret '* ]]; then if [[ "${line}" == *'!secret '* ]]; then
echo "secret detected" echo "secret detected"
@@ -149,6 +155,7 @@ while IFS= read -r line; do
secret=${secret#*: } secret=${secret#*: }
line="${line%%=*}='$secret'" line="${line%%=*}='$secret'"
fi fi
# Data validation # Data validation
if [[ "$line" =~ ^.+[=].+$ ]]; then if [[ "$line" =~ ^.+[=].+$ ]]; then
# extract keys and values # extract keys and values
@@ -158,31 +165,32 @@ while IFS= read -r line; do
if [[ "$VALUE" != \"*\" ]] && [[ "$VALUE" != \'*\' ]]; then if [[ "$VALUE" != \"*\" ]] && [[ "$VALUE" != \'*\' ]]; then
VALUE="\"$VALUE\"" VALUE="\"$VALUE\""
fi fi
line="${KEYS}"="${VALUE}" line="${KEYS}=${VALUE}"
export "$line" export "$line"
# export to python # export to python
if command -v "python3" &>/dev/null; then if command -v "python3" &>/dev/null; then
[ ! -f /env.py ] && echo "import os" >/env.py [ ! -f /env.py ] && echo "import os" > /env.py
# Escape single quotes in VALUE # Escape single quotes in VALUE
VALUE_ESCAPED="${VALUE//\'/\'\"\'\"\'}" VALUE_ESCAPED="${VALUE//\'/\'\"\'\"\'}"
echo "os.environ['${KEYS}'] = '${VALUE_ESCAPED}'" >>/env.py echo "os.environ['${KEYS}'] = '${VALUE_ESCAPED}'" >> /env.py
python3 /env.py python3 /env.py
fi fi
# set .env # set .env
echo "$line" >>/.env echo "$line" >> /.env
# set environement # set environment
mkdir -p /etc mkdir -p /etc
echo "$line" >>/etc/environment echo "$line" >> /etc/environment
# Export to scripts # Export to scripts
if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null; fi if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null; fi
if cat /etc/cont-init.d/*run* &>/dev/null; then sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null; fi if cat /etc/cont-init.d/*run* &>/dev/null; then sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null; fi
# For s6 # For s6
if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" >/var/run/s6/container_environment/"${KEYS}"; fi if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" > /var/run/s6/container_environment/"${KEYS}"; fi
echo "export $line" >>~/.bashrc echo "export $line" >> ~/.bashrc
# Show in log # Show in log
if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi
else else
bashio::log.red "$line does not follow the correct structure. Please check your yaml file." bashio::log.red "Skipping line that does not follow the correct structure: $line"
fi fi
done <"/tempenv" done < "/tempenv"
rm /tempenv rm /tempenv