forked from tcisme/lnmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
235 lines (208 loc) · 6.31 KB
/
uninstall.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
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install lnmp"
exit 1
fi
cur_dir=$(pwd)
Stack=$1
LNMP_Ver='1.4'
. lnmp.conf
. include/main.sh
shopt -s extglob
Check_DB
Get_Dist_Name
clear
echo "+------------------------------------------------------------------------+"
echo "| LNMP V${LNMP_Ver} for ${DISTRO} Linux Server, Written by Licess |"
echo "+------------------------------------------------------------------------+"
echo "| A tool to auto-compile & install Nginx+MySQL+PHP on Linux |"
echo "+------------------------------------------------------------------------+"
echo "| For more information please visit https://lnmp.org |"
echo "+------------------------------------------------------------------------+"
Dele_Iptables_Rules()
{
/sbin/iptables -D INPUT -i lo -j ACCEPT
/sbin/iptables -D INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
/sbin/iptables -D INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -D INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -D INPUT -p tcp --dport 443 -j ACCEPT
/sbin/iptables -D INPUT -p tcp --dport 3306 -j DROP
/sbin/iptables -D INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
}
Uninstall_LNMP()
{
echo "Stoping LNMP..."
lnmp kill
lnmp stop
echo "Deleting iptables rules..."
Dele_Iptables_Rules
Remove_StartUp nginx
Remove_StartUp php-fpm
if [ ${DB_Name} != "None" ]; then
Remove_StartUp ${DB_Name}
echo "Backup ${DB_Name} databases directory to /root/databases_backup_$(date +"%Y%m%d%H%M%S")"
if [ ${DB_Name} == "mysql" ]; then
mv ${MySQL_Data_Dir} /root/databases_backup_$(date +"%Y%m%d%H%M%S")
elif [ ${DB_Name} == "mariadb" ]; then
mv ${MariaDB_Data_Dir} /root/databases_backup_$(date +"%Y%m%d%H%M%S")
fi
fi
chattr -i ${Default_Website_Dir}/.user.ini
echo "Deleting LNMP files..."
rm -rf /usr/local/nginx
rm -rf /usr/local/php
rm -rf /usr/local/zend
if [ ${DB_Name} != "None" ]; then
rm -rf /usr/local/${DB_Name}
rm -f /etc/my.cnf
rm -f /etc/init.d/${DB_Name}
fi
for mphp in /usr/local/php[5,7].[0-9]; do
mphp_ver=`echo $mphp|sed 's#/usr/local/php##'`
if [ -s /etc/init.d/php-fpm${mphp_ver} ]; then
/etc/init.d/php-fpm${mphp_ver} stop
Remove_StartUp php-fpm${mphp_ver}
rm -f /etc/init.d/php-fpm${mphp_ver}
fi
if [ -d ${mphp} ]; then
rm -rf ${mphp}
fi
done
rm -f /etc/init.d/nginx
rm -f /etc/init.d/php-fpm
rm -f /bin/lnmp
echo "LNMP Uninstall completed."
}
Uninstall_LNMPA()
{
echo "Stoping LNMPA..."
lnmp kill
lnmp stop
echo "Deleting iptables rules..."
Dele_Iptables_Rules
Remove_StartUp nginx
Remove_StartUp httpd
if [ ${DB_Name} != "None" ]; then
Remove_StartUp ${DB_Name}
echo "Backup ${DB_Name} databases directory to /root/databases_backup_$(date +"%Y%m%d%H%M%S")"
if [ ${DB_Name} == "mysql" ]; then
mv ${MySQL_Data_Dir} /root/databases_backup_$(date +"%Y%m%d%H%M%S")
elif [ ${DB_Name} == "mariadb" ]; then
mv ${MariaDB_Data_Dir} /root/databases_backup_$(date +"%Y%m%d%H%M%S")
fi
fi
echo "Deleting LNMPA files..."
rm -rf /usr/local/nginx
rm -rf /usr/local/php
rm -rf /usr/local/apache
rm -rf /usr/local/zend
if [ ${DB_Name} != "None" ]; then
rm -rf /usr/local/${DB_Name}
rm -f /etc/my.cnf
rm -f /etc/init.d/${DB_Name}
fi
rm -f /etc/init.d/nginx
rm -f /etc/init.d/httpd
rm -f /bin/lnmp
echo "LNMPA Uninstall completed."
}
Uninstall_LAMP()
{
echo "Stoping LAMP..."
lnmp kill
lnmp stop
echo "Deleting iptables rules..."
Dele_Iptables_Rules
Remove_StartUp httpd
if [ ${DB_Name} != "None" ]; then
Remove_StartUp ${DB_Name}
echo "Backup ${DB_Name} databases directory to /root/databases_backup_$(date +"%Y%m%d%H%M%S")"
if [ ${DB_Name} == "mysql" ]; then
mv ${MySQL_Data_Dir} /root/databases_backup_$(date +"%Y%m%d%H%M%S")
elif [ ${DB_Name} == "mariadb" ]; then
mv ${MariaDB_Data_Dir} /root/databases_backup_$(date +"%Y%m%d%H%M%S")
fi
fi
echo "Deleting LAMP files..."
rm -rf /usr/local/apache
rm -rf /usr/local/php
rm -rf /usr/local/zend
if [ ${DB_Name} != "None" ]; then
rm -rf /usr/local/${DB_Name}
rm -f /etc/my.cnf
rm -f /etc/init.d/${DB_Name}
fi
rm -f /etc/my.cnf
rm -f /etc/init.d/httpd
rm -f /bin/lnmp
echo "LAMP Uninstall completed."
}
Check_Stack
echo "Current Stack: ${Get_Stack}"
action=""
echo "Enter 1 to uninstall LNMP"
echo "Enter 2 to uninstall LNMPA"
echo "Enter 3 to uninstall LAMP"
read -p "(Please input 1, 2 or 3): " action
case "$action" in
1|[lL][nN][nM][pP])
echo "You will uninstall LNMP"
Echo_Red "Please backup your configure files and mysql data!!!!!!"
Echo_Red "The following directory or files will be remove!"
cat << EOF
/usr/local/nginx
${MySQL_Dir}
/usr/local/php
/etc/init.d/nginx
/etc/init.d/${DB_Name}
/etc/init.d/php-fpm
/usr/local/zend
/etc/my.cnf
/bin/lnmp
EOF
sleep 3
Press_Start
Uninstall_LNMP
;;
2|[lL][nN][nM][pP][aA])
echo "You will uninstall LNMPA"
Echo_Red "Please backup your configure files and mysql data!!!!!!"
Echo_Red "The following directory or files will be remove!"
cat << EOF
/usr/local/nginx
${MySQL_Dir}
/usr/local/php
/usr/local/apache
/etc/init.d/nginx
/etc/init.d/${DB_Name}
/etc/init.d/httpd
/usr/local/zend
/etc/my.cnf
/bin/lnmp
EOF
sleep 3
Press_Start
Uninstall_LNMPA
;;
3|[lL][aA][nM][pP])
echo "You will uninstall LAMP"
Echo_Red "Please backup your configure files and mysql data!!!!!!"
Echo_Red "The following directory or files will be remove!"
cat << EOF
/usr/local/apache
${MySQL_Dir}
/etc/init.d/httpd
/etc/init.d/${DB_Name}
/usr/local/php
/usr/local/zend
/etc/my.cnf
/bin/lnmp
EOF
sleep 3
Press_Start
Uninstall_LAMP
;;
esac