2024-01-12 11:12:27 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-01-22 17:21:01 +01:00
|
|
|
write_config_file()
|
|
|
|
{
|
|
|
|
FILE=$1
|
|
|
|
ENGINE=$2
|
|
|
|
DATABASE=$3
|
|
|
|
USER=$4
|
|
|
|
PASS=$5
|
|
|
|
|
|
|
|
echo '%dbconfig= (' >> $FILE;
|
|
|
|
echo " connection => \"${ENGINE}:dbname=${DATABASE}\"," >> $FILE
|
|
|
|
echo " user => \"$USER\"," >> $FILE
|
|
|
|
echo " password => \"$PASS\"" >> $FILE
|
|
|
|
echo ');' >> $FILE
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CONFIGDBFILE=/opt/fhem/configDB.conf
|
|
|
|
LOGDBFILE=/opt/fhem/db.conf
|
|
|
|
|
2024-01-12 11:12:27 +01:00
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
if [ -z ${CONFIG_DATABASE_ENGINE} ]; then
|
|
|
|
CONFIG_DATABASE_ENGINE=sqlite
|
2024-01-12 11:12:27 +01:00
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
if [ -z ${CONFIG_DATABASE} ]; then
|
|
|
|
CONFIG_DATABASE="/opt/fhem/configDB.db"
|
|
|
|
fi
|
2024-01-12 11:12:27 +01:00
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
fi
|
2024-01-12 11:12:27 +01:00
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
if [ -z ${CONFIG_DATABASE} ]; then
|
|
|
|
echo "please provide CONFIG_DATABASE name"
|
|
|
|
exit 255
|
|
|
|
fi
|
2024-01-12 11:12:27 +01:00
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
if [ "${CONFIG_DATABASE_ENGINE}" == "sqlite" ]; then
|
2024-01-22 17:21:01 +01:00
|
|
|
|
|
|
|
write_config_file "${CONFIGDBFILE}" "SQLite" "${CONFIG_DATABASE}" "" "";
|
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
elif [ "${CONFIG_DATABASE_ENGINE}" == "mysql" ]; then
|
|
|
|
|
|
|
|
if [ -z ${CONFIG_DATABASE_USER} ]; then
|
|
|
|
echo "please provide CONFIG_DATABASE_USER "
|
2024-01-12 11:12:27 +01:00
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
if [ -z ${CONFIG_DATABASE_PASS} ]; then
|
|
|
|
echo "please provide CONFIG_DATABASE_PASS"
|
2024-01-21 13:44:37 +01:00
|
|
|
exit 255
|
2024-01-12 11:12:27 +01:00
|
|
|
fi
|
|
|
|
|
2024-01-22 17:21:01 +01:00
|
|
|
write_config_file "${CONFIGDBFILE}" "mysql", "${CONFIG_DATABASE}" "${CONFIG_DATABASE_USER}" "${CONFIG_DATABASE_PASS}"
|
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
else
|
|
|
|
echo "unknown database engine provided in CONFIG_DATABASE_ENGINE"
|
|
|
|
exit 255
|
2024-01-12 11:12:27 +01:00
|
|
|
fi
|
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
if [ -z ${LOG_DATABASE_ENGINE} ]; then
|
|
|
|
LOG_DATABASE_ENGINE=sqlite
|
2024-01-12 11:12:27 +01:00
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
if [ -z ${LOG_DATABASE} ]; then
|
|
|
|
LOG_DATABASE="/opt/fhem/logdb.db"
|
|
|
|
fi
|
2024-01-12 11:12:27 +01:00
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
fi
|
2024-01-12 11:12:27 +01:00
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
if [ -z ${LOG_DATABASE} ]; then
|
|
|
|
echo "please provide LOG_DATABASE name"
|
|
|
|
exit 255
|
|
|
|
fi
|
2024-01-12 11:12:27 +01:00
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
|
|
|
|
if [ "${LOG_DATABASE_ENGINE}" == "sqlite" ]; then
|
2024-01-22 17:21:01 +01:00
|
|
|
|
|
|
|
write_config_file "${LOGDBFILE}" "SQLite" "${LOG_DATABASE}" "" ""
|
|
|
|
|
|
|
|
elif [ "${LOG_DATABASE_ENGINE}" == "mysql" ]; then
|
2024-01-21 22:52:45 +01:00
|
|
|
|
|
|
|
if [ -z ${LOG_DATABASE_USER} ]; then
|
|
|
|
echo "please provide LOG_DATABASE_USER "
|
2024-01-12 11:12:27 +01:00
|
|
|
exit 255
|
|
|
|
fi
|
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
if [ -z ${LOG_DATABASE_PASS} ]; then
|
|
|
|
echo "please provide LOG_DATABASE_PASS "
|
2024-01-21 13:44:37 +01:00
|
|
|
exit 255
|
2024-01-12 11:12:27 +01:00
|
|
|
fi
|
|
|
|
|
2024-01-22 17:21:01 +01:00
|
|
|
write_config_file "${LOGDBFILE}" "mysql" "${LOG_DATABASE}" "${LOG_DATABASE_USER}" "${LOG_DATABASE_PASS}"
|
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
else
|
|
|
|
echo "unknown database engine provided in LOG_DATABASE_ENGINE"
|
|
|
|
exit 255
|
2024-01-12 11:12:27 +01:00
|
|
|
fi
|
|
|
|
|
2024-01-21 22:52:45 +01:00
|
|
|
|
2024-01-12 11:12:27 +01:00
|
|
|
export FHEM_GLOBALATTR="nofork=1 updateInBackground=1 logfile=/dev/stdout"
|
|
|
|
cd /opt/fhem || exit 255
|
2024-01-22 17:21:01 +01:00
|
|
|
./fhem.pl configDB
|