From 3289857e8caaf2347f7a48cc9e241c3a5c0041ce Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 17 Nov 2021 22:52:21 +0100 Subject: [PATCH] Update 99-run.sh --- enedisgateway2mqtt/rootfs/scripts/99-run.sh | 60 +++++++++++++-------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/enedisgateway2mqtt/rootfs/scripts/99-run.sh b/enedisgateway2mqtt/rootfs/scripts/99-run.sh index 51768f898..7c55a9463 100644 --- a/enedisgateway2mqtt/rootfs/scripts/99-run.sh +++ b/enedisgateway2mqtt/rootfs/scripts/99-run.sh @@ -1,37 +1,51 @@ #!/usr/bin/env bashio +################## +# INITIALIZATION # +################## + # Where is the config CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION") +DATABASESOURCE=$(dirname "${CONFIGSOURCE}")/database.sqlite + +# Remoce config in data if existing +[ -f /data/config.yaml ] && rm /data/config.yaml # Check if config file is there, or create one from template if [ -f $CONFIGSOURCE ]; then - echo "Using config file found in $CONFIGSOURCE" + ln -s $CONFIGSOURCE /data + bashio::log.info "Using config file found in $CONFIGSOURCE" + + # Check if yaml is valid + yamllint -d relaxed --no-warnings $CONFIGSOURCE &> ERROR || EXIT_CODE=$? + if [ $EXIT_CODE = 0 ]; then + echo "Config file is a valid yaml" + else + cat ERROR + bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above." + bashio::exit.nok + fi else - echo "No config file, creating one from template" - # Create folder + # Create symlink for addon to create config mkdir -p "$(dirname "${CONFIGSOURCE}")" - # Placing template in config - cp /data/config.yaml "$(dirname "${CONFIGSOURCE}")" &>/dev/null \ - || cp /templates/config.yaml "$(dirname "${CONFIGSOURCE}")" + touch ${CONFIGSOURCE} + ln -s $CONFIGSOURCE /data + rm $CONFIGSOURCE # Need to restart - bashio::log.fatal "Config file not found, creating a new one. Please customize the file in $CONFIGSOURCE before restarting." - bashio::exit.nok + bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting." fi -# Check if yaml is valid -#yamllint -d relaxed --no-warnings $CONFIGSOURCE &> ERROR || EXIT_CODE=$? -#if [ $EXIT_CODE = 0 ]; then -# echo "Config file is a valid yaml" -#else -# cat ERROR -# bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above." -# bashio::exit.nok -#fi - -# Create symlink -[ -f /data/config.yaml ] && rm /data/config.yaml -ln -s $CONFIGSOURCE /data -echo "Symlink created" +# Check if database is here or create symlink +if [ -f $DATABASESOURCE ]; then + ln -s $CONFIGSOURCE /data + bashio::log.info "Using database file found in $DATABASESOURCE" +else + # Create symlink for addon to create database + mkdir -p "$(dirname "${DATABASESOURCE}")" + touch ${DATABASESOURCE} + ln -s $DATABASESOURCE /data + rm $DATABASESOURCE +fi ############## # Launch App # @@ -40,7 +54,7 @@ echo " " bashio::log.info "Starting the app" echo " " -echo "TZ is $TZ" +# Test mode if [ $(bashio::config "TZ") = "test" ]; then echo "secret mode found" cd /config