-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathpreinstall.sh
executable file
·360 lines (280 loc) · 10.7 KB
/
preinstall.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
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
#!/bin/bash
fUsage () {
echo "Usage: $0 -y [--webuser=www] [--softswitch_dir=/usr/local/freeswitch/conf/]"
exit 1
}
fWelcome() {
clear
echo "========================================================"
echo " ______ _ _ _ _______ ______ _______ _ _ "
echo "(____ \(_) (_) (_|_______|____ \(_______|_) (_)"
echo " ____) )_ _ _ _____ ____) )_ _ ___ "
echo "| __ (| | | | | | ___) | __ (| | | | | | "
echo "| |__) ) |____| |___| | |_____| |__) ) |___| |/ / \ \ "
echo "|______/|_______)_____/|_______)______/ \_____/|_| |_|"
echo
echo " - - - Our free software. Your next VoIP system!"
echo "========================================================"
}
fConfirmYes() {
echo -n "$1? "
if [ ! -z $accept_all ]; then
echo
return 1
fi
read ans
case "$ans" in
n|N|no|NO|No) return 1 ;;
*) return 0 ;;
esac
}
fConfirmNo() {
echo -n "$1? "
if [ ! -z $accept_all ]; then
echo
return 0
fi
read ans
case "$ans" in
y|Y|yes|YES|Yes) return 0 ;;
*) return 1 ;;
esac
fConfirmNo "$1"
}
fCheckSELinux() {
if which getenforce &> /dev/null; then
res=`getenforce | grep -i enforcing`;
if [[ ${#res} > 0 ]]; then
echo
echo "SELINUX"
echo "---------------------------------------------------------"
echo "We have detected that selinux is enabled. This will cause"
echo "issues as it inhibits the webservers ability to write to"
echo "the softswitch config."
if fConfirmYes "Would you like to disable selinux (Y/n)"; then
echo '# selinuxenabled 0'
selinuxenabled 0 2>&1
echo "# sed -i -r 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config"
sed -i -r 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config 2>&1
fi
else
echo
echo "SELINUX"
echo "---------------------------------------------------------"
echo "The system appears to have SELINUX disabled . . . OK"
fi
else
echo
echo "SELINUX"
echo "---------------------------------------------------------"
echo "Assuming SELINUX is not on this server . . . OK"
fi
}
fSetWebUser() {
webuser_guess=nobody
if which id &> /dev/null; then
id -g www &>/dev/null
[ $? -eq 0 ] && webuser_guess=www
id -g www-data &>/dev/null
[ $? -eq 0 ] && webuser_guess=www-data
id -g apache &>/dev/null
[ $? -eq 0 ] && webuser_guess=apache
fi
# This was for MAC, not sure if it is needed
[ `uname` = 'Darwin' ] && webuser_guess='www'
[ ! -z $webuser ] && webuser_guess=$webuser
echo
echo "WEB USER"
echo "---------------------------------------------------------"
echo "We need to verify the web user so we can correctly set "
echo "the permissions on certain folder/files."
echo -n "Web user name [$webuser_guess]? "
if [ ! -z $accept_all ]; then
webuser="$webuser_guess"
echo
else
read ans
if [ -z $ans ]; then
webuser="$webuser_guess"
else
webuser="$ans"
fi
fi
}
fUpdateBlueboxPerm() {
echo
echo "BLUEBOX PRIVILEGES"
echo "---------------------------------------------------------"
echo "Updating the permissions so Blue.box can write to its "
echo "configuration files."
[ ! -d bluebox/logs ] && echo "# mkdir -p bluebox/logs" && mkdir -p bluebox/logs 2>&1
echo "# chgrp -R $webuser bluebox/logs/"
chgrp -R $webuser bluebox/logs/
echo "# chmod -R g+w bluebox/logs"
chmod -R g+w bluebox/logs
[ ! -d bluebox/cache ] && echo "# mkdir -p bluebox/cache" && mkdir -p bluebox/cache 2>&1
echo "# chgrp -R $webuser bluebox/cache/"
chgrp -R $webuser bluebox/cache/
echo "# chmod -R g+w bluebox/cache"
chmod -R g+w bluebox/cache
echo "# chgrp -R $webuser bluebox/config/"
chgrp -R $webuser bluebox/config/
echo "# chmod -R g+w bluebox/config/"
chmod -R g+w bluebox/config/
echo "# chgrp -R $webuser modules/freeswitch-*/config/freeswitch.php"
chgrp -R $webuser modules/freeswitch-*/config/freeswitch.php
echo "# chmod -R g+w modules/freeswitch-*/config/freeswitch.php"
chmod -R g+w modules/freeswitch-*/config/freeswitch.php
echo "# chgrp -R $webuser modules/asterisk-*/config/asterisk.php"
chgrp -R $webuser modules/asterisk-*/config/asterisk.php
echo "# chmod -R g+w modules/asterisk-*/config/asterisk.php"
chmod -R g+w modules/asterisk-*/config/asterisk.php
[ ! -d uploads/ ] && echo "# mkdir uploads/" && mkdir -p uploads/ 2>&1
echo "# chgrp -R $webuser uploads/"
chgrp -R $webuser uploads/
echo "# chmod -R g+w uploads/"
chmod -R g+w uploads/
}
fFixSoundsPerms() {
[ -d '/var/lib/asterisk/sounds/' ] && sounddir_guess="/var/lib/asterisk/sounds"
[ -d '/usr/local/freeswitch/sounds/' ] && sounddir_guess="/usr/local/freeswitch/sounds"
[ -d '/opt/freeswitch/sounds/' ] && sounddir_guess="/opt/freeswitch/sounds"
echo
echo "SOUND FILE PRIVILEGES"
echo "---------------------------------------------------------"
echo "We need to verify the path to your sound files."
echo -n "Sound file dir [$sounddir_guess]? "
if [ ! -z $accept_all ]; then
sound_dir="$sounddir_guess"
echo
else
read ans
if [ -z $ans ]; then
sound_dir="$sounddir_guess"
else
sound_dir="$ans"
fi
fi
[ -z "$sound_dir" -o ! -d "$sound_dir" ] && return 0
echo "# chgrp -R $webuser $sound_dir"
chgrp -R $webuser $sound_dir
echo "# chmod -R g+w $sound_dir"
chmod -R g+w $sound_dir
}
fFixRecordsPerms() {
[ -d '/usr/local/freeswitch/recordings/' ] && recorddir_guess="/usr/local/freeswitch/recordings"
[ -d '/opt/freeswitch/recordings/' ] && recorddir_guess="/opt/freeswitch/recordings"
echo
echo "RECORDING FILE PRIVILEGES"
echo "---------------------------------------------------------"
echo "We need to verify the path to your recording files."
echo -n "Record file dir [$recorddir_guess]? "
if [ ! -z $accept_all ]; then
record_dir="$recorddir_guess"
echo
else
read ans
if [ -z $ans ]; then
record_dir="$recorddir_guess"
else
record_dir="$ans"
fi
fi
[ -z "$record_dir" -o ! -d "$record_dir" ] && return 0
echo "# chgrp -R $webuser $record_dir"
chgrp -R $webuser $record_dir
echo "# chmod -R g+w $record_dir"
chmod -R g+w $record_dir
}
fUpdateSwitchPerm() {
[ -d '/usr/local/freeswitch/conf/' ] && softswitch_guess="/usr/local/freeswitch/conf"
[ -d '/opt/freeswitch/conf/' ] && softswitch_guess="/opt/freeswitch/conf"
[ -d '/etc/asterisk/' ] && softswitch_guess="/etc/asterisk"
[ ! -z $softswitch_dir ] && softswitch_guess=$softswitch_dir
echo
echo "SOFTSWITCH PRIVILEGES"
echo "---------------------------------------------------------"
echo "We need to verify the path to your softswitch confs "
echo "directory so we can update its permissions."
echo -n "Softswitch conf dir [$softswitch_guess]? "
if [ ! -z $accept_all ]; then
softswitch_dir="$softswitch_guess"
echo
else
read ans
if [ -z $ans ]; then
softswitch_dir="$softswitch_guess"
else
softswitch_dir="$ans"
fi
fi
[ -z "$softswitch_dir" -o ! -d "$softswitch_dir" ] && return 0
echo "# chgrp -R $webuser $softswitch_dir"
chgrp -R $webuser $softswitch_dir
echo "# chmod -R g+w $softswitch_dir"
chmod -R g+w $softswitch_dir
}
fCopyConfigs() {
echo "Checking config files"
[ ! -e 'bluebox/config/config.php' ] && echo "# Copying bluebox/config/config.php" && cp bluebox/config/config.php.dist bluebox/config/config.php 2>&1
[ ! -e 'bluebox/config/database.php' ] && echo "# Copying bluebox/config/database.php" && cp bluebox/config/database.php.dist bluebox/config/database.php 2>&1
[ ! -e 'bluebox/config/email.php' ] && echo "# Copying bluebox/config/email.php" && cp bluebox/config/email.php.dist bluebox/config/email.php 2>&1
[ ! -e 'bluebox/config/locale.php' ] && echo "# Copying bluebox/config/locale.php" && cp bluebox/config/locale.php.dist bluebox/config/locale.php 2>&1
[ ! -e 'bluebox/config/session.php' ] && echo "# Copying bluebox/config/session.php" && cp bluebox/config/session.php.dist bluebox/config/session.php 2>&1
[ ! -e 'bluebox/config/telephony.php' ] && echo "# Copying bluebox/config/telephony.php" && cp bluebox/config/telephony.php.dist bluebox/config/telephony.php 2>&1
[ ! -e 'bluebox/config/upload.php' ] && echo "# Copying bluebox/config/upload.php" && cp bluebox/config/upload.php.dist bluebox/config/upload.php 2>&1
[ ! -e 'modules/freeswitch-1.1.1/config/freeswitch.php' ] && echo "# Copying modules/freeswitch-1.1.1/config/freeswitch.php" && cp modules/freeswitch-1.1.1/config/freeswitch.php.dist modules/freeswitch-1.1.1/config/freeswitch.php 2>&1
[ ! -e 'modules/asterisk-1.0/config/asterisk.php' ] && echo "# Copying modules/asterisk-1.0/config/asterisk.php" && cp modules/asterisk-1.0/config/asterisk.php.dist modules/asterisk-1.0/config/asterisk.php 2>&1
}
cd `dirname $0`
while [ -n "$*" ]; do
case "x$1" in
x--webuser=*)
webuser=`echo "$1"|cut -d= -sf2`
;;
x--softswitch_dir=*)
softswitch_dir=`echo "$1"|cut -d= -sf2`
;;
x--sound_dir=*)
sound_dir=`echo "$1"|cut -d= -sf2`
;;
x-y)
accept_all=1
;;
x--help)
fUsage
;;
*)
fUsage
;;
esac
shift
done
fWelcome
fCheckSELinux
fCopyConfigs
fSetWebUser
fUpdateBlueboxPerm
fUpdateSwitchPerm
fFixSoundsPerms
fFixRecordsPerms
echo
echo "PLEASE SET UP YOUR DB"
echo "---------------------------------------------------------"
echo "You must now ensure your database has a user configured "
echo "for Blue.box, you will enter the credintials in the next"
echo "phase."
#echo
#echo "In mysql cli you can create a user via:"
#echo "# CREATE USER 'bluebox'@'127.0.0.1' IDENTIFIED BY 'bluebox';"
#echo "# GRANT ALL ON bluebox.* TO 'bluebox'@'127.0.0.1';"
#echo "# FLUSH PRIVILEGES;"
echo
echo "COMPLETE!"
echo "---------------------------------------------------------"
echo "Now point your web browser to your server and the "
echo "Blue.box installer will get your system ready."
echo "Example http://127.0.0.1/"
echo
echo " Welcome and thank you for using Blue.Box!"
exit 0