uninstall.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 6+ Debian 7+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
  11. clear
  12. printf "
  13. #######################################################################
  14. # OneinStack for CentOS/RadHat 6+ Debian 7+ and Ubuntu 12+ #
  15. # Uninstall OneinStack #
  16. # For more information please visit https://oneinstack.com #
  17. #######################################################################
  18. "
  19. # Check if user is root
  20. [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  21. oneinstack_dir=$(dirname "`readlink -f $0`")
  22. pushd ${oneinstack_dir} > /dev/null
  23. . ./options.conf
  24. . ./include/color.sh
  25. . ./include/get_char.sh
  26. . ./include/check_dir.sh
  27. Usage(){
  28. printf "
  29. 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} ]
  30. ${CMSG}all${CEND} --->Uninstall All
  31. ${CMSG}web${CEND} --->Uninstall Nginx/Tengine/Apache/Tomcat
  32. ${CMSG}mysql${CEND} --->Uninstall MySQL/MariaDB/Percona/AliSQL
  33. ${CMSG}postgresql${CEND} --->Uninstall PostgreSQL
  34. ${CMSG}mongodb${CEND} --->Uninstall MongoDB
  35. ${CMSG}php${CEND} --->Uninstall PHP
  36. ${CMSG}hhvm${CEND} --->Uninstall HHVM
  37. ${CMSG}pureftpd${CEND} --->Uninstall PureFtpd
  38. ${CMSG}redis${CEND} --->Uninstall Redis
  39. ${CMSG}memcached${CEND} --->Uninstall Memcached
  40. "
  41. }
  42. Uninstall_status() {
  43. while :; do echo
  44. read -p "Do you want to uninstall? [y/n]: " uninstall_yn
  45. echo
  46. if [[ ! ${uninstall_yn} =~ ^[y,n]$ ]]; then
  47. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  48. else
  49. break
  50. fi
  51. done
  52. }
  53. Print_Warn() {
  54. echo
  55. echo "${CWARNING}You will uninstall OneinStack, Please backup your configure files and DB data! ${CEND}"
  56. }
  57. Print_web() {
  58. [ -d "${nginx_install_dir}" ] && echo "${nginx_install_dir}"
  59. [ -d "${tengine_install_dir}" ] && echo "${tengine_install_dir}"
  60. [ -d "${openresty_install_dir}" ] && echo "${openresty_install_dir}"
  61. [ -e "/etc/init.d/nginx" ] && echo '/etc/init.d/nginx'
  62. [ -e "/lib/systemd/system/nginx.service" ] && echo '/lib/systemd/system/nginx.service'
  63. [ -e "/etc/logrotate.d/nginx" ] && echo '/etc/logrotate.d/nginx'
  64. [ -d "${apache_install_dir}" ] && echo "${apache_install_dir}"
  65. [ -e "/etc/init.d/httpd" ] && echo "/etc/init.d/httpd"
  66. [ -e "/etc/logrotate.d/apache" ] && echo "/etc/logrotate.d/apache"
  67. [ -d "${tomcat_install_dir}" ] && echo "${tomcat_install_dir}"
  68. [ -e "/etc/init.d/tomcat" ] && echo "/etc/init.d/tomcat"
  69. [ -e "/etc/logrotate.d/tomcat" ] && echo "/etc/logrotate.d/tomcat"
  70. [ -d "/usr/java" ] && echo '/usr/java'
  71. [ -d "/usr/local/apr" ] && echo '/usr/local/apr'
  72. }
  73. Uninstall_Web() {
  74. [ -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}"; }
  75. [ -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}"; }
  76. [ -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}"; }
  77. [ -e "/lib/systemd/system/nginx.service" ] && { systemctl disable nginx > /dev/null 2>&1; rm -f /lib/systemd/system/nginx.service; }
  78. [ -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}"; }
  79. [ -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}"; }
  80. [ -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; }
  81. [ -e "${wwwroot_dir}" ] && /bin/mv ${wwwroot_dir}{,$(date +%Y%m%d%H)}
  82. sed -i 's@^website_name=.*@website_name=@' ./options.conf
  83. sed -i 's@^local_bankup_yn=.*@local_bankup_yn=y@' ./options.conf
  84. sed -i 's@^remote_bankup_yn=.*@remote_bankup_yn=n@' ./options.conf
  85. }
  86. Print_MySQL() {
  87. [ -e "${db_install_dir}" ] && echo "${db_install_dir}"
  88. [ -e "/etc/init.d/mysqld" ] && echo "/etc/init.d/mysqld"
  89. [ -e "/etc/my.cnf" ] && echo "/etc/my.cnf"
  90. }
  91. Print_PostgreSQL() {
  92. [ -e "${pgsql_install_dir}" ] && echo "${pgsql_install_dir}"
  93. [ -e "/etc/init.d/postgresql" ] && echo "/etc/init.d/postgresql"
  94. }
  95. Print_MongoDB() {
  96. [ -e "${mongo_install_dir}" ] && echo "${mongo_install_dir}"
  97. [ -e "/etc/init.d/mongod" ] && echo "/etc/init.d/mongod"
  98. [ -e "/etc/mongod.conf" ] && echo "/etc/mongod.conf"
  99. }
  100. Uninstall_MySQL() {
  101. # uninstall mysql,mariadb,percona,alisql
  102. if [ -d "${db_install_dir}/support-files" ]; then
  103. service mysqld stop > /dev/null 2>&1
  104. rm -rf ${db_install_dir} /etc/init.d/mysqld /etc/my.cnf /etc/ld.so.conf.d/{mysql,mariadb,percona,alisql}*.conf
  105. id -u mysql >/dev/null 2>&1 ; [ $? -eq 0 ] && userdel mysql
  106. [ -e "${db_data_dir}" ] && /bin/mv ${db_data_dir}{,$(date +%Y%m%d%H)}
  107. sed -i 's@^dbrootpwd=.*@dbrootpwd=@' ./options.conf
  108. sed -i "s@${db_install_dir}/bin:@@" /etc/profile
  109. echo "${CMSG}MySQL uninstall completed! ${CEND}"
  110. fi
  111. }
  112. Uninstall_PostgreSQL() {
  113. # uninstall postgresql
  114. if [ -e "${pgsql_install_dir}/bin/psql" ]; then
  115. service postgresql stop > /dev/null 2>&1
  116. rm -rf ${pgsql_install_dir} /etc/init.d/postgresql
  117. [ -e "${php_install_dir}/etc/php.d/07-pgsql.ini" ] && rm -rf ${php_install_dir}/etc/php.d/07-pgsql.ini
  118. id -u postgres >/dev/null 2>&1 ; [ $? -eq 0 ] && userdel postgres
  119. [ -e "${pgsql_data_dir}" ] && /bin/mv ${pgsql_data_dir}{,$(date +%Y%m%d%H)}
  120. sed -i 's@^dbpostgrespwd=.*@dbpostgrespwd=@' ./options.conf
  121. sed -i "s@${pgsql_install_dir}/bin:@@" /etc/profile
  122. echo "${CMSG}PostgreSQL uninstall completed! ${CEND}"
  123. fi
  124. }
  125. Uninstall_MongoDB() {
  126. # uninstall mongodb
  127. if [ -e "${mongo_install_dir}/bin/mongo" ]; then
  128. service mongod stop > /dev/null 2>&1
  129. rm -rf ${mongo_install_dir} /etc/mongod.conf /etc/init.d/mongod /tmp/mongo*.sock
  130. [ -e "${php_install_dir}/etc/php.d/07-mongo.ini" ] && rm -rf ${php_install_dir}/etc/php.d/07-mongo.ini
  131. [ -e "${php_install_dir}/etc/php.d/07-mongodb.ini" ] && rm -rf ${php_install_dir}/etc/php.d/07-mongodb.ini
  132. id -u mongod > /dev/null 2>&1 ; [ $? -eq 0 ] && userdel mongod
  133. [ -e "${mongo_data_dir}" ] && /bin/mv ${mongo_data_dir}{,$(date +%Y%m%d%H)}
  134. sed -i 's@^dbmongopwd=.*@dbmongopwd=@' ./options.conf
  135. sed -i "s@${mongo_install_dir}/bin:@@" /etc/profile
  136. echo "${CMSG}MongoDB uninstall completed! ${CEND}"
  137. fi
  138. }
  139. Print_PHP() {
  140. [ -e "${php_install_dir}" ] && echo "${php_install_dir}"
  141. [ -e "/etc/init.d/php-fpm" ] && echo "/etc/init.d/php-fpm"
  142. [ -e "${imagick_install_dir}" ] && echo "${imagick_install_dir}"
  143. [ -e "${gmagick_install_dir}" ] && echo "${gmagick_install_dir}"
  144. [ -e "${curl_install_dir}" ] && echo "${curl_install_dir}"
  145. }
  146. Uninstall_PHP() {
  147. [ -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}"; }
  148. [ -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}"; }
  149. [ -e "${imagick_install_dir}" ] && rm -rf ${imagick_install_dir}
  150. [ -e "${gmagick_install_dir}" ] && rm -rf ${gmagick_install_dir}
  151. [ -e "${curl_install_dir}" ] && rm -rf "${curl_install_dir}"
  152. sed -i "s@${php_install_dir}/bin:@@" /etc/profile
  153. }
  154. Print_HHVM() {
  155. [ -e "/usr/bin/hhvm" ] && echo "/usr/bin/hhvm"
  156. [ -e "/etc/hhvm" ] && echo "/etc/hhvm"
  157. [ -e "/var/log/hhvm" ] && echo "/var/log/hhvm"
  158. [ -e "/etc/supervisord.conf" ] && echo "/etc/supervisord.conf"
  159. [ -e "/etc/init.d/supervisord" ] && echo "/etc/init.d/supervisord"
  160. }
  161. Uninstall_HHVM() {
  162. [ -e "/etc/init.d/supervisord" ] && { service supervisord stop > /dev/null 2>&1; rm -rf /etc/supervisord.conf /etc/init.d/supervisord; }
  163. [ -e "/usr/bin/hhvm" ] && { rpm -e hhvm; rm -rf /etc/hhvm /var/log/hhvm /usr/bin/hhvm; echo "${CMSG}HHVM uninstall completed! ${CEND}"; }
  164. }
  165. Print_PureFtpd() {
  166. [ -e "${pureftpd_install_dir}" ] && echo "${pureftpd_install_dir}"
  167. [ -e "/etc/init.d/pureftpd" ] && echo "/etc/init.d/pureftpd"
  168. }
  169. Uninstall_PureFtpd() {
  170. [ -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}"; }
  171. }
  172. Print_Redis() {
  173. [ -e "$redis_install_dir" ] && echo "$redis_install_dir"
  174. [ -e "/etc/init.d/redis-server" ] && echo "/etc/init.d/redis-server"
  175. [ -e "/lib/systemd/system/redis-server.service" ] && echo '/lib/systemd/system/redis-server.service'
  176. }
  177. Uninstall_Redis() {
  178. [ -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}"; }
  179. [ -e "/lib/systemd/system/redis-server.service" ] && { systemctl disable redis-server > /dev/null 2>&1; rm -f /lib/systemd/system/redis-server.service; }
  180. [ -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}"; }
  181. }
  182. Print_Memcached() {
  183. [ -e "${memcached_install_dir}" ] && echo "${memcached_install_dir}"
  184. [ -e "/etc/init.d/memcached" ] && echo "/etc/init.d/memcached"
  185. [ -e "/usr/bin/memcached" ] && echo "/usr/bin/memcached"
  186. }
  187. Uninstall_Memcached() {
  188. [ -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}"; }
  189. [ -e "${php_install_dir}/etc/php.d/05-memcache.ini" ] && rm -rf ${php_install_dir}/etc/php.d/05-memcache.ini
  190. [ -e "${php_install_dir}/etc/php.d/05-memcached.ini" ] && rm -rf ${php_install_dir}/etc/php.d/05-memcached.ini
  191. }
  192. Print_openssl() {
  193. [ -d "${openssl_install_dir}" ] && echo "${openssl_install_dir}"
  194. }
  195. Uninstall_openssl() {
  196. [ -d "${openssl_install_dir}" ] && rm -rf ${openssl_install_dir}
  197. }
  198. Menu(){
  199. while :; do
  200. printf "
  201. What Are You Doing?
  202. \t${CMSG}0${CEND}. Uninstall All
  203. \t${CMSG}1${CEND}. Uninstall Nginx/Tengine/Apache/Tomcat
  204. \t${CMSG}2${CEND}. Uninstall MySQL/MariaDB/Percona/AliSQL
  205. \t${CMSG}3${CEND}. Uninstall PostgreSQL
  206. \t${CMSG}4${CEND}. Uninstall MongoDB
  207. \t${CMSG}5${CEND}. Uninstall PHP
  208. \t${CMSG}6${CEND}. Uninstall HHVM
  209. \t${CMSG}7${CEND}. Uninstall PureFtpd
  210. \t${CMSG}8${CEND}. Uninstall Redis
  211. \t${CMSG}9${CEND}. Uninstall Memcached
  212. \t${CMSG}q${CEND}. Exit
  213. "
  214. echo
  215. read -p "Please input the correct option: " Number
  216. if [[ ! $Number =~ ^[0-9,q]$ ]]; then
  217. echo "${CWARNING}input error! Please only input 0~9 and q${CEND}"
  218. else
  219. case "$Number" in
  220. 0)
  221. Print_Warn
  222. Print_web
  223. Print_MySQL
  224. Print_PostgreSQL
  225. Print_MongoDB
  226. Print_PHP
  227. Print_HHVM
  228. Print_PureFtpd
  229. Print_Redis
  230. Print_Memcached
  231. Print_openssl
  232. Uninstall_status
  233. if [ "${uninstall_yn}" == 'y' ]; then
  234. Uninstall_Web
  235. Uninstall_MySQL
  236. Uninstall_PostgreSQL
  237. Uninstall_MongoDB
  238. Uninstall_PHP
  239. Uninstall_HHVM
  240. Uninstall_PureFtpd
  241. Uninstall_Redis
  242. Uninstall_Memcached
  243. Uninstall_openssl
  244. else
  245. exit
  246. fi
  247. ;;
  248. 1)
  249. Print_Warn
  250. Print_web
  251. Uninstall_status
  252. [ "${uninstall_yn}" == 'y' ] && Uninstall_Web || exit
  253. ;;
  254. 2)
  255. Print_Warn
  256. Print_MySQL
  257. Uninstall_status
  258. [ "${uninstall_yn}" == 'y' ] && Uninstall_MySQL || exit
  259. ;;
  260. 3)
  261. Print_Warn
  262. Print_PostgreSQL
  263. Uninstall_status
  264. [ "${uninstall_yn}" == 'y' ] && Uninstall_PostgreSQL || exit
  265. ;;
  266. 4)
  267. Print_Warn
  268. Print_MongoDB
  269. Uninstall_status
  270. [ "${uninstall_yn}" == 'y' ] && Uninstall_MongoDB || exit
  271. ;;
  272. 5)
  273. Print_PHP
  274. Uninstall_status
  275. [ "${uninstall_yn}" == 'y' ] && Uninstall_PHP || exit
  276. ;;
  277. 6)
  278. Print_HHVM
  279. Uninstall_status
  280. [ "${uninstall_yn}" == 'y' ] && Uninstall_HHVM || exit
  281. ;;
  282. 7)
  283. Print_PureFtpd
  284. Uninstall_status
  285. [ "${uninstall_yn}" == 'y' ] && Uninstall_PureFtpd || exit
  286. ;;
  287. 8)
  288. Print_Redis
  289. Uninstall_status
  290. [ "${uninstall_yn}" == 'y' ] && Uninstall_Redis || exit
  291. ;;
  292. 9)
  293. Print_Memcached
  294. Uninstall_status
  295. [ "${uninstall_yn}" == 'y' ] && Uninstall_Memcached || exit
  296. ;;
  297. q)
  298. exit
  299. ;;
  300. esac
  301. fi
  302. done
  303. }
  304. if [ $# == 0 ]; then
  305. Menu
  306. elif [ $# == 1 ]; then
  307. case $1 in
  308. all)
  309. Print_Warn
  310. Print_web
  311. Print_MySQL
  312. Print_PostgreSQL
  313. Print_MongoDB
  314. Print_PHP
  315. Print_HHVM
  316. Print_PureFtpd
  317. Print_Redis
  318. Print_Memcached
  319. Print_openssl
  320. Uninstall_status
  321. if [ "${uninstall_yn}" == 'y' ]; then
  322. Uninstall_Web
  323. Uninstall_MySQL
  324. Uninstall_PHP
  325. Uninstall_HHVM
  326. Uninstall_PureFtpd
  327. Uninstall_Redis
  328. Uninstall_Memcached
  329. Uninstall_openssl
  330. else
  331. exit
  332. fi
  333. ;;
  334. web)
  335. Print_Warn
  336. Print_web
  337. Uninstall_status
  338. [ "${uninstall_yn}" == 'y' ] && Uninstall_Web || exit
  339. ;;
  340. mysql)
  341. Print_Warn
  342. Print_MySQL
  343. Uninstall_status
  344. [ "${uninstall_yn}" == 'y' ] && Uninstall_MySQL || exit
  345. ;;
  346. postgresql)
  347. Print_Warn
  348. Print_PostgreSQL
  349. Uninstall_status
  350. [ "${uninstall_yn}" == 'y' ] && Uninstall_PostgreSQL || exit
  351. ;;
  352. mongodb)
  353. Print_Warn
  354. Print_MongoDB
  355. Uninstall_status
  356. [ "${uninstall_yn}" == 'y' ] && Uninstall_MongoDB || exit
  357. ;;
  358. php)
  359. Print_PHP
  360. Uninstall_status
  361. [ "${uninstall_yn}" == 'y' ] && Uninstall_PHP || exit
  362. ;;
  363. hhvm)
  364. Print_HHVM
  365. Uninstall_status
  366. [ "${uninstall_yn}" == 'y' ] && Uninstall_HHVM || exit
  367. ;;
  368. pureftpd)
  369. Print_PureFtpd
  370. Uninstall_status
  371. [ "${uninstall_yn}" == 'y' ] && Uninstall_PureFtpd || exit
  372. ;;
  373. redis)
  374. Print_Redis
  375. Uninstall_status
  376. [ "${uninstall_yn}" == 'y' ] && Uninstall_Redis || exit
  377. ;;
  378. memcached)
  379. Print_Memcached
  380. Uninstall_status
  381. [ "${uninstall_yn}" == 'y' ] && Uninstall_Memcached || exit
  382. ;;
  383. *)
  384. Usage
  385. ;;
  386. esac
  387. else
  388. Usage
  389. fi