2017-02-23 17:53:37 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
#move to script directory so all relative paths work
|
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
|
|
2017-04-23 09:54:20 +02:00
|
|
|
#includes
|
|
|
|
|
. ./config.sh
|
2017-02-23 17:53:37 +01:00
|
|
|
. ./colors.sh
|
|
|
|
|
|
|
|
|
|
#send a message
|
2021-10-06 23:50:51 +02:00
|
|
|
verbose "Installing PostgreSQL"
|
2017-02-23 17:53:37 +01:00
|
|
|
|
|
|
|
|
#generate a random password
|
|
|
|
|
password=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64)
|
|
|
|
|
|
2021-10-06 23:50:51 +02:00
|
|
|
# Install the repository
|
|
|
|
|
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
|
|
|
|
|
|
|
|
|
|
# Install PostgreSQL:
|
|
|
|
|
sudo yum install -y postgresql14-server postgresql14-contrib postgresql14 postgresql14-libs
|
2017-02-23 17:53:37 +01:00
|
|
|
|
2017-04-23 09:54:20 +02:00
|
|
|
#send a message
|
2017-02-23 17:53:37 +01:00
|
|
|
verbose "Initalize PostgreSQL database"
|
2017-04-23 09:54:20 +02:00
|
|
|
|
|
|
|
|
#initialize the database
|
2021-10-06 23:50:51 +02:00
|
|
|
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
|
|
|
|
|
sudo systemctl enable postgresql-14
|
|
|
|
|
sudo systemctl start postgresql-14
|
2017-02-23 17:53:37 +01:00
|
|
|
|
2017-04-23 09:54:20 +02:00
|
|
|
#allow loopback
|
2021-10-07 02:03:48 +02:00
|
|
|
sed -i 's/\(host *all *all *127.0.0.1\/32 *\)ident/\1md5/' /var/lib/pgsql/14/data/pg_hba.conf
|
|
|
|
|
sed -i 's/\(host *all *all *::1\/128 *\)ident/\1md5/' /var/lib/pgsql/14/data/pg_hba.conf
|
2017-02-23 17:53:37 +01:00
|
|
|
|
|
|
|
|
#systemd
|
|
|
|
|
systemctl daemon-reload
|
2021-10-07 02:05:10 +02:00
|
|
|
systemctl restart postgresql-14
|
2017-02-23 17:53:37 +01:00
|
|
|
|
|
|
|
|
#move to /tmp to prevent a red herring error when running sudo with psql
|
|
|
|
|
cwd=$(pwd)
|
|
|
|
|
cd /tmp
|
2017-04-23 09:54:20 +02:00
|
|
|
|
2017-02-23 17:53:37 +01:00
|
|
|
#add the databases, users and grant permissions to them
|
2021-10-07 01:59:39 +02:00
|
|
|
sudo -u postgres /usr/bin/psql -d fusionpbx -c "DROP SCHEMA public cascade;";
|
|
|
|
|
sudo -u postgres /usr/bin/psql -d fusionpbx -c "CREATE SCHEMA public;";
|
|
|
|
|
sudo -u postgres /usr/bin/psql -c "CREATE DATABASE fusionpbx";
|
|
|
|
|
sudo -u postgres /usr/bin/psql -c "CREATE DATABASE freeswitch";
|
|
|
|
|
sudo -u postgres /usr/bin/psql -c "CREATE ROLE fusionpbx WITH SUPERUSER LOGIN PASSWORD '$password';"
|
|
|
|
|
sudo -u postgres /usr/bin/psql -c "CREATE ROLE freeswitch WITH SUPERUSER LOGIN PASSWORD '$password';"
|
|
|
|
|
sudo -u postgres /usr/bin/psql -c "GRANT ALL PRIVILEGES ON DATABASE fusionpbx to fusionpbx;"
|
|
|
|
|
sudo -u postgres /usr/bin/psql -c "GRANT ALL PRIVILEGES ON DATABASE freeswitch to fusionpbx;"
|
|
|
|
|
sudo -u postgres /usr/bin/psql -c "GRANT ALL PRIVILEGES ON DATABASE freeswitch to freeswitch;"
|
2017-02-23 17:53:37 +01:00
|
|
|
#ALTER USER fusionpbx WITH PASSWORD 'newpassword';
|
|
|
|
|
cd $cwd
|
|
|
|
|
|
2017-04-23 09:54:20 +02:00
|
|
|
#send a message
|
2021-10-07 02:03:48 +02:00
|
|
|
verbose "PostgreSQL installed"
|