Update 90-config_yaml.sh

This commit is contained in:
Alexandre
2022-02-17 18:55:41 +01:00
committed by GitHub
parent b3d6e4b7a2
commit 647ad52c0f

View File

@@ -9,7 +9,7 @@
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
# Check if config file is there, or create one from template # Check if config file is there, or create one from template
if [ -f $CONFIGSOURCE ]; then if [ -f "$CONFIGSOURCE" ]; then
echo "Using config file found in $CONFIGSOURCE" echo "Using config file found in $CONFIGSOURCE"
else else
echo "No config file, creating one from template" echo "No config file, creating one from template"
@@ -22,7 +22,7 @@ else
else else
# Download template # Download template
TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template" TEMPLATESOURCE="https://raw.githubusercontent.com/alexbelgium/hassio-addons/master/.templates/config.template"
curl -L -f -s $TEMPLATESOURCE --output $CONFIGSOURCE curl -L -f -s "$TEMPLATESOURCE" --output "$CONFIGSOURCE"
fi fi
# Need to restart # Need to restart
bashio::log.fatal "Config file not found, creating a new one. Please customize the file in $CONFIGSOURCE before restarting." bashio::log.fatal "Config file not found, creating a new one. Please customize the file in $CONFIGSOURCE before restarting."
@@ -34,8 +34,8 @@ chmod -R 755 "$(dirname "${CONFIGSOURCE}")"
# Check if yaml is valid # Check if yaml is valid
EXIT_CODE=0 EXIT_CODE=0
yamllint -d relaxed $CONFIGSOURCE &>ERROR || EXIT_CODE=$? yamllint -d relaxed "$CONFIGSOURCE" &>ERROR || EXIT_CODE=$?
if [ $EXIT_CODE = 0 ]; then if [ "$EXIT_CODE" = 0 ]; then
echo "Config file is a valid yaml" echo "Config file is a valid yaml"
else else
cat ERROR cat ERROR
@@ -70,7 +70,7 @@ bashio::log.info "Starting the app with the variables in in $CONFIGSOURCE"
parse_yaml "$CONFIGSOURCE" "" >/tmpfile parse_yaml "$CONFIGSOURCE" "" >/tmpfile
while IFS= read -r line; do while IFS= read -r line; do
# Clean output # Clean output
line=${line//[\"\']/} line="${line//[\"\']/}"
# Check if secret # Check if secret
if [[ "${line}" == *'!secret '* ]]; then if [[ "${line}" == *'!secret '* ]]; then
echo "secret detected" echo "secret detected"
@@ -84,8 +84,8 @@ while IFS= read -r line; do
line="${line%%=*}='$secret'" line="${line%%=*}='$secret'"
fi fi
# Data validation # Data validation
if [[ $line =~ ^.+[=].+$ ]]; then if [[ "$line" =~ ^.+[=].+$ ]]; then
export $line export "$line"
# Export the variable # Export the variable
sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null || true sed -i "1a export $line" /etc/services.d/*/*run* 2>/dev/null || true
sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null || true sed -i "1a export $line" /etc/cont-init.d/*run* 2>/dev/null || true