Skip to content

Commit

Permalink
Merge pull request #413 from jmpsec/improvements-backend-setup
Browse files Browse the repository at this point in the history
Backend can be multiple versions of PostgreSQL
  • Loading branch information
javuto authored Mar 8, 2024
2 parents 14da762 + e4b8756 commit 770dce7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions deploy/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ function db_user_postgresql() {
sudo su - "$__pguser" -c "$__psql -c 'ALTER ROLE $__dbuser WITH CREATEDB'"
sudo su - "$__pguser" -c "$__psql -c 'CREATE DATABASE $__pgdb'"

log "Make user owner of database"
sudo su - "$__pguser" -c "ALTER DATABASE $__pgdb OWNER TO $__dbuser;"

log "Granting privileges to user"
local _dbstatementgrant="GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $__dbuser;"
sudo su - "$__pguser" -c "$__psql -d $__pgdb -c '$_dbstatementgrant'"
Expand Down
29 changes: 25 additions & 4 deletions deploy/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,11 @@ source "$SOURCE_PATH/deploy/lib.sh"

# Detect Linux distro
if [[ -f "/etc/debian_version" ]]; then
DISTRO="ubuntu"
if [[ $(grep -Fxq "Debian" /etc/issue) ]]; then
DISTRO="debian"
else
DISTRO="ubuntu"
fi
elif [[ -f "/etc/centos-release" ]]; then
DISTRO="centos"
fi
Expand Down Expand Up @@ -621,11 +625,28 @@ else
# PostgreSQL - Backend
if [[ "$POSTGRES" == true ]]; then
if [[ "$DISTRO" == "ubuntu" ]]; then
package postgresql-14
# Ubuntu 22.04 uses postgresql 14
if [[ "$(lsb_release -r | cut -f2 | cut -d'.' -f1)" == "22" ]]; then
package postgresql-14
package postgresql-contrib
package postgresql-client-14
POSTGRES_SERVICE="postgresql"
POSTGRES_PSQL="/usr/lib/postgresql/14/bin/psql"
else
# Assuming we are in Ubuntu 20.04, which uses postgresql 12
package postgresql
package postgresql-contrib
package postgresql-client-12
POSTGRES_SERVICE="postgresql"
POSTGRES_PSQL="/usr/lib/postgresql/12/bin/psql"
fi
# Debian uses postgresql 15
elif [[ "$DISTRO" == "debian" ]]; then
package postgresql
package postgresql-contrib
package postgresql-client-14
package postgresql-client-15
POSTGRES_SERVICE="postgresql"
POSTGRES_PSQL="/usr/lib/postgresql/14/bin/psql"
POSTGRES_PSQL="/usr/lib/postgresql/15/bin/psql"
elif [[ "$DISTRO" == "centos" ]]; then
log "For CentOS, please install Postgres 14 manually"
exit $OHNOES
Expand Down

0 comments on commit 770dce7

Please sign in to comment.