From 0f0891b28642177f12b040e3539d28ef413c606d Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Mon, 8 Jan 2024 21:53:50 +0100 Subject: [PATCH] Allow both configs https://github.com/alexbelgium/hassio-addons/issues/1163#issuecomment-1881771328 --- .templates/00-global_var.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.templates/00-global_var.sh b/.templates/00-global_var.sh index 001317cea..05ccc346e 100755 --- a/.templates/00-global_var.sh +++ b/.templates/00-global_var.sh @@ -9,6 +9,15 @@ set -e # For all keys in options.json JSONSOURCE="/data/options.json" +# Define secrets location +if [ -f /homeassistant/secrets.yaml ]; then + SECRETSOURCE="/homeassistant/secrets.yaml" +elif [ -f /config/secrets.yaml ]; then + SECRETSOURCE="/config/secrets.yaml" +else + SECRETSOURCE="false" +fi + # Export keys as env variables # echo "All addon options were exported as variables" mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}") @@ -27,11 +36,16 @@ for KEYS in "${arr[@]}"; do if [[ "${line}" == *'!secret '* ]]; then echo "secret detected" secret=${line#*secret } + # Stop if secret file not mounted + if [[ "$SECRETSOURCE" == "false" ]; then + bashio::log.warning "Homeassistant config not mounted, secrets are not supported" + continue + fi # Check if single match - secretnum=$(sed -n "/$secret:/=" /config/secrets.yaml) + secretnum=$(sed -n "/$secret:/=" "$SECRETSOURCE" ) [[ "$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" "$SECRETSOURCE" ) secret=${secret#*: } line="${line%%=*}='$secret'" VALUE="$secret"