Postgres: fix detection of existing roles

Role "root" it is hardcode.
In general case role name comes from  local.conf: string  "DATABASE_USER="

Change-Id: Iedfca48e04d23c313851f48d68ac40ba29340805
This commit is contained in:
Anton Merzlyakov 2016-11-30 14:29:18 +03:00
parent 9a69a1abfc
commit ae61e6f3d2

View File

@ -47,7 +47,7 @@ function recreate_database_postgresql {
}
function configure_database_postgresql {
local pg_conf pg_dir pg_hba root_roles version
local pg_conf pg_dir pg_hba check_role version
echo_summary "Configuring and starting PostgreSQL"
if is_fedora; then
pg_hba=/var/lib/pgsql/data/pg_hba.conf
@ -85,8 +85,8 @@ function configure_database_postgresql {
restart_service postgresql
# Create the role if it's not here or else alter it.
root_roles=$(sudo -u root sudo -u postgres -i psql -t -c "SELECT 'HERE' from pg_roles where rolname='root'")
if [[ ${root_roles} == *HERE ]];then
check_role=$(sudo -u root sudo -u postgres -i psql -t -c "SELECT 'HERE' from pg_roles where rolname='$DATABASE_USER'")
if [[ ${check_role} == *HERE ]];then
sudo -u root sudo -u postgres -i psql -c "ALTER ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'"
else
sudo -u root sudo -u postgres -i psql -c "CREATE ROLE $DATABASE_USER WITH SUPERUSER LOGIN PASSWORD '$DATABASE_PASSWORD'"