Update 99-run.sh

This commit is contained in:
Alexandre
2021-11-15 22:58:54 +01:00
committed by GitHub
parent 3927131b8e
commit 7253ccc913

View File

@@ -35,10 +35,42 @@ if bashio::config.true "test"; then
fi
# Create symlink
rm /data/config.yaml
[ -f /data/config.yaml ] && rm /data/config.yaml
ln -s $CONFIGSOURCE /data
echo "Symlink created"
# Export all yaml entries as env variables
# Helper function
function parse_yaml {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
# Get variables and export
bashio::log.info "Starting the app with the variables in /config/enedisgateway2mqtt"
for word in $(parse_yaml $CONFIGSOURCE); do
# Data validation
if [[ $word =~ ^.+[=].+$ ]]; then
export $word # Export the variable
bashio::log.blue "$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
fi
#################