forked from oneinstack/oneinstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
executable file
·423 lines (391 loc) · 15.1 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
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#!/bin/bash
# Author: yeho <lj2007331 AT gmail.com>
# BLOG: https://blog.linuxeye.cn
#
# Notes: OneinStack for CentOS/RadHat 6+ Debian 7+ and Ubuntu 12+
#
# Project home page:
# https://oneinstack.com
# https://github.com/lj2007331/oneinstack
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
clear
printf "
#######################################################################
# OneinStack for CentOS/RadHat 6+ Debian 7+ and Ubuntu 12+ #
# Uninstall OneinStack #
# For more information please visit https://oneinstack.com #
#######################################################################
"
# Check if user is root
[ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
oneinstack_dir=$(dirname "`readlink -f $0`")
pushd ${oneinstack_dir} > /dev/null
. ./options.conf
. ./include/color.sh
. ./include/get_char.sh
. ./include/check_dir.sh
Usage(){
printf "
Usage: $0 [ ${CMSG}all${CEND} | ${CMSG}web${CEND} | ${CMSG}mysql${CEND} | ${CMSG}postgresql${CEND} | ${CMSG}mongodb${CEND} | ${CMSG}php${CEND} | ${CMSG}hhvm${CEND} | ${CMSG}pureftpd${CEND} | ${CMSG}redis${CEND} | ${CMSG}memcached${CEND} ]
${CMSG}all${CEND} --->Uninstall All
${CMSG}web${CEND} --->Uninstall Nginx/Tengine/Apache/Tomcat
${CMSG}mysql${CEND} --->Uninstall MySQL/MariaDB/Percona/AliSQL
${CMSG}postgresql${CEND} --->Uninstall PostgreSQL
${CMSG}mongodb${CEND} --->Uninstall MongoDB
${CMSG}php${CEND} --->Uninstall PHP
${CMSG}hhvm${CEND} --->Uninstall HHVM
${CMSG}pureftpd${CEND} --->Uninstall PureFtpd
${CMSG}redis${CEND} --->Uninstall Redis
${CMSG}memcached${CEND} --->Uninstall Memcached
"
}
Uninstall_status() {
while :; do echo
read -p "Do you want to uninstall? [y/n]: " uninstall_yn
echo
if [[ ! ${uninstall_yn} =~ ^[y,n]$ ]]; then
echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
else
break
fi
done
}
Print_Warn() {
echo
echo "${CWARNING}You will uninstall OneinStack, Please backup your configure files and DB data! ${CEND}"
}
Print_web() {
[ -d "${nginx_install_dir}" ] && echo "${nginx_install_dir}"
[ -d "${tengine_install_dir}" ] && echo "${tengine_install_dir}"
[ -d "${openresty_install_dir}" ] && echo "${openresty_install_dir}"
[ -e "/etc/init.d/nginx" ] && echo '/etc/init.d/nginx'
[ -e "/lib/systemd/system/nginx.service" ] && echo '/lib/systemd/system/nginx.service'
[ -e "/etc/logrotate.d/nginx" ] && echo '/etc/logrotate.d/nginx'
[ -d "${apache_install_dir}" ] && echo "${apache_install_dir}"
[ -e "/etc/init.d/httpd" ] && echo "/etc/init.d/httpd"
[ -e "/etc/logrotate.d/apache" ] && echo "/etc/logrotate.d/apache"
[ -d "${tomcat_install_dir}" ] && echo "${tomcat_install_dir}"
[ -e "/etc/init.d/tomcat" ] && echo "/etc/init.d/tomcat"
[ -e "/etc/logrotate.d/tomcat" ] && echo "/etc/logrotate.d/tomcat"
[ -d "/usr/java" ] && echo '/usr/java'
[ -d "/usr/local/apr" ] && echo '/usr/local/apr'
}
Uninstall_Web() {
[ -d "${nginx_install_dir}" ] && { killall nginx > /dev/null 2>&1; rm -rf ${nginx_install_dir} /etc/init.d/nginx /etc/logrotate.d/nginx; sed -i "s@${nginx_install_dir}/sbin:@@" /etc/profile; echo "${CMSG}Nginx uninstall completed! ${CEND}"; }
[ -d "${tengine_install_dir}" ] && { killall nginx > /dev/null 2>&1; rm -rf ${tengine_install_dir} /etc/init.d/nginx /etc/logrotate.d/nginx; sed -i "s@${tengine_install_dir}/sbin:@@" /etc/profile; echo "${CMSG}Tengine uninstall completed! ${CEND}"; }
[ -d "${openresty_install_dir}" ] && { killall nginx > /dev/null 2>&1; rm -rf ${openresty_install_dir} /etc/init.d/nginx /etc/logrotate.d/nginx; sed -i "s@${openresty_install_dir}/nginx/sbin:@@" /etc/profile; echo "${CMSG}OpenResty uninstall completed! ${CEND}"; }
[ -e "/lib/systemd/system/nginx.service" ] && { systemctl disable nginx > /dev/null 2>&1; rm -f /lib/systemd/system/nginx.service; }
[ -d "${apache_install_dir}" ] && { service httpd stop > /dev/null 2>&1; rm -rf ${apache_install_dir} /etc/init.d/httpd /etc/logrotate.d/apache; sed -i "s@${apache_install_dir}/bin:@@" /etc/profile; echo "${CMSG}Apache uninstall completed! ${CEND}"; }
[ -d "${tomcat_install_dir}" ] && { killall java > /dev/null 2>&1; chmod +x /etc/logrotate.d/tomcat; rm -rf ${tomcat_install_dir} /etc/init.d/tomcat /etc/logrotate.d/tomcat /usr/local/apr; echo "${CMSG}Tomcat uninstall completed! ${CEND}"; }
[ -d "/usr/java" ] && { rm -rf /usr/java; sed -i '/export JAVA_HOME=/d' /etc/profile; sed -i '/export CLASSPATH=/d' /etc/profile; sed -i 's@\$JAVA_HOME/bin:@@' /etc/profile; }
[ -e "${wwwroot_dir}" ] && /bin/mv ${wwwroot_dir}{,$(date +%Y%m%d%H)}
sed -i 's@^website_name=.*@website_name=@' ./options.conf
sed -i 's@^local_bankup_yn=.*@local_bankup_yn=y@' ./options.conf
sed -i 's@^remote_bankup_yn=.*@remote_bankup_yn=n@' ./options.conf
}
Print_MySQL() {
[ -e "${db_install_dir}" ] && echo "${db_install_dir}"
[ -e "/etc/init.d/mysqld" ] && echo "/etc/init.d/mysqld"
[ -e "/etc/my.cnf" ] && echo "/etc/my.cnf"
}
Print_PostgreSQL() {
[ -e "${pgsql_install_dir}" ] && echo "${pgsql_install_dir}"
[ -e "/etc/init.d/postgresql" ] && echo "/etc/init.d/postgresql"
}
Print_MongoDB() {
[ -e "${mongo_install_dir}" ] && echo "${mongo_install_dir}"
[ -e "/etc/init.d/mongod" ] && echo "/etc/init.d/mongod"
[ -e "/etc/mongod.conf" ] && echo "/etc/mongod.conf"
}
Uninstall_MySQL() {
# uninstall mysql,mariadb,percona,alisql
if [ -d "${db_install_dir}/support-files" ]; then
service mysqld stop > /dev/null 2>&1
rm -rf ${db_install_dir} /etc/init.d/mysqld /etc/my.cnf /etc/ld.so.conf.d/{mysql,mariadb,percona,alisql}*.conf
id -u mysql >/dev/null 2>&1 ; [ $? -eq 0 ] && userdel mysql
[ -e "${db_data_dir}" ] && /bin/mv ${db_data_dir}{,$(date +%Y%m%d%H)}
sed -i 's@^dbrootpwd=.*@dbrootpwd=@' ./options.conf
sed -i "s@${db_install_dir}/bin:@@" /etc/profile
echo "${CMSG}MySQL uninstall completed! ${CEND}"
fi
}
Uninstall_PostgreSQL() {
# uninstall postgresql
if [ -e "${pgsql_install_dir}/bin/psql" ]; then
service postgresql stop > /dev/null 2>&1
rm -rf ${pgsql_install_dir} /etc/init.d/postgresql
[ -e "${php_install_dir}/etc/php.d/07-pgsql.ini" ] && rm -rf ${php_install_dir}/etc/php.d/07-pgsql.ini
id -u postgres >/dev/null 2>&1 ; [ $? -eq 0 ] && userdel postgres
[ -e "${pgsql_data_dir}" ] && /bin/mv ${pgsql_data_dir}{,$(date +%Y%m%d%H)}
sed -i 's@^dbpostgrespwd=.*@dbpostgrespwd=@' ./options.conf
sed -i "s@${pgsql_install_dir}/bin:@@" /etc/profile
echo "${CMSG}PostgreSQL uninstall completed! ${CEND}"
fi
}
Uninstall_MongoDB() {
# uninstall mongodb
if [ -e "${mongo_install_dir}/bin/mongo" ]; then
service mongod stop > /dev/null 2>&1
rm -rf ${mongo_install_dir} /etc/mongod.conf /etc/init.d/mongod /tmp/mongo*.sock
[ -e "${php_install_dir}/etc/php.d/07-mongo.ini" ] && rm -rf ${php_install_dir}/etc/php.d/07-mongo.ini
[ -e "${php_install_dir}/etc/php.d/07-mongodb.ini" ] && rm -rf ${php_install_dir}/etc/php.d/07-mongodb.ini
id -u mongod > /dev/null 2>&1 ; [ $? -eq 0 ] && userdel mongod
[ -e "${mongo_data_dir}" ] && /bin/mv ${mongo_data_dir}{,$(date +%Y%m%d%H)}
sed -i 's@^dbmongopwd=.*@dbmongopwd=@' ./options.conf
sed -i "s@${mongo_install_dir}/bin:@@" /etc/profile
echo "${CMSG}MongoDB uninstall completed! ${CEND}"
fi
}
Print_PHP() {
[ -e "${php_install_dir}" ] && echo "${php_install_dir}"
[ -e "/etc/init.d/php-fpm" ] && echo "/etc/init.d/php-fpm"
[ -e "${imagick_install_dir}" ] && echo "${imagick_install_dir}"
[ -e "${gmagick_install_dir}" ] && echo "${gmagick_install_dir}"
[ -e "${curl_install_dir}" ] && echo "${curl_install_dir}"
}
Uninstall_PHP() {
[ -e "${php_install_dir}/bin/phpize" -a -e "${php_install_dir}/etc/php-fpm.conf" ] && { service php-fpm stop > /dev/null 2>&1; rm -rf ${php_install_dir} /etc/init.d/php-fpm; echo "${CMSG}PHP uninstall completed! ${CEND}"; }
[ -e "${php_install_dir}/bin/phpize" -a ! -e "${php_install_dir}/etc/php-fpm.conf" ] && { rm -rf ${php_install_dir}; echo "${CMSG}PHP uninstall completed! ${CEND}"; }
[ -e "${imagick_install_dir}" ] && rm -rf ${imagick_install_dir}
[ -e "${gmagick_install_dir}" ] && rm -rf ${gmagick_install_dir}
[ -e "${curl_install_dir}" ] && rm -rf "${curl_install_dir}"
sed -i "s@${php_install_dir}/bin:@@" /etc/profile
}
Print_HHVM() {
[ -e "/usr/bin/hhvm" ] && echo "/usr/bin/hhvm"
[ -e "/etc/hhvm" ] && echo "/etc/hhvm"
[ -e "/var/log/hhvm" ] && echo "/var/log/hhvm"
[ -e "/lib/systemd/system/hhvm.service" ] && echo "/lib/systemd/system/hhvm.service"
[ -e "/etc/supervisord.conf" ] && echo "/etc/supervisord.conf"
[ -e "/etc/init.d/supervisord" ] && echo "/etc/init.d/supervisord"
}
Uninstall_HHVM() {
[ -e "/lib/systemd/system/hhvm.service" ] && { systemctl disable hhvm > /dev/null 2>&1; rm -rf /lib/systemd/system/hhvm.service; }
[ -e "/etc/init.d/supervisord" ] && { service supervisord stop > /dev/null 2>&1; rm -rf /etc/supervisord.conf /etc/init.d/supervisord; }
[ -e "/usr/bin/hhvm" ] && { rpm -e hhvm; rm -rf /etc/hhvm /var/log/hhvm /usr/bin/hhvm; echo "${CMSG}HHVM uninstall completed! ${CEND}"; }
}
Print_PureFtpd() {
[ -e "${pureftpd_install_dir}" ] && echo "${pureftpd_install_dir}"
[ -e "/etc/init.d/pureftpd" ] && echo "/etc/init.d/pureftpd"
}
Uninstall_PureFtpd() {
[ -e "${pureftpd_install_dir}" ] && { service pureftpd stop > /dev/null 2>&1; rm -rf ${pureftpd_install_dir} /etc/init.d/pureftpd; echo "${CMSG}Pureftpd uninstall completed! ${CEND}"; }
}
Print_Redis() {
[ -e "$redis_install_dir" ] && echo "$redis_install_dir"
[ -e "/etc/init.d/redis-server" ] && echo "/etc/init.d/redis-server"
[ -e "/lib/systemd/system/redis-server.service" ] && echo '/lib/systemd/system/redis-server.service'
}
Uninstall_Redis() {
[ -e "$redis_install_dir" ] && { service redis-server stop > /dev/null 2>&1; rm -rf $redis_install_dir /etc/init.d/redis-server /usr/local/bin/redis-*; echo "${CMSG}Redis uninstall completed! ${CEND}"; }
[ -e "/lib/systemd/system/redis-server.service" ] && { systemctl disable redis-server > /dev/null 2>&1; rm -f /lib/systemd/system/redis-server.service; }
[ -e "${php_install_dir}/etc/php.d/05-redis.ini" ] && { rm -rf ${php_install_dir}/etc/php.d/05-redis.ini; echo "${CMSG}Pecl_redis uninstall completed! ${CEND}"; }
}
Print_Memcached() {
[ -e "${memcached_install_dir}" ] && echo "${memcached_install_dir}"
[ -e "/etc/init.d/memcached" ] && echo "/etc/init.d/memcached"
[ -e "/usr/bin/memcached" ] && echo "/usr/bin/memcached"
}
Uninstall_Memcached() {
[ -e "${memcached_install_dir}" ] && { service memcached stop > /dev/null 2>&1; rm -rf ${memcached_install_dir} /etc/init.d/memcached /usr/bin/memcached; echo "${CMSG}Memcached uninstall completed! ${CEND}"; }
[ -e "${php_install_dir}/etc/php.d/05-memcache.ini" ] && rm -rf ${php_install_dir}/etc/php.d/05-memcache.ini
[ -e "${php_install_dir}/etc/php.d/05-memcached.ini" ] && rm -rf ${php_install_dir}/etc/php.d/05-memcached.ini
}
Print_openssl() {
[ -d "${openssl_install_dir}" ] && echo "${openssl_install_dir}"
}
Uninstall_openssl() {
[ -d "${openssl_install_dir}" ] && rm -rf ${openssl_install_dir}
}
Menu(){
while :; do
printf "
What Are You Doing?
\t${CMSG}0${CEND}. Uninstall All
\t${CMSG}1${CEND}. Uninstall Nginx/Tengine/Apache/Tomcat
\t${CMSG}2${CEND}. Uninstall MySQL/MariaDB/Percona/AliSQL
\t${CMSG}3${CEND}. Uninstall PostgreSQL
\t${CMSG}4${CEND}. Uninstall MongoDB
\t${CMSG}5${CEND}. Uninstall PHP
\t${CMSG}6${CEND}. Uninstall HHVM
\t${CMSG}7${CEND}. Uninstall PureFtpd
\t${CMSG}8${CEND}. Uninstall Redis
\t${CMSG}9${CEND}. Uninstall Memcached
\t${CMSG}q${CEND}. Exit
"
echo
read -p "Please input the correct option: " Number
if [[ ! $Number =~ ^[0-9,q]$ ]]; then
echo "${CWARNING}input error! Please only input 0~9 and q${CEND}"
else
case "$Number" in
0)
Print_Warn
Print_web
Print_MySQL
Print_PostgreSQL
Print_MongoDB
Print_PHP
Print_HHVM
Print_PureFtpd
Print_Redis
Print_Memcached
Print_openssl
Uninstall_status
if [ "${uninstall_yn}" == 'y' ]; then
Uninstall_Web
Uninstall_MySQL
Uninstall_PostgreSQL
Uninstall_MongoDB
Uninstall_PHP
Uninstall_HHVM
Uninstall_PureFtpd
Uninstall_Redis
Uninstall_Memcached
Uninstall_openssl
else
exit
fi
;;
1)
Print_Warn
Print_web
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_Web || exit
;;
2)
Print_Warn
Print_MySQL
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_MySQL || exit
;;
3)
Print_Warn
Print_PostgreSQL
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_PostgreSQL || exit
;;
4)
Print_Warn
Print_MongoDB
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_MongoDB || exit
;;
5)
Print_PHP
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_PHP || exit
;;
6)
Print_HHVM
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_HHVM || exit
;;
7)
Print_PureFtpd
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_PureFtpd || exit
;;
8)
Print_Redis
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_Redis || exit
;;
9)
Print_Memcached
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_Memcached || exit
;;
q)
exit
;;
esac
fi
done
}
if [ $# == 0 ]; then
Menu
elif [ $# == 1 ]; then
case $1 in
all)
Print_Warn
Print_web
Print_MySQL
Print_PostgreSQL
Print_MongoDB
Print_PHP
Print_HHVM
Print_PureFtpd
Print_Redis
Print_Memcached
Print_openssl
Uninstall_status
if [ "${uninstall_yn}" == 'y' ]; then
Uninstall_Web
Uninstall_MySQL
Uninstall_PHP
Uninstall_HHVM
Uninstall_PureFtpd
Uninstall_Redis
Uninstall_Memcached
Uninstall_openssl
else
exit
fi
;;
web)
Print_Warn
Print_web
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_Web || exit
;;
mysql)
Print_Warn
Print_MySQL
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_MySQL || exit
;;
postgresql)
Print_Warn
Print_PostgreSQL
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_PostgreSQL || exit
;;
mongodb)
Print_Warn
Print_MongoDB
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_MongoDB || exit
;;
php)
Print_PHP
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_PHP || exit
;;
hhvm)
Print_HHVM
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_HHVM || exit
;;
pureftpd)
Print_PureFtpd
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_PureFtpd || exit
;;
redis)
Print_Redis
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_Redis || exit
;;
memcached)
Print_Memcached
Uninstall_status
[ "${uninstall_yn}" == 'y' ] && Uninstall_Memcached || exit
;;
*)
Usage
;;
esac
else
Usage
fi