yum install -y yum-utils

# Install PostgreSQL repo
if [ -f /etc/fedora-release ] ; then
	yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/F-29-x86_64/pgdg-fedora-repo-latest.noarch.rpm
else
	yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
fi

# Install PostgreSQL
yum install -y postgresql12 postgresql12-server

# Initialize PostgreSQL database
/usr/pgsql-12/bin/postgresql-12-setup initdb

# Allow trust connection from localhost
sed -i 's/ident/trust/g' /var/lib/pgsql/12/data/pg_hba.conf

# Autostart PostgreSQL
systemctl enable postgresql-12

# Run PostgreSQL
systemctl start postgresql-12