diff --git a/sbin/dm_create_db.sh b/sbin/dm_create_db.sh index a51acbc0396983747b30deab85b3381a68a17f8e..a91b8bf6f43fc3ec822060bd2690161765f8169f 100755 --- a/sbin/dm_create_db.sh +++ b/sbin/dm_create_db.sh @@ -95,7 +95,11 @@ createDb() { echo "Creating database $DM_DB_NAME" ${PG_DIR}/bin/createdb -U $DM_DB_USER -h $DM_DB_HOST -p $DM_DB_PORT $DM_DB_NAME || return 1 echo "Creating database schema for $DM_DB_NAME" - ${PG_DIR}/bin/psql -U $DM_DB_USER -h $DM_DB_HOST -p $DM_DB_PORT -d $DM_DB_NAME -f $DB_CREATE_SCRIPT || return 1 + dbCreateScript=/tmp/`basename $DB_CREATE_SCRIPT.$$` + cmd="cat $DB_CREATE_SCRIPT | sed 's?OWNER TO.*?OWNER TO $DM_DB_USER;?g' > $dbCreateScript" + eval $cmd + ${PG_DIR}/bin/psql -U $DM_DB_USER -h $DM_DB_HOST -p $DM_DB_PORT -d $DM_DB_NAME -f $dbCreateScript || return 1 + rm -f $dbCreateScript touch $DB_LOCK_FILE } @@ -164,9 +168,12 @@ if [ -z "$DM_DB_USER_PASSWORD" ]; then stty $sttyOrig fi -# Create db user +# Create db user unless we are running this script under the same +# account, when user will be created echo "Creating $DM_DB_USER" -createDbUser $DM_DB_USER -E -d || exit 1 +if [ $DM_DB_USER != `whoami` ]; then + createDbUser $DM_DB_USER -E -d || exit 1 +fi modifyDbUserPassword $DM_DB_USER $DM_DB_USER_PASSWORD || exit 1 # Create db password file