mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-06 07:35:56 +02:00
Allow both configs
https://github.com/alexbelgium/hassio-addons/issues/1163#issuecomment-1881771328
This commit is contained in:
@@ -9,6 +9,15 @@ set -e
|
|||||||
# For all keys in options.json
|
# For all keys in options.json
|
||||||
JSONSOURCE="/data/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
|
# Export keys as env variables
|
||||||
# echo "All addon options were exported as variables"
|
# echo "All addon options were exported as variables"
|
||||||
mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}")
|
mapfile -t arr < <(jq -r 'keys[]' "${JSONSOURCE}")
|
||||||
@@ -27,11 +36,16 @@ for KEYS in "${arr[@]}"; do
|
|||||||
if [[ "${line}" == *'!secret '* ]]; then
|
if [[ "${line}" == *'!secret '* ]]; then
|
||||||
echo "secret detected"
|
echo "secret detected"
|
||||||
secret=${line#*secret }
|
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
|
# 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"
|
[[ "$secretnum" == *' '* ]] && bashio::exit.nok "There are multiple matches for your password name. Please check your secrets.yaml file"
|
||||||
# Get text
|
# Get text
|
||||||
secret=$(sed -n "/$secret:/p" /config/secrets.yaml)
|
secret=$(sed -n "/$secret:/p" "$SECRETSOURCE" )
|
||||||
secret=${secret#*: }
|
secret=${secret#*: }
|
||||||
line="${line%%=*}='$secret'"
|
line="${line%%=*}='$secret'"
|
||||||
VALUE="$secret"
|
VALUE="$secret"
|
||||||
|
|||||||
Reference in New Issue
Block a user