2017-03-25 18:41:47 +01:00
|
|
|
#!/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
|
|
|
|
|
|
2017-03-25 18:41:47 +01:00
|
|
|
#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)
|
2017-03-25 18:41:47 +01:00
|
|
|
|
|
|
|
|
#install message
|
|
|
|
|
echo "Install PostgreSQL and create the database and users\n"
|
|
|
|
|
|
2017-03-26 00:49:24 +01:00
|
|
|
#postgres install
|
2024-08-24 17:30:47 +02:00
|
|
|
if [ ."$database_version" = ."16" ]; then
|
2024-08-24 20:17:11 +02:00
|
|
|
echo "IGNORE_DEPENDS=postgresql15-client" >> /usr/local/etc/pkg.conf
|
2024-08-24 17:30:47 +02:00
|
|
|
pkg install --yes postgresql16-server
|
2024-08-24 18:11:54 +02:00
|
|
|
#cd /usr/ports/databases/postgresql16-server/ && make install clean BATCH=yes
|
2024-08-24 17:30:47 +02:00
|
|
|
fi
|
2024-01-03 22:06:57 +01:00
|
|
|
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
|
2017-03-25 18:41:47 +01:00
|
|
|
|
2017-03-26 00:49:24 +01:00
|
|
|
#enable postgres
|
|
|
|
|
echo 'postgresql_enable=true' >> /etc/rc.conf
|
2017-03-25 18:41:47 +01:00
|
|
|
|
2017-03-26 00:49:24 +01:00
|
|
|
#initialize the database
|
|
|
|
|
/usr/local/etc/rc.d/postgresql initdb
|
|
|
|
|
|
2017-04-01 10:49:17 +02:00
|
|
|
#start postgresql
|
2024-08-24 17:30:47 +02:00
|
|
|
if [ ."$database_version" = ."16" ]; then
|
|
|
|
|
sudo -u postgres /usr/local/bin/pg_ctl -D /var/db/postgres/data16 start
|
|
|
|
|
fi
|
2024-01-03 22:06:57 +01:00
|
|
|
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
|
2020-11-17 01:07:34 +01:00
|
|
|
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
|
2017-04-01 10:49:17 +02:00
|
|
|
|
2017-03-26 00:49:24 +01:00
|
|
|
#restart the service
|
|
|
|
|
service postgresql restart
|
2017-03-25 18:41:47 +01:00
|
|
|
|
|
|
|
|
#install the database backup
|
2017-03-26 00:49:24 +01:00
|
|
|
#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
|
2017-03-25 18:41:47 +01:00
|
|
|
|
|
|
|
|
#add the databases, users and grant permissions to them
|
2017-03-26 00:49:24 +01:00
|
|
|
#sudo -u postgres psql -d fusionpbx -c "DROP SCHEMA public cascade;";
|
|
|
|
|
#sudo -u postgres psql -d fusionpbx -c "CREATE SCHEMA public;";
|
2017-03-25 18:41:47 +01:00
|
|
|
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';
|
|
|
|
|
|