Skip to content

Instantly share code, notes, and snippets.

@areski
Created March 23, 2016 10:44
Show Gist options
  • Save areski/6350364c4306a76b78d0 to your computer and use it in GitHub Desktop.
Save areski/6350364c4306a76b78d0 to your computer and use it in GitHub Desktop.
Install FreeSWITCH 1.7
#!/bin/bash
#
# Arezqui Belaid <[email protected]>
#
FS_CONFIG_PATH=/etc/freeswitch
FS_BASE_PATH=/usr/src
FS_VERSION=v1.7
clear
echo ""
echo "FreeSWITCH will now be installed!"
echo ""
# Install Dependencies for FreeSWITCH
func_install_deps() {
echo "Setting up Prerequisites and Dependencies for FreeSWITCH"
apt-get -y update
# Install locales
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
apt-get -y install unzip zip sox sqlite3 ncftp nmap tree locate vim
# Install FS debs | https://freeswitch.org/confluence/display/FREESWITCH/Debian+8+Jessie
apt-get install -y curl
curl https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add -
echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list
echo "deb http://files.freeswitch.org/repo/deb/debian-unstable/ jessie main" >> /etc/apt/sources.list.d/freeswitch.list
apt-get update
apt-get install -y --force-yes freeswitch-video-deps-most
}
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
./configure --enable-system-lua --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
#Set permissions
chown -R freeswitch:freeswitch /usr/local/freeswitch /etc/freeswitch
}
# Install FreeSWITCH via Debs packages
install_fs_deb_packages() {
if [ -d "/etc/apt/sources.list.d/freeswitch.list" ]; then
echo "FreeSWITCH sources.list already added!"
else
echo "Setup new sources.list entries for FreeSWITCH"
echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list
wget --no-check-certificate -O - http://files.freeswitch.org/repo/deb/freeswitch-1.6/key.gpg |apt-key add -
fi
# install FreeSWITCH
apt-get update
apt-get -y install freeswitch-all
# apt-get -y install python-esl
# Check that FreeSWITCH installation succeed
if [ ! -f /usr/bin/freeswitch ]; then
echo ""
echo "File /usr/bin/freeswitch not found..."
echo ">> FreeSWITCH installation failed!"
echo ""
exit 255
fi
}
# Install LuaSQL
func_install_luasql() {
if [ ! -d "/usr/src/luasql-2.3.0" ]; then
echo ""
echo "LuaSQL will now be installed..."
echo ""
# Install Dependencies
apt-get -y install lua5.2 liblua5.2-dev
apt-get -y install 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
# Compile and install
make
make install
fi
}
func_configure_fs() {
echo ""
echo "Enable FreeSWITCH modules"
echo ""
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
}
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
}
# Warning this doesnt work yes with systemd (Debian 8)
func_automatic_bootstart() {
# link config files from source build to their expected F.H.S. locations to keep init script happy
ln /usr/local/freeswitch/bin/freeswitch /usr/bin/freeswitch
mkdir /etc/freeswitch
ln /usr/local/freeswitch/conf/freeswitch.xml /etc/freeswitch/freeswitch.xml
chown freeswitch:daemon /etc/freeswitch
chmod ug=rwx,o= /etc/freeswitch
mkdir /var/lib/freeswitch
chown freeswitch:daemon /var/lib/freeswitch
chmod -R ug=rwX,o= /var/lib/freeswitch
cp /usr/src/freeswitch.git/debian/freeswitch-sysvinit.freeswitch.default /etc/default/freeswitch
chown freeswitch:daemon /etc/default/freeswitch
chmod ug=rw,o= /etc/default/freeswitch
cp /usr/src/freeswitch.git/debian/freeswitch-sysvinit.freeswitch.init /etc/init.d/freeswitch
chown freeswitch:daemon /etc/init.d/freeswitch
chmod u=rwx,g=rx,o= /etc/init.d/freeswitch
update-rc.d freeswitch defaults
# optionally, to make manual start-up and shutdown of FreeSWITCH a bit easier
ln /etc/init.d/freeswitch /usr/local/bin/fs
}
#Install FreeSWITCH from Debian packages
#install_fs_deb_packages
#Install FreeSWITCH from sources
func_install_fs_sources
#Install luaSQL
func_install_luasql
#Create alias fs_cli
func_create_alias_fs_cli
#Configure FreeSWITCH
func_configure_fs
#Start FreeSWITCH
cd /usr/local/freeswitch/
./bin/freeswitch -ncwait -nonat
if [ -f "/usr/bin/freeswitch" ]; then
echo ""
echo "*********************************************"
echo "Congratulations, FreeSWITCH is now installed!"
echo "*********************************************"
echo ""
echo "cd /usr/local/freeswitch/"
echo "./bin/fs_cli"
echo ""
else
echo ""
echo "FreeSWITCH installation failed!"
echo ""
exit 255
fi
cd $FS_BASE_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment