2010-11-04 02:46:38 +07:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-09-09 00:37:00 +07:00
|
|
|
echo iDempiere Database Import
|
2010-11-04 02:46:38 +07:00
|
|
|
|
2020-09-09 00:37:00 +07:00
|
|
|
echo Importing iDempiere DB from "$IDEMPIERE_HOME"/data/ExpDat.dmp
|
2010-11-04 02:46:38 +07:00
|
|
|
|
2020-09-09 00:37:00 +07:00
|
|
|
if [ $# -le 2 ]
|
2010-11-04 02:46:38 +07:00
|
|
|
then
|
|
|
|
echo "Usage: $0 <systemAccount> <AdempiereID> <AdempierePWD> <PostgresPWD>"
|
|
|
|
echo "Example: $0 postgres adempiere adempiere postgrespwd"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-09-09 00:37:00 +07:00
|
|
|
if [ "$IDEMPIERE_HOME" = "" ] || [ "$ADEMPIERE_DB_NAME" = "" ] || [ "$ADEMPIERE_DB_SERVER" = "" ] || [ "$ADEMPIERE_DB_PORT" = "" ]
|
2010-11-04 02:46:38 +07:00
|
|
|
then
|
|
|
|
echo "Please make sure that the environment variables are set correctly:"
|
2012-06-06 21:13:34 +07:00
|
|
|
echo " IDEMPIERE_HOME e.g. /idempiere"
|
2010-11-04 02:46:38 +07:00
|
|
|
echo " ADEMPIERE_DB_NAME e.g. adempiere or xe"
|
|
|
|
echo " ADEMPIERE_DB_SERVER e.g. dbserver.adempiere.org"
|
|
|
|
echo " ADEMPIERE_DB_PORT e.g. 5432 or 1521"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-11-16 23:36:07 +07:00
|
|
|
ISAMAZONRDS=N
|
|
|
|
if echo "$ADEMPIERE_DB_SERVER" | grep 'rds.amazonaws.com$' > /dev/null
|
|
|
|
then
|
|
|
|
ISAMAZONRDS=Y
|
|
|
|
fi
|
|
|
|
|
|
|
|
PGPASSWORD=$4
|
|
|
|
export PGPASSWORD
|
|
|
|
if [ "x$4" = "x^TryLocalConnection^" ]
|
|
|
|
then
|
|
|
|
LOCALPG=true # Allow to run this command with user postgres (just useful running configure as root)
|
|
|
|
else
|
|
|
|
LOCALPG=false
|
|
|
|
fi
|
2010-11-04 02:46:38 +07:00
|
|
|
|
|
|
|
PGPASSWORD=$4
|
|
|
|
export PGPASSWORD
|
2014-04-15 01:06:49 +07:00
|
|
|
if [ "x$4" = "x^TryLocalConnection^" ]
|
|
|
|
then
|
|
|
|
LOCALPG=true # Allow to run this command with user postgres (just useful running configure as root)
|
|
|
|
else
|
|
|
|
LOCALPG=false
|
|
|
|
fi
|
|
|
|
|
2010-11-04 02:46:38 +07:00
|
|
|
echo -------------------------------------
|
|
|
|
echo Recreate user and database
|
|
|
|
echo -------------------------------------
|
2018-11-16 23:36:07 +07:00
|
|
|
if [ $ISAMAZONRDS = Y ]
|
|
|
|
then
|
|
|
|
# modified for amazon RDS - doesn't allow SUPERUSER
|
2020-03-09 22:08:29 +07:00
|
|
|
ROOT_ROLE="CREATEDB IN ROLE rds_superuser"
|
2018-11-16 23:36:07 +07:00
|
|
|
else
|
|
|
|
ROOT_ROLE="SUPERUSER"
|
|
|
|
fi
|
|
|
|
ADEMPIERE_CREATE_ROLE_SQL="CREATE ROLE $2 $ROOT_ROLE LOGIN PASSWORD '$3'"
|
2014-04-15 01:06:49 +07:00
|
|
|
if [ $LOCALPG = "true" ]
|
|
|
|
then
|
|
|
|
# Assuming that adempiere role already exists (it was created out there)
|
|
|
|
PGPASSWORD=$3
|
|
|
|
export PGPASSWORD
|
2020-09-09 00:37:00 +07:00
|
|
|
dropdb -h "$ADEMPIERE_DB_SERVER" -p "$ADEMPIERE_DB_PORT" -U "$2" "$ADEMPIERE_DB_NAME"
|
2014-04-15 01:06:49 +07:00
|
|
|
else
|
2018-11-16 23:36:07 +07:00
|
|
|
if [ "x$2" != xadempiere ]
|
|
|
|
then
|
2020-09-09 00:37:00 +07:00
|
|
|
psql -h "$ADEMPIERE_DB_SERVER" -p "$ADEMPIERE_DB_PORT" -U postgres -c "CREATE ROLE adempiere"
|
2018-11-16 23:36:07 +07:00
|
|
|
fi
|
|
|
|
if [ $ISAMAZONRDS = Y ]
|
|
|
|
then
|
|
|
|
PGPASSWORD=$3
|
2020-09-09 00:37:00 +07:00
|
|
|
dropdb -h "$ADEMPIERE_DB_SERVER" -p "$ADEMPIERE_DB_PORT" -U "$2" "$ADEMPIERE_DB_NAME"
|
2018-11-16 23:36:07 +07:00
|
|
|
PGPASSWORD=$4
|
|
|
|
else
|
2020-09-09 00:37:00 +07:00
|
|
|
dropdb -h "$ADEMPIERE_DB_SERVER" -p "$ADEMPIERE_DB_PORT" -U postgres "$ADEMPIERE_DB_NAME"
|
2018-11-16 23:36:07 +07:00
|
|
|
fi
|
2020-09-09 00:37:00 +07:00
|
|
|
dropuser -h "$ADEMPIERE_DB_SERVER" -p "$ADEMPIERE_DB_PORT" -U postgres "$2"
|
|
|
|
psql -h "$ADEMPIERE_DB_SERVER" -p "$ADEMPIERE_DB_PORT" -U postgres -c "$ADEMPIERE_CREATE_ROLE_SQL"
|
2014-04-15 01:06:49 +07:00
|
|
|
fi
|
2010-11-04 02:46:38 +07:00
|
|
|
ADEMPIERE_CREATE_ROLE_SQL=
|
|
|
|
|
|
|
|
PGPASSWORD=$3
|
|
|
|
export PGPASSWORD
|
2020-09-09 00:37:00 +07:00
|
|
|
createdb -h "$ADEMPIERE_DB_SERVER" -p "$ADEMPIERE_DB_PORT" -E UNICODE -T template0 -O "$2" -U "$2" "$ADEMPIERE_DB_NAME"
|
2010-11-04 02:46:38 +07:00
|
|
|
|
|
|
|
echo -------------------------------------
|
2020-09-09 00:37:00 +07:00
|
|
|
echo Import ExpDat.dmp
|
2010-11-04 02:46:38 +07:00
|
|
|
echo -------------------------------------
|
|
|
|
ADEMPIERE_ALTER_ROLE_SQL="ALTER ROLE $2 SET search_path TO adempiere, pg_catalog"
|
2020-09-09 00:37:00 +07:00
|
|
|
psql -h "$ADEMPIERE_DB_SERVER" -p "$ADEMPIERE_DB_PORT" -d "$ADEMPIERE_DB_NAME" -U "$2" -c "$ADEMPIERE_ALTER_ROLE_SQL"
|
|
|
|
psql -h "$ADEMPIERE_DB_SERVER" -p "$ADEMPIERE_DB_PORT" -d "$ADEMPIERE_DB_NAME" -U "$2" -f "$IDEMPIERE_HOME"/data/ExpDat.dmp
|
2010-11-04 02:46:38 +07:00
|
|
|
|
|
|
|
PGPASSWORD=
|
|
|
|
export PGPASSWORD
|