forked from cdr-stats/cdr-stats
-
Notifications
You must be signed in to change notification settings - Fork 10
/
install-freeswitch.sh
executable file
·254 lines (219 loc) · 10.8 KB
/
install-freeswitch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/bash
#
# CDR-Stats License
# http://www.cdr-stats.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#
#
# To download and run the script on your server :
# cd /usr/src/ ; wget --no-check-certificate https://raw.github.com/Star2Billing/cdr-stats/master/install/install-freeswitch.sh -O install-freeswitch.sh ; bash install-freeswitch.sh
BRANCH='master'
KERNELARCH=$(uname -p)
#Get Scripts dependencies
cd /usr/src/
wget --no-check-certificate https://raw.github.com/Star2Billing/cdr-stats/$BRANCH/install/bash-common-functions.sh -O bash-common-functions.sh
#Include general functions
source bash-common-functions.sh
#Identify the OS
func_identify_os
FS_CONF_PATH=https://raw.github.com/Star2Billing/cdr-stats/$BRANCH/install/freeswitch-conf
FS_INIT_PATH=https://raw.github.com/Star2Billing/cdr-stats/$BRANCH/install/freeswitch-init
FS_GIT_REPO=git://git.freeswitch.org/freeswitch.git
FS_INSTALLED_PATH=/usr/local/freeswitch
FS_CONFIG_PATH=/etc/freeswitch
#####################################################
FS_BASE_PATH=/usr/src/
#####################################################
CURRENT_PATH=$PWD
clear
echo ""
echo "FreeSWITCH will be installed in $FS_INSTALLED_PATH"
echo "Press Enter to continue or CTRL-C to exit"
echo ""
read INPUT
func_install_fs_source() {
#install fs from source
echo "installing from source"
#Add Freeswitch group and user
grep -c "^freeswitch:" /etc/group &> /dev/null
if [ $? = 1 ]; then
/usr/sbin/groupadd -r -f freeswitch
else
echo "group freeswitch already present"
fi
grep -c "^freeswitch:" /etc/passwd &> /dev/null
if [ $? = 1 ]; then
echo "adding user freeswitch..."
/usr/sbin/useradd -r -c "freeswitch" -g freeswitch freeswitch
else
echo "user freeswitch already present"
fi
# Install FreeSWITCH
cd $FS_BASE_PATH
git clone $FS_GIT_REPO
cd $FS_BASE_PATH/freeswitch
sh bootstrap.sh && ./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/#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" \
-e "s/#event_handlers\/mod_cdr_mongodb/event_handlers\/mod_cdr_mongodb/g" \
modules.conf
make && make install && make sounds-install && make moh-install
#Set permissions
chown -R freeswitch:freeswitch /usr/local/freeswitch /etc/freeswitch
}
echo "Setting up Prerequisites and Dependencies for FreeSWITCH"
case $DIST in
'DEBIAN')
apt-get -y update
apt-get -y install autoconf automake autotools-dev binutils bison build-essential cpp curl flex g++ gcc git-core libaudiofile-dev libc6-dev libdb-dev libexpat1 libgdbm-dev libgnutls-dev libmcrypt-dev libncurses5-dev libnewt-dev libpcre3 libpopt-dev libsctp-dev libsqlite3-dev libtiff4 libtiff4-dev libtool libx11-dev libxml2 libxml2-dev lksctp-tools lynx m4 make mcrypt ncftp nmap openssl sox sqlite3 ssl-cert ssl-cert unixodbc-dev unzip zip zlib1g-dev zlib1g-dev
apt-get -y install libssl-dev pkg-config
apt-get -y install libvorbis0a libogg0 libogg-dev libvorbis-dev
apt-get -y install flite flite1-dev
#Install Freeswitch
func_install_fs_source
;;
'CENTOS')
echo ""
echo "Do you want to install Freeswitch via the yum repository instead of from source [y/n]"
read YUMSOURCE
yum -y update
yum -y install autoconf automake bzip2 cpio curl curl-devel curl-devel expat-devel fileutils gcc-c++ gettext-devel gnutls-devel libjpeg-devel libogg-devel libtiff-devel libtool libvorbis-devel make ncurses-devel nmap openssl openssl-devel openssl-devel perl patch unixODBC unixODBC-devel unzip wget zip zlib zlib-devel
yum -y install flite
#install the RPMFORGE Repository
if [ ! -f /etc/yum.repos.d/rpmforge.repo ];
then
# Install RPMFORGE Repo
if [ $KERNELARCH = "x86_64" ]; then
rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
else
rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
fi
fi
yum -y --enablerepo=rpmforge install git-core
if [ "$YUMSOURCE" = "y" ] || [ "$YUMSOURCE" = "Y" ]; then
echo "Installing via yum repository"
# install the Freeswitch Repo
rpm -Uvh http://files.freeswitch.org/yum/freeswitch-release-1-0.noarch.rpm
# install the freeswitch files
yum -y install freeswitch-config-vanilla freeswitch-codec-siren freeswitch-codec-passthru-amr freeswitch-application-conference freeswitch-application-db freeswitch-endpoint-dingaling freeswitch-application-enum freeswitch-application-esf freeswitch-application-expr freeswitch-application-fifo freeswitch-asrtts-flite freeswitch-application-fsv freeswitch-codec-passthru-g723_1 freeswitch-codec-passthru-g729 freeswitch-codec-h26x freeswitch-application-hash freeswitch-application-httapi freeswitch-codec-ilbc freeswitch-format-local-stream freeswitch-lua freeswitch-format-native-file freeswitch-lang-de freeswitch-lang-en freeswitch-lang-fr freeswitch-lang-ru freeswitch-format-mod-shout freeswitch-codec-speex freeswitch-spidermonkey freeswitch-format-tone-stream freeswitch-asrtts-tts-commandline freeswitch-application-valet_parking freeswitch-application-voicemail freeswitch-format-shell-stream freeswitch-event-cdr-mongodb
else
echo "installing from source"
func_install_fs_source
fi
;;
esac
# 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_xml_curl\"\/>\s?-->/<load module=\"mod_xml_curl\"\/>/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"\/> <load module="mod_cdr_mongodb"\/>/' \
modules.conf.xml
#Rename default mongodb database
sed -i "s/test.cdr/freeswitch.cdr/g" cdr_mongodb.conf.xml
#Configure Dialplan
cd $FS_CONFIG_PATH/conf/dialplan/
#Return to current path
cd $CURRENT_PATH
case $DIST in
'DEBIAN')
#Install init.d script
wget --no-check-certificate $FS_INIT_PATH/debian/freeswitch -O /etc/init.d/freeswitch
chmod 0755 /etc/init.d/freeswitch
cd /etc/init.d; update-rc.d freeswitch defaults 90
;;
'CENTOS')
#Install init.d script
wget --no-check-certificate $FS_INIT_PATH/centos/freeswitch -O /etc/init.d/freeswitch
chmod 0755 /etc/init.d/freeswitch
chkconfig --add freeswitch
chkconfig --level 345 freeswitch on
;;
esac
#replace with our own working init script as per http://jira.freeswitch.org/browse/FS-4042
if [ "$YUMSOURCE" = "y" ] || [ "$YUMSOURCE" = "Y" ]; then
echo "Installed via yum repository"
#replace with our own working init script as per http://jira.freeswitch.org/browse/FS-4042
rm -f /etc/init.d/freeswitch
#Install init.d script
wget --no-check-certificate $FS_INIT_PATH/centos/freeswitch -O /etc/init.d/freeswitch
chmod 0755 /etc/init.d/freeswitch
chkconfig --add freeswitch
chkconfig --level 345 freeswitch on
sed -i "s@/usr/local/freeswitch/bin@/usr/bin@g" /etc/init.d/freeswitch
sed -i "s@/usr/local/freeswitch/run@/var/run/freeswitch@g" /etc/init.d/freeswitch
else
echo "installing from source"
#Add alias 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
fi
#Extra configuration for FreeSwitch
#Update crontab to add Core.db Freeswitch Update
grep -c "^freeswitch" /var/spool/cron/crontabs/root &> /dev/null
if [ $? = 1 ]; then
echo "* * * * * echo 'ALTER TABLE channels ADD accountcode VARCHAR(50);' | sqlite3 /usr/local/freeswitch/db/core.db" >> /var/spool/cron/crontabs/root
/etc/init.d/cron restart
else
echo "cront already present"
fi
#ADD XML Config files for FreeSwitch
cp /etc/freeswitch/dialplan/default.xml /etc/freeswitch/dialplan/default.xml.backup.cdrstats
wget --no-check-certificate $FS_CONF_PATH/default.xml -O /etc/freeswitch/dialplan/default.xml
cp /etc/freeswitch/dialplan/public.xml /etc/freeswitch/dialplan/public.xml.backup.cdrstats
wget --no-check-certificate $FS_CONF_PATH/public.xml -O /etc/freeswitch/dialplan/public.xml
#Restart FreeSwitch
/etc/init.d/freeswitch restart
# Install Complete
#clear
echo ""
echo ""
echo ""
echo "**************************************************************"
echo "Congratulations, FreeSWITCH is now installed at '$FS_INSTALLED_PATH'"
echo "**************************************************************"
echo
echo "* To Start FreeSWITCH in foreground :"
echo " '$FS_INSTALLED_PATH/bin/freeswitch'"
echo
echo "* To Start FreeSWITCH in background :"
echo " '$FS_INSTALLED_PATH/bin/freeswitch -nc'"
echo
echo "**************************************************************"
echo ""
echo ""