Skip to content

Instantly share code, notes, and snippets.

@areski
Created November 30, 2015 17:54
Show Gist options
  • Save areski/90d81d53329fa3f790cb to your computer and use it in GitHub Desktop.
Save areski/90d81d53329fa3f790cb to your computer and use it in GitHub Desktop.
FreeSWITCH 1.6
#!/bin/bash
#
# Newfies-Dialer License
# http://www.newfies-dialer.org
#
# Copyright (C) 2011-2015 Star2Billing S.L.
# Arezqui Belaid <[email protected]>
#
FS_CONF_PATH=/usr/src/newfies-dialer/install/freeswitch-conf
FS_INIT_PATH=/usr/src/newfies-dialer/install/freeswitch-init
FS_CONFIG_PATH=/etc/freeswitch
FS_BASE_PATH=/usr/src
# KERNELARCH=$(uname -m)
# This script is intended for x86_64 architecture
KERNELARCH="x86_64"
# Valid Freeswitch versions are : v1.2.stable
#FS_VERSION=v1.2.stable
FS_VERSION=v1.6
SCRIPT_NOTICE="This script is only intended to run on Debian (64bits) 8.X"
#Set branch to install develop / default: master
if [ -z "${INSTALL_FS}" ]; then
INSTALL_FS='yes'
fi
clear
echo ""
echo "FreeSWITCH will now be installed!"
echo ""
# echo ""
# echo "Press Enter to continue or CTRL-C to exit"
# echo ""
# read INPUT
# -- Functions --
func_install_deps() {
echo "Setting up Prerequisites and Dependencies for FreeSWITCH"
apt-get -y update
apt-get -y install locales-all
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
locale-gen es_ES.UTF-8
locale-gen fr_FR.UTF-8
locale-gen pt_BR.UTF-8
apt-get -y install unzip zip sox sqlite3 ncftp nmap
apt-get -y install autoconf2.64 automake autotools-dev binutils bison build-essential cpp curl flex gcc libaudiofile-dev libc6-dev libexpat1 libexpat1-dev mcrypt libmcrypt-dev libnewt-dev libpopt-dev libsctp-dev libx11-dev libxml2 libxml2-dev lksctp-tools lynx m4 openssl ssl-cert zlib1g-dev
apt-get -y install autoconf automake devscripts gawk g++ git-core 'libjpeg-dev|libjpeg62-turbo-dev' libncurses5-dev 'libtool-bin|libtool' make python-dev gawk pkg-config libtiff5-dev libperl-dev libgdbm-dev libdb-dev gettext libssl-dev libcurl4-openssl-dev libpcre3-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libedit-dev libldns-dev libpq-dev libmp3lame-dev
if [ $DEBIANCODE != "jessie" ]; then
#DEBIAN7
apt-get -y install libgnutls-dev libtiff4-dev libtiff4
else
#DEBIAN8
apt-get -y install libgnutls28-dev libtiff5-dev libtiff5
fi
apt-get -y install libvorbis0a libogg0 libogg-dev libvorbis-dev
apt-get -y install flite flite1-dev
apt-get -y install unixodbc-dev odbc-postgresql
}
func_install_fs_sources() {
echo "Installing from sources"
#install Dependencies
func_install_deps
#Add Freeswitch group and user
grep -c "^freeswitch:" /etc/group &> /dev/null
if [ $? = 1 ]; then
/usr/sbin/groupadd -r -f freeswitch
fi
grep -c "^freeswitch:" /etc/passwd &> /dev/null
if [ $? = 1 ]; then
echo "adding user freeswitch..."
/usr/sbin/useradd -r -c "freeswitch" -g freeswitch freeswitch
fi
#Download and install FS from git repository.
cd $FS_BASE_PATH
rm -rf freeswitch
# dont use depth : --depth=1 as we wont be able to checkout
git clone --branch=$FS_VERSION https://freeswitch.org/stash/scm/fs/freeswitch.git --depth=1
cd $FS_BASE_PATH/freeswitch
# git checkout $FS_VERSION
echo ""
echo "Running ./bootstrap.sh -j"
echo ""
./bootstrap.sh -j
# !!! virtual memory exhausted: Cannot allocate memory !!!
# we need to make more temporary swap space
#
# dd if=/dev/zero of=/root/fakeswap bs=1024 count=1048576
# mkswap /root/fakeswap
# swapon /root/fakeswap
./configure --without-pgsql --prefix=/usr/local/freeswitch --sysconfdir=/etc/freeswitch/
[ -f modules.conf ] && cp modules.conf modules.conf.bak
sed -i -e \
"s/#applications\/mod_curl/applications\/mod_curl/g" \
-e "s/#applications\/mod_avmd/applications\/mod_avmd/g" \
-e "s/#asr_tts\/mod_flite/asr_tts\/mod_flite/g" \
-e "s/#asr_tts\/mod_tts_commandline/asr_tts\/mod_tts_commandline/g" \
-e "s/#formats\/mod_shout/formats\/mod_shout/g" \
-e "s/#endpoints\/mod_dingaling/endpoints\/mod_dingaling/g" \
-e "s/#formats\/mod_shell_stream/formats\/mod_shell_stream/g" \
-e "s/#say\/mod_say_de/say\/mod_say_de/g" \
-e "s/#say\/mod_say_es/say\/mod_say_es/g" \
-e "s/#say\/mod_say_fr/say\/mod_say_fr/g" \
-e "s/#say\/mod_say_it/say\/mod_say_it/g" \
-e "s/#say\/mod_say_nl/say\/mod_say_nl/g" \
-e "s/#say\/mod_say_ru/say\/mod_say_ru/g" \
-e "s/#say\/mod_say_zh/say\/mod_say_zh/g" \
-e "s/#say\/mod_say_hu/say\/mod_say_hu/g" \
-e "s/#say\/mod_say_th/say\/mod_say_th/g" \
# -e "s/#xml_int\/mod_xml_cdr/xml_int\/mod_xml_cdr/g" \
modules.conf
make && make install && make sounds-install && make moh-install
# Remove temporary swap
# swapoff /root/fakeswap
# rm /root/fakeswap
#Set permissions
chown -R freeswitch:freeswitch /usr/local/freeswitch /etc/freeswitch
}
install_fs_deb_packages() {
#for 1.2 Stable Branch
echo "deb http://files.freeswitch.org/repo/deb/debian/ $DEBIANCODE main" >> /etc/apt/sources.list.d/freeswitch.list
curl http://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add -
#install Dependencies
func_install_deps
apt-get -y install freeswitch-meta-vanilla
apt-get -y install freeswitch-mod-vmd freeswitch-mod-python freeswitch-mod-sndfile freeswitch-sounds-en
apt-get -y install libfreeswitch-dev freeswitch-mod-lua freeswitch-mod-flite
apt-get -y install freeswitch-mod-esl freeswitch-mod-event-socket freeswitch-mod-curl
}
func_install_luasql() {
#Install Dependencies
apt-get install -y lua5.2 liblua5.2-dev
apt-get install -y libpq-dev
#Install LuaSQL
cd /usr/src/
wget --no-check-certificate https://github.com/keplerproject/luasql/archive/v2.3.0.zip
unzip v2.3.0.zip
cd luasql-2.3.0/
#Copy a config file adapted for 64bit
cp config config.orig
rm config
wget --no-check-certificate https://gist.githubusercontent.com/areski/4b82058ddf84e9d6f1e5/raw/5fae61dd851960b7063b82581b1b4904ba9413df/luasql_config -O config
# if [ $KERNELARCH != "x86_64" ]; then
# sed -i "s/64//g" config
# fi
#Compile and install
make
make install
}
func_configure_fs() {
echo "Enable FreeSWITCH modules"
cd $FS_CONFIG_PATH/autoload_configs/
[ -f modules.conf.xml ] && cp modules.conf.xml modules.conf.xml.bak
sed -i -r \
-e "s/<\!--\s?<load module=\"mod_lua\"\/>\s?-->/<load module=\"mod_lua\"\/>/g" \
# -e "s/<\!--\s?<load module=\"mod_xml_cdr\"\/>\s?-->/<load module=\"mod_xml_cdr\"\/>/g" \
-e "s/<\!--\s?<load module=\"mod_dingaling\"\/>\s?-->/<load module=\"mod_dingaling\"\/>/g" \
-e "s/<\!--\s?<load module=\"mod_shell_stream\"\/>\s?-->/<load module=\"mod_shell_stream\"\/>/g" \
-e "s/<\!-- \s?<load module=\"mod_shell_stream\"\/>\s? -->/<load module=\"mod_shell_stream\"\/>/g" \
-e "s/<\!--\s?<load module=\"mod_shout\"\/>\s?-->/<load module=\"mod_shout\"\/>/g" \
-e "s/<\!--\s?<load module=\"mod_tts_commandline\"\/>\s?-->/<load module=\"mod_tts_commandline\"\/>/g" \
-e "s/<\!--\s?<load module=\"mod_flite\"\/>\s?-->/<load module=\"mod_flite\"\/>/g" \
-e "s/<\!--\s?<load module=\"mod_say_ru\"\/>\s?-->/<load module=\"mod_say_ru\"\/>/g" \
-e "s/<\!--\s?<load module=\"mod_say_zh\"\/>\s?-->/<load module=\"mod_say_zh\"\/>/g" \
-e 's/mod_say_zh.*$/&\n <load module="mod_say_de"\/>\n <load module="mod_say_es"\/>\n <load module="mod_say_fr"\/>\n <load module="mod_say_it"\/>\n <load module="mod_say_nl"\/>\n <load module="mod_say_hu"\/>\n <load module="mod_say_th"\/>/' \
modules.conf.xml
[ -f lua.conf.xml ] && mv lua.conf.xml lua.conf.xml.bak
cp $FS_CONF_PATH/lua.conf.xml lua.conf.xml
#Configure Dialplan
#cd $FS_CONFIG_PATH/conf/dialplan/
#Configure XML CDR
#cd $FS_CONFIG_PATH/conf/autoload_configs/
#this is commented as we don't use xml_cdr anymore
## Place Newfies XML CDR conf in FreeSWITCH
#[ -f xml_cdr.conf.xml ] && mv xml_cdr.conf.xml xml_cdr.conf.xml.bak
cp $FS_CONF_PATH/xml_cdr.conf.xml xml_cdr.conf.xml
#create dir to store send error of CDR
#mkdir /usr/local/freeswitch/log/err_xml_cdr/
}
func_create_alias_fs_cli() {
echo "Setup alias fs_cli"
alias fs_cli='/usr/local/freeswitch/bin/fs_cli'
chk=`grep "fs_cli" ~/.bashrc|wc -l`
if [ $chk -lt 1 ] ; then
echo "alias fs_cli='/usr/local/freeswitch/bin/fs_cli'" >> ~/.bashrc
fi
}
func_add_init_script() {
#Install init.d script
cp $FS_INIT_PATH/debian/freeswitch /etc/init.d/freeswitch
chmod 0755 /etc/init.d/freeswitch
cd /etc/init.d; update-rc.d freeswitch defaults 90
# Remove with:
# cd /etc/init.d; update-rc.d -f freeswitch remove
}
if [ $INSTALL_FS = "yes" ]; then
#Install FreeSWITCH from Debian packages
#install_fs_deb_packages
#!!! At the moment we cannot install from Deb packages cause we need the sources to compile
#libs/esl/python
#Install FreeSWITCH from sources
func_install_fs_sources
#Install luaSQL
func_install_luasql
#Create alias fs_cli
func_create_alias_fs_cli
#Install init.d script
func_add_init_script
#Configure FreeSWITCH
func_configure_fs
#Start FreeSWITCH
/etc/init.d/freeswitch start
echo ""
echo "*********************************************"
echo "Congratulations, FreeSWITCH is now installed!"
echo "*********************************************"
echo ""
fi
cd $FS_BASE_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment