forked from joglomedia/LEMPer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lemper.sh
executable file
·354 lines (292 loc) · 11.1 KB
/
lemper.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
#!/bin/bash
# +-------------------------------------------------------------------------+
# | LEMPer.sh is a simple LEMP stack installer for Debian/Ubuntu |
# |-------------------------------------------------------------------------+
# | Features : |
# | - Nginx latest |
# | - MariaDB 10 (MySQL drop-in replacement) |
# | - PHP latest |
# | - Zend OpCache |
# | - Memcached latest |
# | - ionCube Loader |
# | - SourceGuardian Loader |
# | - Adminer (PhpMyAdmin replacement) |
# | Min requirement : GNU/Linux Ubuntu 14.04 or Linux Mint 17 |
# | Last Update : 10/08/2019 |
# | Author : ESLabs.ID ([email protected]) |
# | Version : 1.0.0 |
# +-------------------------------------------------------------------------+
# | Copyright (c) 2014-2019 ESLabs (https://eslabs.id/lemper) |
# +-------------------------------------------------------------------------+
# | This source file is subject to the GNU General Public License |
# | that is bundled with this package in the file LICENSE.md. |
# | |
# | If you did not receive a copy of the license and are unable to |
# | obtain it through the world-wide-web, please send an email |
# | to [email protected] so we can send you a copy immediately. |
# +-------------------------------------------------------------------------+
# | Authors: Edi Septriyanto <[email protected]> |
# +-------------------------------------------------------------------------+
# Work even if somebody does "sh lemper.sh".
set -e
# Try to export global path.
if [ -z "${PATH}" ] ; then
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
fi
# Get installer base directory.
export BASEDIR && \
BASEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
# Include helper functions.
if [ "$(type -t run)" != "function" ]; then
. scripts/helper.sh
fi
# Make sure only root can run this installer script.
requires_root
# Make sure only supported distribution can run this installer script.
system_check
##
# Main
#
case "${1}" in
"--install")
header_msg
echo "Starting LEMP stack installation..."
echo "Please ensure that you're on a fresh install!"
if ! "${AUTO_INSTALL}"; then
echo ""
read -t 60 -rp "Press [Enter] to continue..." </dev/tty
fi
# Init log.
run init_log
# Init config.
run init_config
### Clean-up server ###
echo ""
if [ -f scripts/cleanup_server.sh ]; then
. ./scripts/cleanup_server.sh
fi
### Install dependencies packages ###
echo ""
if [ -f scripts/install_dependencies.sh ]; then
. ./scripts/install_dependencies.sh
fi
### Check and enable swap ###
echo ""
enable_swap
### Create default account ###
echo ""
create_account "${LEMPER_USERNAME}"
### Certbot Let's Encrypt SSL installation ###
if [ -f scripts/install_certbotle.sh ]; then
echo ""
. ./scripts/install_certbotle.sh
fi
### Nginx installation ###
if [ -f scripts/install_nginx.sh ]; then
echo ""
. ./scripts/install_nginx.sh
fi
### PHP installation ###
if [ -f scripts/install_php.sh ]; then
echo ""
. ./scripts/install_php.sh
fi
### Imagick installation ###
if [ -f scripts/install_imagemagick.sh ]; then
echo ""
. ./scripts/install_imagemagick.sh
fi
### Memcached installation ###
if [ -f scripts/install_memcached.sh ]; then
echo ""
. ./scripts/install_memcached.sh
fi
### Phalcon PHP installation ###
if [ -f scripts/install_phalcon.sh ]; then
echo ""
. ./scripts/install_phalcon.sh
fi
### MySQL database installation ###
if [ -f scripts/install_mariadb.sh ]; then
echo ""
. ./scripts/install_mariadb.sh
fi
### Redis database installation ###
if [ -f scripts/install_redis.sh ]; then
echo ""
. ./scripts/install_redis.sh
fi
### MongoDB database installation ###
if [ -f scripts/install_mongodb.sh ]; then
echo ""
. ./scripts/install_mongodb.sh
fi
### Mail server installation ###
if [ -f scripts/install_mailer.sh ]; then
echo ""
. ./scripts/install_mailer.sh
fi
### Addon-tools installation ###
if [ -f scripts/install_tools.sh ]; then
echo ""
. ./scripts/install_tools.sh
fi
### Fail2ban, intrusion prevention software framework that protects computer servers from brute-force attacks. ###
if [ -f scripts/install_fail2ban.sh ]; then
echo ""
. ./scripts/install_fail2ban.sh
fi
### Basic server security ###
if [ -f scripts/secure_server.sh ]; then
echo ""
. ./scripts/secure_server.sh "--install"
fi
### FINAL STEP ###
if "${FORCE_REMOVE}"; then
# Cleaning up all build dependencies hanging around on production server?
echo -e "\nClean up installation process..."
run apt-get -qq autoremove -y
# Cleanup build dir
echo "Clean up build directory..."
if [ -d "$BUILD_DIR" ]; then
run rm -fr "$BUILD_DIR"
fi
fi
if "${DRYRUN}"; then
warning -e "\nLEMPer installation has been completed in dry-run mode."
else
status -e "\nCongrats, your LEMP stack installation has been completed."
### Recap ###
if [[ -n "${PASSWORD}" ]]; then
CREDENTIALS="
Here is your default system account information:
Hostname : ${HOSTNAME}
Server IP: ${SERVER_IP}
SSH Port : ${SSH_PORT}
Username : ${USERNAME}
Password : ${PASSWORD}
Access to your Database administration (Adminer):
http://${SERVER_IP}:8082/lcp/dbadmin/
Database root password: ${MYSQL_ROOT_PASS}
Mariabackup user information:
DB Username: ${MARIABACKUP_USER}
DB Password: ${MARIABACKUP_PASS}
Access to your File manager (TinyFileManager):
http://${SERVER_IP}:8082/lcp/filemanager/
Please Save & Keep It Private!
~~~~~~~~~~~~~~~~~~~~~~~~~o0o~~~~~~~~~~~~~~~~~~~~~~~~~"
status "${CREDENTIALS}"
# Save it to log file
save_log "${CREDENTIALS}"
fi
fi
echo "
See the log file (lemper.log) for more information.
Now, you can reboot your server and enjoy it!"
;;
"--remove"|"--uninstall")
header_msg
echo "Are you sure to remove LEMP stack installation?"
echo "Please ensure that you've back up your critical data!"
if ! "${AUTO_REMOVE}"; then
echo ""
read -rt 15 -p "Press [Enter] to continue..." </dev/tty
fi
# Fix broken install, first?
echo ""
run dpkg --configure -a
run apt-get --fix-broken install
### Remove Nginx ###
if [ -f scripts/remove_nginx.sh ]; then
echo ""
. ./scripts/remove_nginx.sh
fi
### Remove PHP & FPM ###
if [ -f scripts/remove_php.sh ]; then
echo ""
. ./scripts/remove_php.sh
fi
### Remove MySQL ###
if [ -f scripts/remove_mariadb.sh ]; then
echo ""
. ./scripts/remove_mariadb.sh
fi
### Remove PHP & FPM ###
if [ -f scripts/remove_memcached.sh ]; then
echo ""
. ./scripts/remove_memcached.sh
fi
### Remove Redis ###
if [ -f scripts/remove_redis.sh ]; then
echo ""
. ./scripts/remove_redis.sh
fi
### Remove MongoDB ###
if [ -f scripts/remove_mongodb.sh ]; then
echo ""
. ./scripts/remove_mongodb.sh
fi
### Remove Certbot LE ###
if [ -f scripts/remove_certbotle.sh ]; then
echo ""
. ./scripts/remove_certbotle.sh
fi
### Remove server security ###
if [ -f scripts/secure_server.sh ]; then
echo ""
. ./scripts/secure_server.sh "--remove"
fi
### Remove
# Remove default user account.
echo ""
echo "Removing created default account..."
if "${AUTO_REMOVE}"; then
REMOVE_ACCOUNT="y"
else
while [[ "${REMOVE_ACCOUNT}" != "y" && "${REMOVE_ACCOUNT}" != "n" ]]; do
read -rp "Remove default LEMPer account? [y/n]: " -i y -e REMOVE_ACCOUNT
done
fi
if [[ "${REMOVE_ACCOUNT}" == Y* || "${REMOVE_ACCOUNT}" == y* || "${FORCE_REMOVE}" == true ]]; then
if [ "$(type -t delete_account)" == "function" ]; then
delete_account "lemper"
fi
fi
# Remove created swap.
echo ""
echo "Removing created swap..."
if "${AUTO_REMOVE}"; then
REMOVE_SWAP="y"
else
while [[ "${REMOVE_SWAP}" != "y" && "${REMOVE_SWAP}" != "n" ]]; do
read -rp "Remove created Swap? [y/n]: " -i y -e REMOVE_SWAP
done
fi
if [[ "${REMOVE_SWAP}" == Y* || "${REMOVE_SWAP}" == y* || "${FORCE_REMOVE}" == true ]]; then
if [ "$(type -t remove_swap)" == "function" ]; then
remove_swap
fi
fi
# Remove tools.
[ -f /usr/local/bin/lemper-cli ] && run rm -f /usr/local/bin/lemper-cli
[ -d /usr/local/lib/lemper ] && run rm -fr /usr/local/lib/lemper
# Clean up existing lemper config.
[ -f /etc/lemper/lemper.conf ] && run rm -f /etc/lemper/lemper.conf
# Remove unnecessary packages.
echo -e "\nCleaning up unnecessary packages..."
run apt-get -qq autoremove -y
status -e "\nLEMP stack has been removed completely."
warning -e "\nDid you know? that we're so sad to see you leave :'(
If you are not satisfied with LEMPer stack or have
any other reasons to uninstall it, please let us know ^^"
;;
--help)
echo "Please read the README file for more information!"
exit 0
;;
*)
fail "Invalid argument: ${1}"
exit 1
;;
esac
footer_msg