#!/usr/bin/env bash

AST_VER=18

echo 
echo "*** Installing Asterisk $AST_VER ***"
echo 

yum -y install asterisk${AST_VER} asterisk${AST_VER}-config asterisk-sounds-moh-opsound-wav asterisk-sounds-extra-en-gsm  asterisk-sounds-core-en-gsm --enablerepo=epel
mkdir -p /var/lib/asterisk/agi-bin/

# fix for dual app_voicemail modules
echo "noload => app_voicemail_odbc.so" >>  /etc/asterisk/modules.conf

ASTSAVE=/root/asterisk-conf-init.tar.gz
chmod 777 /var/run/

echo Starting PBXPORTAL...
# save current config and remove config rpms
cd /
tar cvfz $ASTSAVE /etc/asterisk  >/dev/null 2>&1

rpm -e asterisk${AST_VER}-config

# restore config after rpm deinstallation
tar zxf $ASTSAVE >/dev/null 2>&1

chown -R asterisk:asterisk /var/run/asterisk/ # temp fix
chown -R asterisk:asterisk /var/log/asterisk/
chmod -R 755 /var/log/asterisk/

echo "d /run/asterisk   710 asterisk asterisk" > /etc/tmpfiles.d/asterisk.conf 

systemctl enable  asterisk
systemctl restart asterisk
