mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-02 13:54:05 +02:00
Update 99-run.sh
This commit is contained in:
@@ -35,10 +35,42 @@ if bashio::config.true "test"; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Create symlink
|
# Create symlink
|
||||||
rm /data/config.yaml
|
[ -f /data/config.yaml ] && rm /data/config.yaml
|
||||||
ln -s $CONFIGSOURCE /data
|
ln -s $CONFIGSOURCE /data
|
||||||
echo "Symlink created"
|
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
|
fi
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
|||||||
Reference in New Issue
Block a user