2010-11-04 02:46:38 +07:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# $Id: ImportAdempiere.sh,v 1.10 2005/12/20 07:12:17 jjanke Exp $
|
2012-06-06 21:13:34 +07:00
|
|
|
echo idempiere Database Import $Revision: 1.10 $
|
2010-11-04 02:46:38 +07:00
|
|
|
|
2013-04-27 00:09:28 +07:00
|
|
|
echo Importing idempiere DB from $IDEMPIERE_HOME/data/seed/Adempiere$5.dmp
|
2010-11-04 02:46:38 +07:00
|
|
|
|
2010-12-16 15:53:12 +07:00
|
|
|
if [ $# -le 2 ]
|
2010-11-04 02:46:38 +07:00
|
|
|
then
|
|
|
|
echo "Usage: $0 <systemAccount> <AdempiereID> <AdempierePWD> <PostgresPwd>"
|
2012-06-06 21:13:34 +07:00
|
|
|
echo "Example: $0 postgres idempiere idempiere postgresPwd"
|
2010-11-04 02:46:38 +07:00
|
|
|
exit 1
|
|
|
|
fi
|
2012-06-06 21:13:34 +07:00
|
|
|
if [ "$IDEMPIERE_HOME" = "" -o "$ADEMPIERE_DB_NAME" = "" -o "$ADEMPIERE_DB_SERVER" = "" -o "$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"
|
|
|
|
echo " ADEMPIERE_DB_NAME e.g. idempiere"
|
|
|
|
echo " ADEMPIERE_DB_SERVER e.g. dbserver.idempiere.org"
|
|
|
|
echo " ADEMPIERE_DB_PORT e.g. 5432"
|
2010-11-04 02:46:38 +07:00
|
|
|
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
|
|
|
|
|
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
|
|
|
|
ROOT_ROLE="CREATEDB IN ROLE rds_superuser, adempiere"
|
|
|
|
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
|
|
|
|
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U $2 $ADEMPIERE_DB_NAME
|
|
|
|
else
|
2018-11-16 23:36:07 +07:00
|
|
|
if [ "x$2" != xadempiere ]
|
|
|
|
then
|
|
|
|
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres -c "CREATE ROLE adempiere"
|
|
|
|
fi
|
|
|
|
if [ $ISAMAZONRDS = Y ]
|
|
|
|
then
|
|
|
|
PGPASSWORD=$3
|
|
|
|
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U $2 $ADEMPIERE_DB_NAME
|
|
|
|
PGPASSWORD=$4
|
|
|
|
else
|
|
|
|
dropdb -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -U postgres $ADEMPIERE_DB_NAME
|
|
|
|
fi
|
2014-04-15 01:06:49 +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"
|
|
|
|
fi
|
2010-11-04 02:46:38 +07:00
|
|
|
ADEMPIERE_CREATE_ROLE_SQL=
|
|
|
|
|
|
|
|
PGPASSWORD=$3
|
|
|
|
export PGPASSWORD
|
2014-04-15 01:06:49 +07:00
|
|
|
createdb -T template0 -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -E UNICODE -O $2 -U $2 $ADEMPIERE_DB_NAME
|
2010-11-04 02:46:38 +07:00
|
|
|
|
|
|
|
echo -------------------------------------
|
2013-04-27 00:09:28 +07:00
|
|
|
echo Import Adempiere$5.dmp
|
2010-11-04 02:46:38 +07:00
|
|
|
echo -------------------------------------
|
2011-01-11 16:35:01 +07:00
|
|
|
ADEMPIERE_ALTER_ROLE_SQL="ALTER ROLE $2 SET search_path TO adempiere, pg_catalog"
|
2010-11-04 02:46:38 +07:00
|
|
|
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -c "$ADEMPIERE_ALTER_ROLE_SQL"
|
2013-04-27 00:09:28 +07:00
|
|
|
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -f $IDEMPIERE_HOME/data/seed/Adempiere$5.dmp
|
2010-11-04 02:46:38 +07:00
|
|
|
ADEMPIERE_ALTER_ROLE_SQL=
|
|
|
|
PGPASSWORD=
|
|
|
|
export PGPASSWORD
|