Fix postgres users when re-provisioning

If we run provision.py a second time, there will already be
zulip/zulip_test users, so the CREATE USER will fail and the password
won't get updated to the newly generated value. By creating the user
and setting the password in two commands, we allow the creation to
fail without affecting whether the password is set.

Also the quoting for updating .pgpass was wrong.

(imported from commit 5e249813c17cb4829e4e4958e92aaa30563c5f96)
This commit is contained in:
Reid Barton 2015-08-20 15:29:48 -07:00 committed by Tim Abbott
parent dd8eda4edc
commit 748f931999
1 changed files with 3 additions and 2 deletions

View File

@ -29,7 +29,8 @@ fi
DBNAME_BASE=${DBNAME}_base
$ROOT_POSTGRES $DEFAULT_DB << EOF
CREATE USER $USERNAME WITH PASSWORD '$PASSWORD';
CREATE USER $USERNAME;
ALTER USER $USERNAME PASSWORD '$PASSWORD';
ALTER USER $USERNAME CREATEDB;
ALTER ROLE $USERNAME SET search_path TO $SEARCH_PATH;
@ -53,7 +54,7 @@ PGPASS_ESCAPED_PREFIX="*:\*:\*:$USERNAME:"
if ! $(grep -q "$PGPASS_ESCAPED_PREFIX" ~/.pgpass); then
echo $PGPASS_PREFIX$PASSWORD >> ~/.pgpass
else
sed -i 's/$PGPASS_ESCAPED_PREFIX.*$/$PGPASS_PREFIX$PASSWORD/' ~/.pgpass
sed -i "s/$PGPASS_ESCAPED_PREFIX.*\$/$PGPASS_PREFIX$PASSWORD/" ~/.pgpass
fi
chmod go-rw ~/.pgpass