forked from playsms/playsms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·370 lines (322 loc) · 8.48 KB
/
install.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
361
362
363
364
365
366
367
368
369
370
#!/bin/bash
USERID=$(id -u)
if [ "$USERID" = "0" ]; then
echo
echo "You are running this installation script as root"
echo
echo "Aborting installation, please run as normal Linux user"
echo
exit 1
fi
INSTALLCONF="./install.conf"
if [ -n "$1" ]; then
if [ -e "$1" ]; then
INSTALLCONF=$1
fi
fi
if [ ! -e "$INSTALLCONF" ]; then
echo
echo "ERROR: unable to find install.conf"
echo
echo "Please rename install.conf.dist to install.conf"
echo " cp install.conf.dist install.conf"
echo
echo "Edit install.conf to suit your system configuration"
echo " vi install.conf"
echo
echo "Please re-run this script once install.conf edited and saved"
echo " ./install.sh"
echo
exit 1
fi
. $INSTALLCONF
# ========================================
# DO NOT CHANGE ANYTHING BELOW THIS LINE #
# UNLESS YOU KNOW WHAT YOU'RE DOING #
# ========================================
clear
echo
echo "playSMS Install Script"
echo
echo "==================================================================="
echo "WARNING:"
echo "- This install script WILL NOT backup currently installed playSMS"
echo "- This install script WILL NOT upgrade currently installed playSMS"
echo "- This install script WILL REMOVE your current playSMS database"
echo "- This install script is compatible ONLY with playSMS version 1.4.4"
echo "- This install script designed to work only on Linux OS"
echo "- Please BACKUP before proceeding"
echo "==================================================================="
echo
PLAYSMSSRCVER=$(cat $PATHSRC/VERSION.txt)
echo "INSTALL DATA:"
echo
echo "Admin username = admin"
echo "Admin password = $ADMINPASSWORD"
echo "MySQL username = $DBUSER"
echo "MySQL password = $DBPASS"
echo "MySQL database = $DBNAME"
echo "MySQL host = $DBHOST"
echo "MySQL port = $DBPORT"
echo "playSMS web URL = $URLWEB"
echo "playSMS web path = $PATHWEB"
echo "playSMS bin path = $PATHBIN"
echo "playSMS log path = $PATHLOG"
echo "playSMS storage = $PATHSTR"
echo "playSMS source path = $PATHSRC"
echo "playSMS version = $PLAYSMSSRCVER"
echo
echo "==================================================================="
echo
echo "Please read and confirm INSTALL DATA above"
echo
confirm=
while [ -z $confirm ]
do
echo "When you're ready press [y/Y] or press [Control+C] to cancel"
read -p "> " confirm
if [[ $confirm == 'y' ]]; then
break
fi
if [[ $confirm == 'Y' ]]; then
break
fi
confirm=
done
echo
echo "==================================================================="
echo
sleep 1
echo "Checking $PATHWEB..."
echo
if [ -d "$PATHWEB" ] && [ -f "$PATHWEB/init.php" ] && [ -f "$PATHWEB/appsetup.php" ]; then
echo "ERROR: playSMS found installed on $PATHWEB"
echo
echo "Please backup and remove/empty $PATHWEB before proceeding"
echo
exit 1
fi
sleep 1
echo "Checking $PATHSTR..."
echo
if [ -d "$PATHSTR" ] && [ -d "$PATHSTR/composer" ] && [ -d "$PATHSTR/custom" ] && [ -d "$PATHSTR/tmp" ]; then
echo "ERROR: playSMS found installed on $PATHSTR"
echo
echo "Please backup and remove/empty $PATHSTR before proceeding"
echo
exit 1
fi
sleep 1
echo "Checking $PATHBIN/playsmsd..."
echo
if [ -f "$PATHBIN/playsmsd" ]; then
echo "WARNING: playSMS daemon found installed on $PATHBIN"
echo
confirm=
while [ -z $confirm ]
do
echo "To continue and replace $PATHBIN/playsmsd press [y/Y] or press [Control+C] to cancel"
read -p "> " confirm
if [[ $confirm == 'y' ]]; then
break
fi
if [[ $confirm == 'Y' ]]; then
break
fi
confirm=
done
echo
fi
sleep 1
echo "Checking database..."
echo
FOUND_DATABASE=`mysql -u$DBUSER -p$DBPASS -h$DBHOST --skip-column-names --batch -e "SHOW DATABASES LIKE '$DBNAME'" | wc -l`
if [ "$FOUND_DATABASE" == "1" ]; then
echo "Found database '$DBNAME'"
echo
echo "This install script will empty database '$DBNAME'"
echo
confirm=
while [ -z $confirm ]
do
echo "To continue emptying database '$DBNAME' press [y/Y] or press [Control+C] to cancel"
read -p "> " confirm
if [[ $confirm == 'y' ]]; then
break
fi
if [[ $confirm == 'Y' ]]; then
break
fi
confirm=
done
echo
else
echo "ERROR: database '$DBNAME' not found or user have no permission to access '$DBNAME'"
echo
echo "Database '$DBNAME' must be created prior to running this installation script"
echo
echo "Also note that database user '$DBUSER' must be granted permission"
echo "SELECT, INSERT, UPDATE, DELETE to database '$DBNAME'"
echo
exit 1
fi
sleep 1
echo "==================================================================="
echo
sleep 1
echo "Are you sure ?"
echo
echo "Please read and check again the INSTALL DATA above"
echo
confirm=
while [ -z $confirm ]
do
echo "When you're ready press [y/Y] or press [Control+C] to cancel"
read -p "> " confirm
if [[ $confirm == 'y' ]]; then
break
fi
if [[ $confirm == 'Y' ]]; then
break
fi
confirm=
done
echo
echo "==================================================================="
echo
echo "Installation is in progress"
echo
echo -n "DO NOT press [Control+C] until this script ends"
sleep 1
echo -n .
sleep 1
echo -n .
sleep 1
echo -n .
sleep 1
echo
echo
echo "==================================================================="
echo
sleep 1
set +e
echo "Setup database..."
echo
mysql -u$DBUSER -p$DBPASS -h$DBHOST -P$DBPORT $DBNAME < $PATHSRC/db/playsms.sql
ADMINPASSWORD=$(echo -n $ADMINPASSWORD | md5sum | cut -d' ' -f1)
mysql -u$DBUSER -p$DBPASS -h$DBHOST -P$DBPORT $DBNAME -e "UPDATE playsms_tblUser SET password='$ADMINPASSWORD',salt='' WHERE uid=1"
set -e
echo -n "Copying files."
echo -n .
mkdir -p $PATHWEB $PATHLOG $PATHSTR $PATHBIN
if [ ! -d "$PATHWEB" ]; then
echo "ERROR: unable to create $PATHWEB"
echo
exit 1
fi
if [ ! -d "$PATHLOG" ]; then
echo "ERROR: unable to create $PATHLOG"
echo
exit 1
fi
if [ ! -d "$PATHSTR" ]; then
echo "ERROR: unable to create $PATHSTR"
echo
exit 1
fi
if [ ! -d "$PATHBIN" ]; then
echo "ERROR: unable to create $PATHBIN"
echo
exit 1
fi
echo -n .
cp -rf $PATHSRC/web/* $PATHWEB
echo -n .
cp -rf $PATHSRC/storage/* $PATHSTR
echo -n .
echo
echo
echo "Getting composer..."
echo
php -r "readfile('https://getcomposer.org/installer');" | php -q
echo "Move composer.phar to $PATHSTR/composer/"
echo
mkdir -p "$PATHSTR/composer"
mv composer.phar "$PATHSTR/composer/" >/dev/null 2>&1
cp storage/composer/composer.json.dist "$PATHSTR/composer/composer.json" >/dev/null 2>&1
if [ -e "$PATHSTR/composer/composer.json" ]; then
chmod -x "$PATHSTR/composer/composer.json"
else
echo "ERROR: unable to find composer.json on storage directory"
echo
exit 1
fi
if [ -e "$PATHSTR/composer/composer.phar" ]; then
chmod +x "$PATHSTR/composer/composer.phar"
if [ -x "$PATHSTR/composer/composer.phar" ]; then
echo "Getting packages..."
echo
$PATHSTR/composer/composer.phar --working-dir="$PATHSTR/composer/" update
echo
else
echo "ERROR: unable to get composer from https://getcomposer.com"
echo
exit 1
fi
else
echo "ERROR: unable to get composer from https://getcomposer.com"
echo
exit 1
fi
cp $PATHSTR/custom/application/configs/config-dist.php $PATHSTR/custom/application/configs/config.php
echo -n .
sed -i "s|#DBHOST#|$DBHOST|g" $PATHSTR/custom/application/configs/config.php
echo -n .
sed -i "s|#DBPORT#|$DBPORT|g" $PATHSTR/custom/application/configs/config.php
echo -n .
sed -i "s|#DBNAME#|$DBNAME|g" $PATHSTR/custom/application/configs/config.php
echo -n .
sed -i "s|#DBUSER#|$DBUSER|g" $PATHSTR/custom/application/configs/config.php
echo -n .
sed -i "s|#DBPASS#|$DBPASS|g" $PATHSTR/custom/application/configs/config.php
echo -n .
cp $PATHWEB/appsetup-dist.php $PATHWEB/appsetup.php
echo -n .
sed -i "s|#PATHLOG#|$PATHLOG|g" $PATHWEB/appsetup.php
echo -n .
sed -i "s|#PATHBIN#|$PATHBIN|g" $PATHWEB/appsetup.php
echo -n .
sed -i "s|#PATHSTR#|$PATHSTR|g" $PATHWEB/appsetup.php
echo -n .
sed -i "s|#PATHWEB#|$PATHWEB|g" $PATHWEB/appsetup.php
echo -n .
sed -i "s|#URLWEB#|$URLWEB|g" $PATHWEB/appsetup.php
echo -n .
rm -f $PATHBIN/playsmsd
cp -rR $PATHSRC/bin/playsmsd.php $PATHBIN/playsmsd
chmod 700 $PATHBIN/playsmsd
echo -n .
echo "done"
echo
touch $PATHLOG/playsms.log >/dev/null 2>&1
chmod 664 $PATHLOG/playsms.log >/dev/null 2>&1
touch $PATHLOG/audit.log >/dev/null 2>&1
chmod 664 $PATHLOG/audit.log >/dev/null 2>&1
export PLAYSMS_WEB="$PATHWEB"
echo "Checking installation..."
$PATHBIN/playsmsd check
sleep 3
echo
echo "Restarting playSMS daemon..."
$PATHBIN/playsmsd restart
sleep 3
echo
echo "Checking playSMS daemon status..."
$PATHBIN/playsmsd status
sleep 3
echo
echo "playSMS install script finished"
echo
echo "Please review installation log above before testing"
echo
exit 0