Postgres install is working nginx is closer

This commit is contained in:
Mark J Crane
2017-03-25 17:49:24 -06:00
parent 2b6188363c
commit 1089698a00
5 changed files with 73 additions and 92 deletions

View File

@@ -6,63 +6,51 @@ cd "$(dirname "$0")"
#includes
. ./config.sh
. ./colors.sh
. ./environment.sh
#send a message
echo "Install PostgreSQL"
#generate a random password
password=$(dd if=/dev/urandom bs=1 count=20 2>/dev/null | base64)
password=$(cat /dev/random | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 16)
#install message
echo "Install PostgreSQL and create the database and users\n"
#use the system database repo for arm
if [ .$cpu_architecture = .'arm' ]; then
database_repo="system"
#postgres install
if [ ."$database_version" = ."9.6" ]; then
pkg install --yes postgresql96-server
fi
if [ ."$database_version" = ."9.5" ]; then
pkg install --yes postgresql95-server
fi
if [ ."$database_version" = ."9.4" ]; then
pkg install --yes postgresql94-server
fi
if [ ."$database_version" = ."9.3" ]; then
pkg install --yes postgresql93-server
fi
#included in the distribution
if [ ."$database_repo" = ."system" ]; then
apt-get install -y --force-yes sudo postgresql
fi
#enable postgres
echo 'postgresql_enable=true' >> /etc/rc.conf
#postgres official repository
if [ ."$database_repo" = ."official" ]; then
echo 'deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main' > /etc/apt/sources.list.d/pgdg.list
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
apt-get update && apt-get upgrade -y
apt-get install -y --force-yes sudo postgresql
fi
#initialize the database
/usr/local/etc/rc.d/postgresql initdb
#Add PostgreSQL and BDR REPO
if [ ."$database_repo" = ."2ndquadrant" ]; then
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
/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
#systemd
systemctl daemon-reload
systemctl restart postgresql
#init.d
#/usr/sbin/service postgresql restart
#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
sed -i "s/zzz/$password/g" /etc/cron.daily/fusionpbx-backup.sh
#cp backup/fusionpbx-backup.sh /etc/cron.daily
#chmod 755 /etc/cron.daily/fusionpbx-backup.sh
#sed -i "s/zzz/$password/g" /etc/cron.daily/fusionpbx-backup.sh
#move to /tmp to prevent a red herring error when running sudo with psql
#move to /tmp to prevent an error when running sudo with psql
cwd=$(pwd)
cd /tmp
#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 -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';"
@@ -71,7 +59,4 @@ sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE fusionpbx to fusionpb
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';
cd $cwd
#set the ip address
#server_address=$(hostname -I)