#/bin/bash

if [ -z "$1" ]; then
 clear
 echo "ERROR: Number of Asterisk 13 tarball is required."
 echo "SYNTAX example: ./upgrade-asterisk 13.22.0"
 echo " "
 echo " "
 exit 1
fi

cd /usr/src
rm -f asterisk-$1.tar.gz
rm -rf asterisk-$1
wget http://downloads.asterisk.org/pub/telephony/asterisk/releases/asterisk-$1.tar.gz
tar zxvf asterisk-$1.tar.gz
mv asterisk-$1.tar.gz /tmp

cd /usr/src/asterisk-$1
contrib/scripts/install_prereq install
yum -y install --enablerepo="epel" gmime-devel
contrib/scripts/get_mp3_source.sh 


make distclean

wget http://incrediblepbx.com/menuselect-incredible13.8.tar.gz
tar zxvf menuselect-incredible*
rm -f menuselect-incredible*

CFLAGS='-DENABLE_SRTP_AES_256 -DENABLE_SRTP_AES_GCM' ./configure --libdir=/usr/lib64 --with-pjproject-bundled

make menuselect.makeopts
 menuselect/menuselect --enable-category MENUSELECT_ADDONS menuselect.makeopts
 menuselect/menuselect --enable-category MENUSELECT_CODECS menuselect.makeopts
 menuselect/menuselect --disable-category MENUSELECT_TESTS menuselect.makeopts
 menuselect/menuselect --enable CORE-SOUNDS-EN-GSM --enable MOH-OPSOUND-WAV --enable EXTRA-SOUNDS-EN-GSM --enable cdr_mysql menuselect.makeopts
 menuselect/menuselect --disable app_mysql --disable app_setcallerid --disable func_audiohookinherit --disable res_fax_spandsp menuselect.makeopts
 menuselect/menuselect --disable test_named_lock --disable test_res_pjsip_scheduler --disable test_file --disable test_bridging --disable test_res_pjsip_scheduler menuselect.makeopts
sed -i 's|march=native|mtune=native|' Makefile.rules

# The new Josh Culp way to clean out incompatible Asterisk pieces
make menuselect.makeopts

# Old-fashioned way
#  expect -c 'set timeout 15;spawn make menuselect;expect Save;send "\t\t\r";interact'


make menuselect


make && make install && ldconfig

cd /usr/src/Asterisk-Flite-2.2-rc1-flite1.3
make
make install

amportal restart

