fusionpbx-install.sh/debian/resources/postgresql.sh

78 lines
2.8 KiB
Bash
Raw Normal View History

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