131 lines
5.6 KiB
Bash
Executable File
131 lines
5.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
DBNAME=$(/sbin/e-smith/db configuration getprop freepbx DbName)
|
|
DBUSER=$(/sbin/e-smith/db configuration getprop freepbx DbUser)
|
|
DBPASS=$(/sbin/e-smith/db configuration getprop freepbx DbPassword)
|
|
CDRDBNAME=$(/sbin/e-smith/db configuration getprop freepbx CdrDbName)
|
|
MANAGERPASSWORD=$(/sbin/e-smith/db configuration getprop freepbx ManagerPassword)
|
|
DomainName=$(/sbin/e-smith/db configuration get DomainName)
|
|
|
|
if [ $(mysqlshow | grep -c $DBNAME) -lt 1 ]; then
|
|
mysql -e "create database $DBNAME CHARACTER SET utf8 COLLATE utf8_unicode_ci ;"
|
|
mysql -e "grant all privileges on $DBNAME.* to '$DBUSER'@'localhost' identified by '$DBPASS';"
|
|
mysql -e 'flush privileges;'
|
|
|
|
if [ -e /usr/share/freepbx/sql/asterisk.sql ]; then
|
|
mysql $DBNAME < /usr/share/freepbx/sql/asterisk.sql
|
|
else
|
|
echo "Error: file /usr/share/freepbx/sql/asterisk.sql doesn't exists"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if [ $(mysqlshow | grep -c $CDRDBNAME) -lt 1 ]; then
|
|
mysql -e "create database $CDRDBNAME CHARACTER SET utf8 COLLATE utf8_unicode_ci ;"
|
|
mysql -e "grant all privileges on $CDRDBNAME.* to '$DBUSER'@'localhost' identified by '$DBPASS';"
|
|
mysql -e 'flush privileges;'
|
|
if [ -e /usr/share/freepbx/sources/freepbx/installlib/SQL/cdr.sql ]; then
|
|
mysql $CDRDBNAME < /usr/share/freepbx/sources/freepbx/installlib/SQL/cdr.sql
|
|
else
|
|
echo "Error: file /usr/share/freepbx/sources/freepbx/installlib/SQL/cdr.sql doesn't exists"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# set user and passwords
|
|
/usr/bin/mysql $DBNAME -e "INSERT INTO \`admin\` (\`variable\`, \`value\`) VALUES ('email', 'admin\@$DomainName') ON DUPLICATE KEY UPDATE \`value\` = 'admin\@$DomainName';"
|
|
/usr/bin/mysql $DBNAME -e "INSERT INTO \`ampusers\` (\`username\`, \`password_sha1\`, \`extension_low\`, \`extension_high\`, \`deptname\`, \`sections\`) VALUES
|
|
('admin', sha1('$MANAGERPASSWORD '), '', '', '', 0x2a) ON DUPLICATE KEY UPDATE \`password_sha1\` = sha1('$ManagerPassword ');"
|
|
|
|
# Chown dir to allow user asterisk to create its files
|
|
chown asterisk:asterisk /var/lib/asterisk
|
|
|
|
# workaround as freepbx is expecting them in /var not /usr/share
|
|
cd /var/lib/asterisk
|
|
if [[ ! -d /var/lib/asterisk/documentation ]]; then ln -s /usr/share/asterisk/documentation ; fi
|
|
if [[ ! -d /var/lib/asterisk/moh ]]; then ln -s /usr/share/asterisk/moh ; fi
|
|
if [[ ! -d /var/lib/asterisk/sounds ]]; then ln -s /usr/share/asterisk/sounds/ ; fi
|
|
mkdir -p /usr/share/asterisk/sounds/tmp
|
|
chown asterisk: /usr/share/asterisk/sounds/tmp
|
|
chown asterisk: /usr/share/asterisk/sounds/ /usr/share/asterisk/moh
|
|
|
|
# Run the install script only if it's a new install
|
|
# Upgrades have to be done through freePBX and the online repository
|
|
if [ ! -d /opt/freepbx/admin ]; then
|
|
mkdir -p /opt/freepbx
|
|
# we need the right php version available
|
|
version=$(/usr/bin/rpm -q freepbx-src --qf "%{version}"|cut -d. -f1)
|
|
php="/usr/bin/php56"
|
|
if [[ $version -ge 16 ]]
|
|
then
|
|
php="/usr/bin/php74"
|
|
elif [[ $version -le 15 ]]
|
|
then
|
|
php="/usr/bin/php56"
|
|
fi
|
|
ln -sf $php /usr/sbin/php
|
|
ln -sf $php /usr/local/sbin/php
|
|
|
|
if [ -e /usr/share/freepbx/sources/freepbx/ ]; then
|
|
cd /usr/share/freepbx/sources/freepbx/
|
|
echo "Starting Asterisk..." > /root/freepbx_install.log
|
|
./start_asterisk start >> /root/freepbx_install.log 2>&1
|
|
echo "" >> /root/freepbx_install.log
|
|
echo "Installing FreePBX..." >> /root/freepbx_install.log
|
|
echo "a" |$php --define sys_temp_dir=/var/spool/asterisk/tmp/ --define allow_url_fopen=1 --define memory_limit=256M /usr/share/freepbx/sources/freepbx/install --webroot="/opt/freepbx" \
|
|
--dbengine="mysql" --dbname="freepbxdb" --dbuser="freepbxuser" --dbpass="$DBPASS" -n \
|
|
--cdrdbname="$CDRDBNAME" --astmoddir=/usr/lib64/asterisk/modules/ \
|
|
--astagidir=/usr/share/asterisk/agi-bin/ --ampsbin=/usr/sbin --ampcgibin=/opt/freepbx/cgi-bin \
|
|
>> /root/freepbx_install.log 2>&1
|
|
else
|
|
echo "error: /usr/share/freepbx/sources/freepbx/ doesn't exists"
|
|
exit 1
|
|
fi
|
|
else
|
|
if [ -x /var/lib/asterisk/bin/freepbx_engine ]; then
|
|
/var/lib/asterisk/bin/freepbx_engine chown > /dev/null 2>&1
|
|
else
|
|
echo "error: /var/lib/asterisk/bin/freepbx_engine is not executable"
|
|
exit 1
|
|
fi
|
|
if [ -x /var/lib/asterisk/bin/retrieve_conf ]; then
|
|
/var/lib/asterisk/bin/retrieve_conf > /dev/null 2>&1
|
|
else
|
|
echo "error: /var/lib/asterisk/bin/freepbx_engine is not executable"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if [ ! -d /opt/freepbx/digium_phones ]; then
|
|
mkdir -p /opt/freepbx/digium_phones
|
|
chown asterisk:asterisk /opt/freepbx/digium_phones
|
|
fi
|
|
|
|
#change the links to get the right php
|
|
ln -sf /usr/sbin/e-smith/fwconsole /usr/sbin/fwconsole
|
|
ln -sf /usr/sbin/e-smith/fwconsole /usr/local/sbin/fwconsole
|
|
version=$(/usr/bin/xmllint --xpath 'string(/module/version)' /opt/freepbx/admin/modules/core/module.xml|cut -d. -f1)
|
|
php="56"
|
|
if [[ $version -ge 16 ]]
|
|
then
|
|
#version we have is not fully compatible, need newer source
|
|
php="74"
|
|
elif [[ $version -le 15 ]]
|
|
then
|
|
php="56"
|
|
fi
|
|
forcephp=$(/sbin/e-smith/db configuration getprop freepbx PHPVersion 2>/dev/null || echo $php )
|
|
php=$forcephp
|
|
ln -sf /usr/bin/php$php /usr/sbin/php
|
|
ln -sf /usr/bin/php$php /usr/local/sbin/php
|
|
|
|
# update modules
|
|
/usr/sbin/e-smith/fwconsole ma upgrade framework 2>/dev/null
|
|
/usr/sbin/e-smith/fwconsole ma upgrade core 2>/dev/null
|
|
/usr/sbin/e-smith/fwconsole ma upgradeall -R standard -R extended 2>/dev/null
|
|
/usr/sbin/e-smith/fwconsole ma refreshsignatures 2>/dev/null
|
|
/usr/sbin/e-smith/fwconsole ma downloadinstall userman certman arimanager 2>/dev/null
|
|
/usr/sbin/e-smith/fwconsole ma downloadinstall ucp 2>/dev/null
|
|
|
|
exit 0
|