From bd00a77d3bdcc935f170a47ab6d133b7b8c89b33 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Fri, 4 Jul 2025 13:28:53 +0200 Subject: [PATCH] Update 01-config_yaml.sh --- .templates/01-config_yaml.sh | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/.templates/01-config_yaml.sh b/.templates/01-config_yaml.sh index 542efd160..6be190683 100644 --- a/.templates/01-config_yaml.sh +++ b/.templates/01-config_yaml.sh @@ -163,6 +163,8 @@ SECRETSFILE="/config/secrets.yaml" if [ -f "$SECRETSFILE" ]; then SECRETSFILE="/homeassistant/secrets.yaml"; fi while IFS= read -r line; do + # Clean output + line="${line//[\"\']/}" # Check if secret if [[ "${line}" == *'!secret '* ]]; then echo "secret detected" @@ -180,30 +182,27 @@ while IFS= read -r line; do # extract keys and values KEYS="${line%%=*}" VALUE="${line#*=}" - if [[ "$VALUE" == \"*\"*\" ]]; then - VALUE="${VALUE:1:-1}" - VALUE="\"$VALUE\"" - fi - export "${KEYS}=${VALUE}" + line="${KEYS}='${VALUE}'" + export "$line" # export to python if command -v "python3" &>/dev/null; then [ ! -f /env.py ] && echo "import os" >/env.py - echo "os.environ['${KEYS}'] = \"${VALUE//\"/\\\"}\"" >>/env.py + echo "os.environ['${KEYS}'] = '${VALUE//[\"\']/}'" >>/env.py python3 /env.py fi # set .env - if [ -f /.env ]; then echo "${KEYS}=${VALUE//\"/\\\"}" >>/.env; fi + if [ -f /.env ]; then echo "$line" >>/.env; fi mkdir -p /etc - echo "${KEYS}=${VALUE//\"/\\\"}" >>/etc/environment + echo "$line" >>/etc/environment # Export to scripts - if cat /etc/services.d/*/*run* &>/dev/null; then sed -i "1a export ${KEYS}=${VALUE//\"/\\\"}" /etc/services.d/*/*run* 2>/dev/null; fi - if cat /etc/cont-init.d/*run* &>/dev/null; then sed -i "1a export ${KEYS}=${VALUE//\"/\\\"}" /etc/cont-init.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 # For s6 - if [ -d /var/run/s6/container_environment ]; then printf "%s='%s'\n" "$KEYS" "${VALUE//\"/\\\"}" >>/etc/environment; fi - echo "export ${KEYS}=${VALUE//\"/\\\"}" >>~/.bashrc + if [ -d /var/run/s6/container_environment ]; then printf "%s" "${VALUE}" >/var/run/s6/container_environment/"${KEYS}"; fi + echo "export $line" >>~/.bashrc # Show in log - if ! bashio::config.false "verbose"; then bashio::log.blue "${KEYS}=${VALUE//\"/\\\"}"; fi + if ! bashio::config.false "verbose"; then bashio::log.blue "$line"; fi else - bashio::log.red "${KEYS}=${VALUE} does not follow the correct structure. Please check your yaml file." + bashio::log.red "$line does not follow the correct structure. Please check your yaml file." fi done <"/tmpfile"