forked from kismetgerald/fusionpbx-migrate-fs-src2pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate_fs_src2pkg.sh
More file actions
362 lines (325 loc) · 14.3 KB
/
Copy pathmigrate_fs_src2pkg.sh
File metadata and controls
362 lines (325 loc) · 14.3 KB
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#!/bin/bash
#Define global variables
fs_path="/usr/local/freeswitch"
fs_pkg_conf_dir="/etc/freeswitch"
fpbx_path="/var/www/fusionpbx"
fpbx_src_path="/usr/src/fusionpbx-install.sh/debian/resources/switch/"
f2b_jail_local="/etc/fail2ban/jail.local"
f2b_jail_conf="/etc/fail2ban/jail.conf"
# Functions
main ()
{
clear
echo "${LICENSE}"
read -p "Shall we proceed? [Y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
detect_os
switch_check
# Step 1:
# First we stop the FreeSWITCH service
echo "Stopping FreeSWITCH..."
systemctl stop freeswitch
echo "Done"
echo
# Step 2:
# Rename existing directories which will prevent the package install
# We first check if they exist then rename them
# If they don't exist, then just rename and move on
echo "Renaming ${fs_pkg_conf_dir} (if it exists) to ${fs_pkg_conf_dir}""_old"
if [ -d "${fs_pkg_conf_dir}" ]; then
mv "${fs_pkg_conf_dir}" "${fs_pkg_conf_dir}"\_old
fi
echo
echo "Renaming ${fs_path} to ${fs_path}""_old"
mv "${fs_path}" "${fs_path}"\_old
echo
echo "Checking for the FusionPBX install folder"
if [ -d "${fpbx_src_path}" ]; then
echo "FusionPBX install folder found at ${fpbx_src_path}, switching to it."
cd ${fpbx_src_path} || exit
echo
else
echo "FusionPBX install folder was not found, so let's get it."
cd /usr/src || exit
git clone https://github.com/fusionpbx/fusionpbx-install.sh.git
chmod 755 -R /usr/src/fusionpbx-install.sh
cd /usr/src/fusionpbx-install.sh/debian/resources/switch/ || exit
echo
fi
fi
# Step 3:
# Install FreeSWITCH
echo "Ready to install FreeSWITCH"
sleep 2
echo
read -p "Please make a selection: [1] Official Release [2], Official Release with ALL MODULES, or [3] Master Branch: " answer
#read -r answer
if [[ ${answer} == 1 ]]; then
./package-release.sh
elif [[ ${answer} == 2 ]]; then
./package-all.sh
elif [[ ${answer} == 3 ]]; then
./package-master-all.sh
fi
echo
# Step 4
# Write the following changes to the db. These will adjust the switch paths to those used by the package:
# COLUMNS --> default_setting_subcategory default_setting_name default_setting_value default_setting_enabled
# base dir /usr true
# bin dir null true
# call_center dir /etc/freeswitch/autoload_configs false
# conf dir /etc/freeswitch true
# db dir /var/lib/freeswitch/db true
# diaplan dir /etc/freeswitch/dialplan false
# extensions dir /etc/freeswitch/directory false
# grammar dir /usr/share/freeswitch/grammar true
# log dir /var/log/freeswitch true
# mod dir /usr/lib/freeswitch/mod true
# phrases dir /etc/freeswitch/lang false
# recordings dir /var/lib/freeswitch/recordings true
# scripts dir /usr/share/freeswitch/scripts true
# sip_profiles dir /etc/freeswitch/sip_profiles false
# sounds dir /usr/share/freeswitch/sounds true
# storage dir /var/lib/freeswitch/storage true
# voicemail dir /var/lib/freeswitch/storage/voicemail true
echo "Now updating switch paths in FusionPBX's Default Settings ..."
cd /tmp || exit
sudo -u postgres -- psql -d fusionpbx -t -c "UPDATE v_default_settings
SET default_setting_value = v.value,
default_setting_enabled = v.enabled
FROM (VALUES
('base', '/usr', 'true' ),
('bin', '', 'true' ),
('call_center', '/etc/freeswitch/autoload_configs', 'false'),
('conf', '/etc/freeswitch', 'true' ),
('db', '/var/lib/freeswitch/db', 'true' ),
('dialplan', '/etc/freeswitch/dialplan', 'false'),
('extensions', '/etc/freeswitch/directory', 'false'),
('grammar', '/usr/share/freeswitch/grammar', 'true' ),
('log', '/var/log/freeswitch', 'true' ),
('mod', '/usr/lib/freeswitch/mod', 'true' ),
('phrases', '/etc/freeswitch/lang', 'false'),
('recordings', '/var/lib/freeswitch/recordings', 'true' ),
('scripts', '/usr/share/freeswitch/scripts', 'true' ),
('sip_profiles', '/etc/freeswitch/sip_profiles', 'false'),
('sounds', '/usr/share/freeswitch/sounds', 'true' ),
('storage', '/var/lib/freeswitch/storage', 'true' ),
('voicemail', '/var/lib/freeswitch/storage/voicemail', 'true' )
) AS v(subcategory,value,enabled)
WHERE v.subcategory = v_default_settings.default_setting_subcategory;"
echo "Done updating switch path variables in the database ..."
cd ${fpbx_src_path} || exit
echo
# Step 5(a)
echo "Deleting switch configs pulled down by the package install from /etc/freeswitch ..."
rm -Rf "/etc/freeswitch/*"
if [[ ! -e "${fs_pkg_conf_dir}" ]]; then
mkdir "${fs_pkg_conf_dir}"
fi
echo "Done"
echo
# Step 5(b)
echo "Restoring switch configs from /usr/local/freeswitch_old/* to /etc/freeswitch ..."
cp -adrf /usr/local/freeswitch_old/conf/* /etc/freeswitch
echo "Done"
echo
# Step 5(c)
echo "Patching the lua.conf.xml file so it points to the new scripts directory ..."
sed -i 's~base_dir}/scripts~script_dir}~' /etc/freeswitch/autoload_configs/lua.conf.xml
echo "Done patching the lua.conf.xml file"
echo
# Step 5(d)
# As of 02/14/2016, FreeSWITCH has mod_vpx built into the core thus no longer needing mod_vp8
# Here, we remove mod_vp8 from the database and patch the modules.conf.xml file accordingly
echo "Now removing mod_vp8 from the v_modules tables in the PostgreSQL database"
cd /tmp || exit
sudo -u postgres -- psql -d fusionpbx -t -c "DELETE from v_modules WHERE module_name = 'mod_vp8';"
cd ${fpbx_src_path} || exit
echo "Done"
echo
echo "Now patching the modules.conf.xml file to prevent mod_vp8 from being loaded with FreeSWITCH"
sed -i '/load module="mod_vp8"/d' /etc/freeswitch/autoload_configs/modules.conf.xml
echo "Done"
echo
# Step 5(e)
echo "Now running FusionPBX's App Defaults routine to ensure the switch scripts are in place"
cd /var/www/fusionpbx;php /var/www/fusionpbx/core/upgrade/upgrade.php
echo "Done"
echo
# Step 6
# Let's fix permissions and restart the various services.
echo "Fixing permissions and restarting the various services"
cd "${fpbx_src_path}" || exit
./package-permissions.sh
systemctl daemon-reload
systemctl try-restart freeswitch
systemctl daemon-reload
systemctl restart php5-fpm
systemctl restart nginx
echo "Done"
echo
# Step 7
# Here we update Fail2Ban to look in /var/log/freeswitch/ for the switch logs
if [[ -f "${f2b_jail_local}" ]]; then
echo "Updating log file path in the /etc/fail2ban/jail.local file"
sed -i 's~usr/local/freeswitch/log/freeswitch.log~var/log/freeswitch/freeswitch.log~' /etc/fail2ban/jail.local
elif [[ -f "${f2b_jail_conf}" ]]; then
echo "Updating log file path in the /etc/fail2ban/jail.conf file"
sed -i 's~usr/local/freeswitch/log/freeswitch.log~var/log/freeswitch/freeswitch.log~' /etc/fail2ban/jail.conf
fi
echo
echo "Restarting the Fail2Ban service ..."
systemctl restart fail2ban
echo "Done"
sleep 3
echo
echo
# Step 8
# Let's wrap-up
echo "${FINISH}"
echo
echo
read -p "Reboot the server? [Y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Rebooting server in 10 seconds"
echo "If you change your mind use Ctrl+C to interrupt the reboot."
sleep 10
sudo reboot
fi
}
detect_os ()
{
if [[ ( -z "${os}" ) && ( -z "${dist}" ) ]]; then
# some systems dont have lsb-release yet have the lsb_release binary and
# vice-versa
if [ -e /etc/lsb-release ]; then
. /etc/lsb-release
if [ "${ID}" = "raspbian" ]; then
os=${ID}
dist=$(cut --delimiter='.' -f1 /etc/debian_version)
else
os=${DISTRIB_ID}
dist=${DISTRIB_CODENAME}
if [ -z "${dist}" ]; then
dist=${DISTRIB_RELEASE}
fi
fi
elif [ "$(which lsb_release 2>/dev/null)" ]; then
dist=$(lsb_release -c | cut -f2)
os=$(lsb_release -i | cut -f2 | awk '{ print tolower($1) }')
elif [ -e /etc/debian_version ]; then
# some Debians have jessie/sid in their /etc/debian_version
# while others have '6.0.7'
os=$(cat /etc/issue | head -1 | awk '{ print tolower($1) }')
if grep -q '/' /etc/debian_version; then
dist=$(cut --delimiter='/' -f1 /etc/debian_version)
else
dist=$(cut --delimiter='.' -f1 /etc/debian_version)
fi
else
unknown_os
fi
fi
if [ -z "${dist}" ]; then
unknown_os
fi
# remove whitespace from OS and dist name
os="${os// /}"
dist="${dist// /}"
echo "Detected operating system as ${os}/${dist}."
echo ""
}
unknown_os ()
{
echo "Unfortunately, your operating system distribution and version are not supported by this script."
echo "Please consider using the manual approach, if you know what you're doing!"
echo ""
echo "Exiting...."
echo ""
sleep 5
}
switch_check ()
{
echo "Checking for the existence of FreeSWITCH..."
if [ -d "${fs_path}" ]
then
echo "Excellent! The FreeSWITCH directory (${fs_path}) was found so let's continue."
echo ""
else
echo "Error: Directory ${fs_path} does not exists."
echo ""
echo "The traditional FreeSWITCH path (${fs_path}) was not detected, as such, this script will stop execution."
echo ""
sleep 3
exit 1
fi
}
LICENSE=$( cat << DELIM
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# "THE UAYOR LICENSE" (Version 1)
#
# This is the Use At Your Own Risk (UAYOR) License.
# I, Kismet Agbasi, wrote this script. As long as you retain this notice you can do whatever you want with it. This
# script is just my basic attempt to help automate the process of switching FreeSWITCH from source to packages on an
# existing and fully operational FusionBPX server. I am by no means an expert and this script is not intended to be
# super advanced in anyway.
#
# If you appreciate the rudimentary work and feel you can contribute to making it better in anyway, please consider
# contributing some code via my Github repo.
#
# Author:
# Kismet Agbasi <kagbasi@digitainc.com>
#
# Contributor(s):
# <could you some - email me if you're interested>
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# SOME THINGS TO NOTE BEFORE WE PROCEED:
#
# This script will automatically check your system to ensure it is supported and that a source installation
# of FreeSWITCH actually exists. The traditional path ($fs_path) is used for this check.
# Additionally, there are some files we will need from the FusionPBX installation folders, so if you don't have
# them this script will fetch them for you and place them in ($fpbx_path).
#
# NOTE: If the FreeSWITCH path is not detected this script will not continue!!!
#
# VERY IMPORTANT: IF YOU HAVE NOT BACKED UP YOUR SYSTEM, DO SO NOW!!!
#
# I take no responsibility for a failed system as a result of using this script. If anything should go wrong
# a proper backup should be easy to restore. If you proceed without taking a backup, YOU ARE FULLY RESPONSIBLE!!!
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
DELIM
)
FINISH=$( cat << DELIM
# Congratulations, you have just completed an in-place migration of FreeSWITCH
# from a source compilation to a package install. Some final things to note:
#
# 1. Log back into FusionPBX and check to make sure ALL modules have started and are running:
#
# ADVANCED >> Modules
#
# 2. This is optional, but I chose to reboot the server at this point.
# When the server comes back up, login into FusionPBX and check the Sip Status page to make
# sure your profiles have restarted. That’s it, enjoy!
#
# 3. And to wrap-up, you might consider bringing your system up-to-date via ADVANCED > UPGRADE.
# I did run into some issues with the new changes that had been made with MOH, however, all
#
# If this is the case for you, follow the instructions provided by a member of the #fusionpbx
# IRC channel: http://pastebin.com/fHw0wDjb
#
# If you get this error when placing calls to *9664 to test MOH, then simply restart FreeSWITCH:
# < [ERR] mod_local_stream.c:814 Unknown source default >
DELIM
)
# BEGIN SCRIPT EXECUTION
getdb
main
echo "Done!"
echo
exit