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

126 lines
4.4 KiB
Bash
Raw Normal View History

#!/bin/sh
#move to script directory so all relative paths work
cd "$(dirname "$0")"
#includes
. ./config.sh
. ./colors.sh
2017-04-25 07:21:49 +02:00
#install the dependencies
pkg install --yes sudo
2017-04-01 23:47:29 +02:00
#move to /tmp to prevent an error when running sudo with psql
cwd=$(pwd)
cd /tmp
#send a message
echo "Install PostgreSQL"
#generate a random password
2017-03-26 21:24:16 +02:00
password=$(cat /dev/random | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 20)
#install message
echo "Install PostgreSQL and create the database and users\n"
#postgres install
if [ ."$database_version" = ."15" ]; then
pkg install --yes postgresql15-server
#cd /usr/ports/databases/postgresql15-server/ && make install clean BATCH=yes
fi
if [ ."$database_version" = ."14" ]; then
pkg install --yes postgresql14-server
#cd /usr/ports/databases/postgresql14-server/ && make install clean BATCH=yes
fi
2020-11-16 05:59:47 +01:00
if [ ."$database_version" = ."13" ]; then
pkg install --yes postgresql13-server
#cd /usr/ports/databases/postgresql13-server/ && make install clean BATCH=yes
fi
if [ ."$database_version" = ."12" ]; then
pkg install --yes postgresql12-server
#cd /usr/ports/databases/postgresql12-server/ && make install clean BATCH=yes
fi
2019-01-20 00:22:41 +01:00
if [ ."$database_version" = ."11" ]; then
pkg install --yes postgresql11-server
2020-11-16 05:59:47 +01:00
#cd /usr/ports/databases/postgresql11-server/ && make install clean BATCH=yes
2019-01-20 00:22:41 +01:00
fi
2018-05-16 20:31:57 +02:00
if [ ."$database_version" = ."10" ]; then
pkg install --yes postgresql10-server
#cd /usr/ports/databases/postgresql10-server/ && make install clean BATCH=yes
fi
if [ ."$database_version" = ."9.6" ]; then
2017-04-01 23:47:29 +02:00
pkg install --yes postgresql96-server
#cd /usr/ports/databases/postgresql96-server/ && make install clean BATCH=yes
fi
if [ ."$database_version" = ."9.5" ]; then
2017-04-01 23:47:29 +02:00
pkg install --yes postgresql95-server
#cd /usr/ports/databases/postgresql95-server/ && make install clean BATCH=yes
fi
if [ ."$database_version" = ."9.4" ]; then
2017-04-01 23:47:29 +02:00
pkg install --yes postgresql94-server
#cd /usr/ports/databases/postgresql94-server/ && make install clean BATCH=yes
fi
if [ ."$database_version" = ."9.3" ]; then
2017-04-01 23:47:29 +02:00
pkg install --yes postgresql93-server
#cd /usr/ports/databases/postgresql93-server/ && make install clean BATCH=yes
fi
#enable postgres
echo 'postgresql_enable=true' >> /etc/rc.conf
#initialize the database
/usr/local/etc/rc.d/postgresql initdb
2017-04-01 10:49:17 +02:00
#start postgresql
if [ ."$database_version" = ."15" ]; then
sudo -u postgres /usr/local/bin/pg_ctl -D /var/db/postgres/data15 start
fi
if [ ."$database_version" = ."14" ]; then
sudo -u postgres /usr/local/bin/pg_ctl -D /var/db/postgres/data14 start
fi
if [ ."$database_version" = ."13" ]; then
sudo -u postgres /usr/local/bin/pg_ctl -D /var/db/postgres/data13 start
fi
if [ ."$database_version" = ."12" ]; then
sudo -u postgres /usr/local/bin/pg_ctl -D /var/db/postgres/data12 start
fi
2019-01-20 00:22:41 +01:00
if [ ."$database_version" = ."11" ]; then
sudo -u postgres /usr/local/bin/pg_ctl -D /var/db/postgres/data11 start
2019-01-20 00:22:41 +01:00
fi
2018-05-16 20:31:57 +02:00
if [ ."$database_version" = ."10" ]; then
sudo -u postgres /usr/local/bin/pg_ctl -D /var/db/postgres/data10 start
2018-05-16 20:31:57 +02:00
fi
2017-04-01 10:49:17 +02:00
if [ ."$database_version" = ."9.6" ]; then
sudo -u postgres /usr/local/bin/pg_ctl -D /var/db/postgres/data96 start
2017-04-01 10:49:17 +02:00
fi
2017-04-01 19:31:35 +02:00
if [ ."$database_version" = ."9.5" ]; then
sudo -u postgres /usr/local/bin/pg_ctl -D /var/db/postgres/data95 start
2017-04-01 19:31:35 +02:00
fi
if [ ."$database_version" = ."9.4" ]; then
sudo -u postgres /usr/local/bin/pg_ctl -D /var/db/postgres/data94 start
2017-04-01 19:31:35 +02:00
fi
if [ ."$database_version" = ."9.3" ]; then
sudo -u pgsql /usr/local/bin/pg_ctl -D /usr/local/pgsql/data start
2017-04-01 19:31:35 +02:00
fi
2017-04-01 10:49:17 +02:00
#restart the service
service postgresql restart
#install the database backup
#cp backup/fusionpbx-backup.sh /etc/cron.daily
#chmod 755 /etc/cron.daily/fusionpbx-backup.sh
2017-03-26 21:24:16 +02:00
#sed -i' ' -e "s/zzz/$password/g" /etc/cron.daily/fusionpbx-backup.sh
#add the databases, users and grant permissions to them
#sudo -u postgres psql -d fusionpbx -c "DROP SCHEMA public cascade;";
#sudo -u postgres psql -d fusionpbx -c "CREATE SCHEMA public;";
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';