From 9846275912401c76fa3bb276dd011c19f2d9a9aa Mon Sep 17 00:00:00 2001 From: Timo Reimann Date: Fri, 21 Oct 2022 19:43:21 +0200 Subject: [PATCH] Add possibility to pass sqlite flag using Home Assistant Addon config.json (#4884) * Add possibility to pass sqlite flag using Home Assistant Addon config.json * Update CONFIG initialisation, as the current grep-cut-sed does not support more than one entry inside options.json update to pure regex grep * Fix updated CONFIG initialisation * Swapped if-else-Statement as suggested by @Hofyyy Co-authored-by: Reimann, Timo --- docker/bin/entrypoint.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/docker/bin/entrypoint.sh b/docker/bin/entrypoint.sh index 98ac5e420..280929f31 100755 --- a/docker/bin/entrypoint.sh +++ b/docker/bin/entrypoint.sh @@ -5,15 +5,22 @@ set -e HASSIO_OPTIONSFILE=/data/options.json if [ -f ${HASSIO_OPTIONSFILE} ]; then - CONFIG=$(grep config_file ${HASSIO_OPTIONSFILE}| cut -d ':' -f 2 | sed s/[\"}]//g ) + CONFIG=$(grep -o '"config_file": "[^"]*' ${HASSIO_OPTIONSFILE} | grep -o '[^"]*$') echo "Using config file: ${CONFIG}" - if [ ! -f ${CONFIG} ]; then + SQLITE_FILE=$(grep -o '"sqlite_file": "[^"]*' ${HASSIO_OPTIONSFILE} | grep -o '[^"]*$') + + if [ ! -f "${CONFIG}" ]; then echo "Config not found. Please create a config under ${CONFIG}." echo "For details see evcc documentation at https://github.com/evcc-io/evcc#readme." else - echo "starting evcc: 'evcc --config ${CONFIG}'" - exec evcc --config ${CONFIG} + if [ "${SQLITE_FILE}" ]; then + echo "starting evcc: 'evcc --config ${CONFIG} --sqlite ${SQLITE_FILE}'" + exec evcc --config "${CONFIG}" --sqlite "${SQLITE_FILE}" + else + echo "starting evcc: 'evcc --config ${CONFIG}'" + exec evcc --config "${CONFIG}" + fi fi else if [ "$1" == '"evcc"' ] || expr "$1" : '-*' > /dev/null; then