update @native
This commit is contained in:
parent
4b6bff7c65
commit
817326dac8
@ -197,21 +197,23 @@ Generate_Config_Native(){
|
||||
ADDONS=${1:-}
|
||||
REPO_NAME=$(basename "$(git rev-parse --show-toplevel)" | sed -E 's/[.-]/_/g')
|
||||
USER="${REPO_NAME:-"default_repo"}"
|
||||
# Convert to lowercase
|
||||
USER="${USER,,}"
|
||||
PASSWORD="$(openssl rand -hex 24)"
|
||||
# Check if the user already exists
|
||||
USER_EXISTS=$(psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -t -A -c "SELECT COUNT(*) FROM pg_roles WHERE rolname='$USER';")
|
||||
|
||||
if [ "$USER_EXISTS" -eq 0 ]; then
|
||||
# User does not exist, create the user
|
||||
Show 2 "Create the new PostgreSQL username: $USER with password: $PASSWORD"
|
||||
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "CREATE USER $USER WITH PASSWORD '$PASSWORD';"
|
||||
Show 2 " Grant $USER superuser (admin) privileges"
|
||||
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "ALTER USER $USER WITH SUPERUSER;"
|
||||
else
|
||||
# User exists, update the password
|
||||
Show 2 "User $USER already exists, updating password to $PASSWORD"
|
||||
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "ALTER USER $USER WITH PASSWORD '$PASSWORD';"
|
||||
fi
|
||||
if [ $USER_EXISTS -eq 0 ]; then
|
||||
# User does not exist, create the user
|
||||
Show 2 "Create the new PostgreSQL username: $USER with password: $PASSWORD"
|
||||
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "CREATE USER $USER WITH PASSWORD '$PASSWORD';"
|
||||
Show 2 "Grant $USER superuser (admin) privileges"
|
||||
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "ALTER USER $USER WITH SUPERUSER;"
|
||||
else
|
||||
# User exists, update the password (do not try to create)
|
||||
Show 2 "User $USER already exists, updating password to $PASSWORD"
|
||||
psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_SERVER}:${DB_PORT}/postgres" -c "ALTER USER $USER WITH PASSWORD '$PASSWORD';"
|
||||
fi
|
||||
${PYTHON} "$SETUP_PATH/gen_config.py" --db_user $USER --db_pass $PASSWORD --deploy_path "$(pwd)" \
|
||||
--addons_path $ADDONS --db_port $DB_PORT --db_server $DB_SERVER
|
||||
Show 0 " Generate Config Complete"
|
||||
|
Loading…
Reference in New Issue
Block a user