pull/470/head
spatialgeobyte 2024-03-17 08:57:16 +02:00
rodzic d9a3df7b00
commit add4d5518c
2 zmienionych plików z 15 dodań i 8 usunięć

Wyświetl plik

@ -610,6 +610,7 @@ function non_root_permission() {
function role_check() {
ROLE_NAME=$1
echo "Creating user $1"
echo -e "\e[32m [Entrypoint] Creating/Updating user \e[1;31m $1 \033[0m"
RESULT=$(su - postgres -c "psql postgres -t -c \"SELECT 1 FROM pg_roles WHERE rolname = '$ROLE_NAME'\"")
COMMAND="ALTER"
if [ -z "$RESULT" ]; then
@ -618,3 +619,13 @@ function role_check() {
}
function role_creation() {
ROLE_NAME=$1
ROLE_STATUS=$2
ROLE_PASS=$3
STATEMENT="$COMMAND USER \"$ROLE_NAME\" WITH ${ROLE_STATUS} ENCRYPTED PASSWORD '$ROLE_PASS';"
echo "$STATEMENT" > /tmp/setup_user.sql
su - postgres -c "psql postgres -f /tmp/setup_user.sql"
rm /tmp/setup_user.sql
}

Wyświetl plik

@ -7,14 +7,10 @@ source /scripts/env-data.sh
# Check user already exists
role_check "$POSTGRES_USER"
STATEMENT="$COMMAND USER \"$POSTGRES_USER\" WITH SUPERUSER ENCRYPTED PASSWORD '$POSTGRES_PASS';"
echo "$STATEMENT" > /tmp/setup_superuser.sql
su - postgres -c "psql postgres -f /tmp/setup_superuser.sql"
rm /tmp/setup_superuser.sql
role_creation ${POSTGRES_USER} SUPERUSER $POSTGRES_PASS
role_check "$REPLICATION_USER"
STATEMENT_REPLICATION="$COMMAND USER \"$REPLICATION_USER\" WITH REPLICATION ENCRYPTED PASSWORD '$REPLICATION_PASS';"
echo "$STATEMENT_REPLICATION" > /tmp/setup_replication.sql
su - postgres -c "psql postgres -f /tmp/setup_replication.sql"
rm /tmp/setup_replication.sql
role_creation ${REPLICATION_USER} REPLICATION ${REPLICATION_PASS}