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

71 lines
3.9 KiB
Bash
Raw Normal View History

2017-05-21 21:54:47 +02:00
#!/bin/sh
2017-05-21 21:56:29 +02:00
#move to script directory so all relative paths work
cd "$(dirname "$0")"
#includes
. ../config.sh
#set the date
now=$(date +%Y-%m-%d)
#get the database password
if [ .$database_password = .'random' ]; then
2017-05-21 21:59:34 +02:00
read -p "Enter the database password: " database_password
2017-05-21 21:56:29 +02:00
fi
2017-05-21 21:54:47 +02:00
2017-06-15 18:59:02 +02:00
#whether to load the schema
read -p "Auto create schemas (y/n): " auto_create_schema
#whether to load the schema
read -p "Load schema with primary keys (y/n): " load_schema
2017-05-21 21:54:47 +02:00
#set PGPASSWORD
export PGPASSWORD=$database_password
2017-06-15 18:36:48 +02:00
#disable auto create schemas
2017-06-15 19:05:12 +02:00
if [ .$auto_create_schema = ."n" ]; then
2017-06-15 18:59:02 +02:00
sed -i /etc/freeswitch/autoload_configs/switch.conf.xml -e s:'<!-- <param name="auto-create-schemas" value="true"/> -->:<param name="auto-create-schemas" value="false"/>:'
fi
2017-06-15 18:36:48 +02:00
2017-06-15 18:41:59 +02:00
#load the schema
2017-06-15 19:05:12 +02:00
if [ .$load_schema = ."y" ]; then
2017-10-13 01:42:34 +02:00
sudo -u postgres psql -h $database_host -p $database_port -U freeswitch -d freeswitch -c "create extension pgcrypto;";
sudo -u postgres psql -h $database_host -p $database_port -U freeswitch -d freeswitch -f /var/www/fusionpbx/resources/install/sql/switch.sql -L /tmp/schema.log;
2017-06-15 18:59:02 +02:00
fi
2017-06-15 18:41:59 +02:00
2017-05-21 21:54:47 +02:00
#enable odbc-dsn in the xml
sed -i /etc/freeswitch/autoload_configs/db.conf.xml -e s:'<!--<param name="odbc-dsn" value="$${dsn}"/>-->:<param name="odbc-dsn" value="$${dsn}"/>:'
sed -i /etc/freeswitch/autoload_configs/fifo.conf.xml -e s:'<!--<param name="odbc-dsn" value="$${dsn}"/>-->:<param name="odbc-dsn" value="$${dsn}"/>:'
sed -i /etc/freeswitch/autoload_configs/switch.conf.xml -e s:'<!-- <param name="core-db-dsn" value="$${dsn}" /> -->:<param name="core-db-dsn" value="$${dsn}" />:'
#enable odbc-dsn in the sip profiles
2017-10-13 01:42:34 +02:00
sudo -u postgres psql -h $database_host -p $database_port -U freeswitch -d fusionpbx -c "update v_sip_profile_settings set sip_profile_setting_enabled = 'true' where sip_profile_setting_name = 'odbc-dsn';";
2017-05-21 21:54:47 +02:00
#add the dsn variables
2018-05-24 08:15:52 +02:00
sudo -u postgres psql -h $database_host -p $database_port -U freeswitch -d fusionpbx -c "insert into v_vars (var_uuid, var_name, var_value, var_category, var_enabled, var_order, var_description, var_hostname) values ('785d7013-1152-4a44-aa15-28336d9b36f9', 'dsn_system', 'pgsql://hostaddr=$database_host port=$database_port dbname=fusionpbx user=fusionpbx password=$database_password options=', 'DSN', 'true', '0', null, null);";
sudo -u postgres psql -h $database_host -p $database_port -U freeswitch -d fusionpbx -c "insert into v_vars (var_uuid, var_name, var_value, var_category, var_enabled, var_order, var_description, var_hostname) values ('0170e737-b453-40ea-99f2-f1375474e5ce', 'dsn', 'pgsql://hostaddr=$database_host port=$database_port dbname=freeswitch user=fusionpbx password=$database_password options=', 'DSN', 'true', '0', null, null);";
sudo -u postgres psql -h $database_host -p $database_port -U freeswitch -d fusionpbx -c "insert into v_vars (var_uuid, var_name, var_value, var_category, var_enabled, var_order, var_description, var_hostname) values ('32e3e364-a8ef-4fe0-9d02-c652d5122bbf', 'dsn_callcenter', 'sqlite:///var/lib/freeswitch/db/callcenter.db', 'DSN', 'true', '0', null, null);";
2017-05-21 21:54:47 +02:00
2017-06-15 19:30:13 +02:00
#add the
2017-06-15 19:40:30 +02:00
echo "<!-- DSN -->" >> /etc/freeswitch/vars.xml
2017-10-13 03:34:04 +02:00
echo "<X-PRE-PROCESS cmd=\"set\" data=\"dsn_system=pgsql://hostaddr=$database_host port=$database_port dbname=fusionpbx user=fusionpbx password=$database_password options=\" />" >> /etc/freeswitch/vars.xml
echo "<X-PRE-PROCESS cmd=\"set\" data=\"dsn=pgsql://hostaddr=$database_host port=$database_port dbname=freeswitch user=fusionpbx password=$database_password options=\" />" >> /etc/freeswitch/vars.xml
2017-06-15 21:20:11 +02:00
echo "<X-PRE-PROCESS cmd=\"set\" data=\"dsn_callcenter=sqlite:///var/lib/freeswitch/db/callcenter.db\" />" >> /etc/freeswitch/vars.xml
2017-06-15 19:30:13 +02:00
2017-05-21 21:54:47 +02:00
#remove the sqlite database files
dbs="/var/lib/freeswitch/db/core.db /var/lib/freeswitch/db/fifo.db /var/lib/freeswitch/db/call_limit.db /var/lib/freeswitch/db/sofia_reg_*"
for db in ${dbs};
do
if [ -f $db ]; then
echo "Deleting $db";
rm $db
fi
done
2017-05-21 21:54:47 +02:00
#flush memcache
2017-06-15 19:53:07 +02:00
/usr/bin/fs_cli -x 'memcache flush'
2017-05-21 21:54:47 +02:00
#restart freeswitch
2017-06-15 18:42:17 +02:00
service freeswitch restart