Escape quotes within variable

https://github.com/alexbelgium/hassio-addons/issues/1933#issuecomment-3034813782
This commit is contained in:
Alexandre
2025-07-04 09:54:56 +02:00
committed by GitHub
parent 5004d07bc1
commit 115f5c6a3c

View File

@@ -188,21 +188,21 @@ while IFS= read -r line; do
# 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 "${KEYS}=${VALUE//\"/\\\"}" >>/.env; fi
mkdir -p /etc
echo "${KEYS}=${VALUE}" >>/etc/environment
echo "${KEYS}=${VALUE//\"/\\\"}" >>/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 ${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
# 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='%s'\n" "$KEYS" "${VALUE//\"/\\\"}" >>/etc/environment; fi
echo "export ${KEYS}=${VALUE//\"/\\\"}" >>~/.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 "${KEYS}=${VALUE//\"/\\\"}"; fi
else
bashio::log.red "${KEYS}=${VALUE} does not follow the correct structure. Please check your yaml file."
fi