PREIN
/bin/sh
/etc/init.d/postgresql restart
POSTIN
/bin/sh
export CATALINA_HOME=/usr/share/tomcat6/
# Do this if we are intalling, not upgrading
if [ $1 = 1 ]; then
cat > /tmp/create_db.sql << EOF
CREATE ROLE tad LOGIN PASSWORD 'tad' SUPERUSER CREATEDB CREATEROLE VALID UNTIL 'infinity';
UPDATE pg_authid SET rolcatupdate=true WHERE rolname='tad';
CREATE DATABASE openbravo WITH TEMPLATE = template0 ENCODING = 'UTF8' OWNER=tad;
EOF
echo "Creating DB..."
/usr/bin/psql -d postgres -U postgres -h 127.0.0.1 -p 5432 -f /tmp/create_db.sql
echo "Restoring dump..."
/usr/bin/pg_restore -C -i -U tad -d openbravo -h 127.0.0.1 -p 5432 -O /usr/src/openbravo/tad_pgsql.dump
fi
# Upgrading
if [ $1 = 2 ]; then
pushd /usr/src/openbravo
echo "Updating database..."
JAVA_HOME=/usr/lib/jvm/java-rpmbuild ant update.database
JAVA_HOME=/usr/lib/jvm/java-rpmbuild ant smartbuild -Dlocal=no
popd
fi
echo "Vaccuming..."
/usr/bin/vacuumdb -f -z -h '127.0.0.1' -d 'openbravo' -U 'tad'
# Not really sure, because of files sections
/bin/chown tomcat.tomcat /var/lib/tomcat6/webapps/openbravo -Rf
cat /usr/src/openbravo/README.mandriva