Skip to content

Commit

Permalink
Correct set password in setup DB
Browse files Browse the repository at this point in the history
  • Loading branch information
eloravpn committed Nov 4, 2024
1 parent b8b4c74 commit b376047
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,20 @@ check_postgresql() {

# Setup PostgreSQL database
setup_database() {
log "Setting up PostgreSQL database..."
log "Setting up PostgreSQL database..."

# Generate random password if not set
DB_PASSWORD=${DB_PASSWORD:-$(generate_db_password)}
DB_NAME=${DB_NAME:-"elora_db"}
DB_USER=${DB_USER:-"elora"}

# Ensure PostgreSQL is running
check_postgresql

# Check if user exists
if ! su - postgres -c "psql -tAc \"SELECT 1 FROM pg_roles WHERE rolname='$DB_USER'\"" | grep -q 1; then
log "Creating database user ${DB_USER}..."
su - postgres -c "psql -c \"CREATE USER ${DB_USER} WITH PASSWORD '${DB_PASSWORD}';\""
su - postgres -c "psql -c \"CREATE USER ${DB_USER} WITH LOGIN PASSWORD '${DB_PASSWORD}';\""
else
log "User ${DB_USER} already exists, updating password..."
su - postgres -c "psql -c \"ALTER USER ${DB_USER} WITH PASSWORD '${DB_PASSWORD}';\""
Expand All @@ -268,6 +270,10 @@ setup_database() {
su - postgres -c "psql -c \"ALTER DATABASE ${DB_NAME} OWNER TO ${DB_USER};\""
fi

# Grant privileges
log "Setting up database privileges..."
su - postgres -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE ${DB_NAME} TO ${DB_USER};\""

log "Database setup completed successfully"
}

Expand Down

0 comments on commit b376047

Please sign in to comment.