onlyoffice-docserver/images/onlyoffice-docserver/root/entrypoint.d/20-sql.sh

39 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
set -euo pipefail
export PGHOST=${OO_DB_HOST}
export DGPORT=${OO_DB_PORT}
export PGDATABASE=${OO_DB_NAME}
export PGUSER=${OO_DB_USER}
export PGPASSWORD=${OO_DB_PASS}
function init_db(){
psql -f /var/www/onlyoffice/documentserver/server/schema/postgresql/createdb.sql
}
function reset_db(){
psql -f /var/www/onlyoffice/documentserver/server/schema/postgresql/removetbl.sql
}
function write_version(){
echo $(rpm -q onlyoffice-documentserver --qf "%{VERSION}-%{RELEASE}") > /var/lib/onlyoffice/documentserver/App_Data/onlyoffice.version
}
if [ ! -e "/var/lib/onlyoffice/documentserver/App_Data/onlyoffice.version" ]; then
echo "File /var/lib/onlyoffice/documentserver/App_Data/onlyoffice.version doesn't exist, initializing database"
init_db
write_version
else
PREVIOUS_VERSION=$(head -n 1 /var/lib/onlyoffice/documentserver/App_Data/onlyoffice.version)
CURRENT_VERSION=$(rpm -q onlyoffice-documentserver --qf "%{VERSION}-%{RELEASE}")
if [ "${CURRENT_VERSION}" != "${PREVIOUS_VERSION}" ]; then
echo "Running ${CURRENT_VERSION} while previous version was ${PREVIOUS_VERSION}. Reinitializing database"
reset_db
init_db
write_version
else
echo "Running ${CURRENT_VERSION}, same as previous version"
fi
fi