2016-04-29 13:24:22 -06:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
2017-03-04 12:56:38 -07:00
|
|
|
#move to script directory so all relative paths work
|
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
|
|
|
|
|
|
#includes
|
|
|
|
|
. ./config.sh
|
2017-03-05 10:45:03 -07:00
|
|
|
. ./colors.sh
|
2018-12-12 02:06:19 +01:00
|
|
|
. ./environment.sh
|
2017-03-04 12:56:38 -07:00
|
|
|
|
2016-04-29 13:24:22 -06:00
|
|
|
#send a message
|
|
|
|
|
echo "Install PostgreSQL"
|
|
|
|
|
|
|
|
|
|
#generate a random password
|
|
|
|
|
password=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64)
|
|
|
|
|
|
2017-01-11 12:39:05 -07:00
|
|
|
#install message
|
2016-04-29 13:24:22 -06:00
|
|
|
echo "Install PostgreSQL and create the database and users\n"
|
2017-01-11 12:39:05 -07:00
|
|
|
|
|
|
|
|
#included in the distribution
|
2017-03-04 13:20:01 -07:00
|
|
|
if [ ."$database_repo" = ."system" ]; then
|
2019-02-17 09:29:57 -07:00
|
|
|
apt-get install -y sudo postgresql
|
2017-03-04 13:22:57 -07:00
|
|
|
fi
|
2017-01-11 12:39:05 -07:00
|
|
|
|
|
|
|
|
#postgres official repository
|
2017-03-04 13:22:57 -07:00
|
|
|
if [ ."$database_repo" = ."official" ]; then
|
2018-01-03 18:56:37 -07:00
|
|
|
echo "deb http://apt.postgresql.org/pub/repos/apt/ $os_codename-pgdg main" > /etc/apt/sources.list.d/postgresql.list
|
2017-03-04 13:20:01 -07:00
|
|
|
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
|
|
|
|
|
apt-get update && apt-get upgrade -y
|
2017-11-06 17:55:38 -07:00
|
|
|
if [ ."$database_version" = ."latest" ]; then
|
2019-02-17 09:29:57 -07:00
|
|
|
apt-get install -y sudo postgresql
|
2017-11-06 19:57:35 -07:00
|
|
|
fi
|
|
|
|
|
if [ ."$database_version" = ."9.6" ]; then
|
2019-02-17 09:29:57 -07:00
|
|
|
apt-get install -y sudo postgresql-$database_version
|
2018-05-17 19:15:37 -06:00
|
|
|
fi
|
|
|
|
|
if [ ."$database_version" = ."9.4" ]; then
|
2019-02-17 09:29:57 -07:00
|
|
|
apt-get install -y sudo postgresql-$database_version
|
2017-11-06 17:55:38 -07:00
|
|
|
fi
|
2017-03-04 13:20:01 -07:00
|
|
|
fi
|
2016-04-29 13:24:22 -06:00
|
|
|
|
2017-11-06 17:55:38 -07:00
|
|
|
#add PostgreSQL and 2ndquadrant repos
|
2017-03-04 13:22:57 -07:00
|
|
|
if [ ."$database_repo" = ."2ndquadrant" ]; then
|
2018-10-13 11:11:31 -06:00
|
|
|
echo "deb http://apt.postgresql.org/pub/repos/apt/ $os_codename-pgdg main" > /etc/apt/sources.list.d/postgresql.list
|
|
|
|
|
echo "deb http://packages.2ndquadrant.com/bdr/apt/ $os_codename-2ndquadrant main" > /etc/apt/sources.list.d/2ndquadrant.list
|
2017-03-04 13:20:01 -07:00
|
|
|
/usr/bin/wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
|
|
|
|
|
/usr/bin/wget --quiet -O - http://packages.2ndquadrant.com/bdr/apt/AA7A6805.asc | apt-key add -
|
|
|
|
|
apt-get update && apt-get upgrade -y
|
2019-02-17 09:29:57 -07:00
|
|
|
apt-get install -y sudo postgresql-bdr-9.4 postgresql-bdr-9.4-bdr-plugin postgresql-bdr-contrib-9.4
|
2017-03-04 13:20:01 -07:00
|
|
|
fi
|
2016-06-08 09:28:47 -06:00
|
|
|
|
2017-04-20 00:55:50 +01:00
|
|
|
|
2016-04-29 13:24:22 -06:00
|
|
|
#systemd
|
2016-06-11 15:50:10 +01:00
|
|
|
systemctl daemon-reload
|
|
|
|
|
systemctl restart postgresql
|
2016-04-29 13:24:22 -06:00
|
|
|
|
|
|
|
|
#init.d
|
|
|
|
|
#/usr/sbin/service postgresql restart
|
|
|
|
|
|
2017-03-05 12:20:19 -07:00
|
|
|
#install the database backup
|
2018-12-11 01:26:25 -07:00
|
|
|
#cp backup/fusionpbx-backup /etc/cron.daily
|
|
|
|
|
#cp backup/fusionpbx-maintenance /etc/cron.daily
|
|
|
|
|
#chmod 755 /etc/cron.daily/fusionpbx-backup
|
|
|
|
|
#chmod 755 /etc/cron.daily/fusionpbx-maintenance
|
|
|
|
|
#sed -i "s/zzz/$password/g" /etc/cron.daily/fusionpbx-backup
|
|
|
|
|
#sed -i "s/zzz/$password/g" /etc/cron.daily/fusionpbx-maintenance
|
2017-03-05 11:25:06 -07:00
|
|
|
|
2016-06-04 19:47:40 +01:00
|
|
|
#move to /tmp to prevent a red herring error when running sudo with psql
|
|
|
|
|
cwd=$(pwd)
|
|
|
|
|
cd /tmp
|
2017-04-23 01:54:00 -06:00
|
|
|
|
2016-04-29 13:24:22 -06:00
|
|
|
#add the databases, users and grant permissions to them
|
2017-03-05 11:25:06 -07:00
|
|
|
sudo -u postgres psql -c "CREATE DATABASE fusionpbx;";
|
|
|
|
|
sudo -u postgres psql -c "CREATE DATABASE freeswitch;";
|
2016-04-29 13:24:22 -06:00
|
|
|
sudo -u postgres psql -c "CREATE ROLE fusionpbx WITH SUPERUSER LOGIN PASSWORD '$password';"
|
|
|
|
|
sudo -u postgres psql -c "CREATE ROLE freeswitch WITH SUPERUSER LOGIN PASSWORD '$password';"
|
|
|
|
|
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE fusionpbx to fusionpbx;"
|
|
|
|
|
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE freeswitch to fusionpbx;"
|
|
|
|
|
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE freeswitch to freeswitch;"
|
|
|
|
|
#ALTER USER fusionpbx WITH PASSWORD 'newpassword';
|
2016-06-04 19:47:40 +01:00
|
|
|
cd $cwd
|
2016-04-29 13:24:22 -06:00
|
|
|
|
|
|
|
|
#set the ip address
|
2017-01-11 20:49:15 -07:00
|
|
|
#server_address=$(hostname -I)
|