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

117 lines
4.2 KiB
Bash
Raw Normal View History

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
if [ ."$database_host" = ."127.0.0.1" ] || [ ."$database_host" = ."::1" ] ; then
2020-08-19 13:23:09 -06:00
apt-get install -y sudo postgresql
else
apt-get install -y sudo postgresql-client
fi
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
2019-08-20 16:12:00 -06:00
if [ ."$os_codename" = ."jessie" ]; then
echo "deb http://apt.postgresql.org/pub/repos/apt/ $os_codename-pgdg main" > /etc/apt/sources.list.d/postgresql.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update && apt-get upgrade -y
fi
if [ ."$os_codename" = ."stretch" ]; then
echo "deb http://apt.postgresql.org/pub/repos/apt/ $os_codename-pgdg main" > /etc/apt/sources.list.d/postgresql.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update && apt-get upgrade -y
fi
if [ ."$os_codename" = ."buster" ]; then
echo "deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main" > /etc/apt/sources.list.d/postgresql.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
fi
if [ ."$os_codename" = ."bullseye" ]; then
echo "deb http://apt.postgresql.org/pub/repos/apt/ bullseye-pgdg main" > /etc/apt/sources.list.d/postgresql.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
fi
if [ ."$database_host" = ."127.0.0.1" ] || [ ."$database_host" = ."::1" ] ; then
2020-08-19 13:23:09 -06:00
if [ ."$database_version" = ."latest" ]; then
apt-get install -y sudo postgresql
fi
if [ ."$database_version" = ."9.6" ]; then
apt-get install -y sudo postgresql-$database_version
fi
if [ ."$database_version" = ."9.4" ]; then
apt-get install -y sudo postgresql-$database_version
fi
else
apt-get install -y sudo postgresql-client
2017-11-06 19:57:35 -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
if [ ."$database_host" = ."127.0.0.1" ] || [ ."$database_host" = ."::1" ] ; then
2020-08-19 13:23:09 -06:00
apt install -y curl
curl https://dl.2ndquadrant.com/default/release/get/deb | bash
if [ ."$os_codename" = ."buster" ]; then
sed -i /etc/apt/sources.list.d/2ndquadrant-dl-default-release.list -e 's#buster#stretch#g'
fi
if [ ."$os_codename" = ."bullseye" ]; then
sed -i /etc/apt/sources.list.d/2ndquadrant-dl-default-release.list -e 's#bullseye#stretch#g'
fi
2020-08-19 13:23:09 -06:00
apt update
apt-get install -y sudo postgresql-bdr-9.4 postgresql-bdr-9.4-bdr-plugin postgresql-bdr-contrib-9.4
fi
2017-03-04 13:20:01 -07:00
fi
2016-06-08 09:28:47 -06:00
2016-04-29 13:24:22 -06:00
#systemd
if [ ."$database_host" = ."127.0.0.1" ] || [ ."$database_host" = ."::1" ] ; then
2020-08-19 13:23:09 -06:00
systemctl daemon-reload
systemctl restart postgresql
fi
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
if [ ."$database_host" = ."127.0.0.1" ] || [ ."$database_host" = ."::1" ] ; then
2020-08-19 13:23:09 -06:00
# add the databases, users and grant permissions to them
sudo -u postgres psql -c "CREATE DATABASE fusionpbx;";
sudo -u postgres psql -c "CREATE DATABASE freeswitch;";
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';
fi
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)