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 <timo.reimann@eventim.de>
This commit is contained in:
Timo Reimann 2022-10-21 19:43:21 +02:00 • committed by GitHub
parent f9c217abfd
commit 9846275912
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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