From d7e89a9788efcdb73837dd3f406664aca176e2ee Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sat, 13 Nov 2021 15:13:37 +0100 Subject: [PATCH] allow custom var --- enedisgateway2mqtt/rootfs/scripts/99-run.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/enedisgateway2mqtt/rootfs/scripts/99-run.sh b/enedisgateway2mqtt/rootfs/scripts/99-run.sh index 29632985e..49a4c6de9 100644 --- a/enedisgateway2mqtt/rootfs/scripts/99-run.sh +++ b/enedisgateway2mqtt/rootfs/scripts/99-run.sh @@ -21,7 +21,8 @@ mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE}) for KEYS in ${arr[@]}; do # if the custom_var field is used if [ "${KEYS}" = "custom_var" ]; then - VALUES=$(jq .$KEYS ${JSONSOURCE}) + VALUES=$(jq .$KEYS ${JSONSOURCE}) # Get list of custom elements + VALUES=${VALUES:1:-1} # Remove first and last "" for SUBKEYS in ${VALUES//,/ }; do [[ ! $SUBKEYS =~ ^.+[=].+$ ]] && bashio::log.fatal "Your custom_var field does not follow the structure KEY=\"text\",KEY2=\"text2\" it will be ignored" && continue || true # Remove the key if already existing @@ -51,9 +52,14 @@ sed -i 's|"|'\''|g' $CONFIGSOURCE # For all keys in config file for word in $(cat $CONFIGSOURCE); do - [[ ! $word =~ ^.+[=].+$ ]] && bashio::log.fatal "$word does not follow the structure KEY=\'text\', it will be ignored" || true - export "$word" # Export the variable - echo "$word" + # Data validation + if [[ $word =~ ^.+[=].+$ ]]; then + export "$word" # Export the variable + echo "$word" + else + bashio::log.fatal "$word does not follow the structure KEY=\'text\', it will be ignored and removed from the config" + sed -i "/$word/ d" ${CONFIGSOURCE} + fi done ##############