1
0

uninstall.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  11. clear
  12. printf "
  13. #######################################################################
  14. # OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+ #
  15. # Uninstall OneinStack #
  16. # For more information please visit https://oneinstack.com #
  17. #######################################################################
  18. "
  19. . ./options.conf
  20. . ./include/color.sh
  21. . ./include/get_char.sh
  22. . ./include/check_dir.sh
  23. # Check if user is root
  24. [ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
  25. Usage(){
  26. printf "
  27. Usage: $0 [ ${CMSG}all${CEND} | ${CMSG}web${CEND} | ${CMSG}db${CEND} | ${CMSG}php${CEND} | ${CMSG}hhvm${CEND} | ${CMSG}pureftpd${CEND} | ${CMSG}redis${CEND} | ${CMSG}memcached${CEND} ]
  28. ${CMSG}all${CEND} --->Uninstall All
  29. ${CMSG}web${CEND} --->Uninstall Nginx/Tengine/Apache/Tomcat
  30. ${CMSG}db${CEND} --->Uninstall MySQL/MariaDB/Percona/AliSQL
  31. ${CMSG}php${CEND} --->Uninstall PHP
  32. ${CMSG}hhvm${CEND} --->Uninstall HHVM
  33. ${CMSG}pureftpd${CEND} --->Uninstall PureFtpd
  34. ${CMSG}redis${CEND} --->Uninstall Redis
  35. ${CMSG}memcached${CEND} --->Uninstall Memcached
  36. "
  37. }
  38. Uninstall_status() {
  39. while :; do echo
  40. read -p "Do you want to uninstall? [y/n]: " uninstall_yn
  41. echo
  42. if [[ ! ${uninstall_yn} =~ ^[y,n]$ ]]; then
  43. echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
  44. else
  45. break
  46. fi
  47. done
  48. }
  49. Print_Warn() {
  50. echo
  51. echo "${CWARNING}You will uninstall OneinStack, Please backup your configure files and DB data! ${CEND}"
  52. }
  53. Print_web() {
  54. [ -d "${nginx_install_dir}" ] && echo "${nginx_install_dir}"
  55. [ -d "${tengine_install_dir}" ] && echo "${tengine_install_dir}"
  56. [ -d "${openresty_install_dir}" ] && echo "${openresty_install_dir}"
  57. [ -e "/etc/init.d/nginx" ] && echo '/etc/init.d/nginx'
  58. [ -e "/etc/logrotate.d/nginx" ] && echo '/etc/logrotate.d/nginx'
  59. [ -d "${apache_install_dir}" ] && echo "${apache_install_dir}"
  60. [ -e "/etc/init.d/httpd" ] && echo "/etc/init.d/httpd"
  61. [ -e "/etc/logrotate.d/apache" ] && echo "/etc/logrotate.d/apache"
  62. [ -d "${tomcat_install_dir}" ] && echo "${tomcat_install_dir}"
  63. [ -e "/etc/init.d/tomcat" ] && echo "/etc/init.d/tomcat"
  64. [ -e "/etc/logrotate.d/tomcat" ] && echo "/etc/logrotate.d/tomcat"
  65. [ -d "/usr/java" ] && echo '/usr/java'
  66. [ -d "/usr/local/apr" ] && echo '/usr/local/apr'
  67. [ -d "${openssl_install_dir}" ] && echo "${openssl_install_dir}"
  68. }
  69. Uninstall_Web() {
  70. [ -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; }
  71. [ -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; }
  72. [ -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; }
  73. [ -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; }
  74. [ -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; }
  75. [ -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; }
  76. [ -d "${openssl_install_dir}" ] && rm -rf ${openssl_install_dir}
  77. [ -e "${wwwroot_dir}" ] && /bin/mv ${wwwroot_dir}{,$(date +%Y%m%d%H)}
  78. sed -i 's@^website_name=.*@website_name=@' ./options.conf
  79. sed -i 's@^local_bankup_yn=.*@local_bankup_yn=y@' ./options.conf
  80. sed -i 's@^remote_bankup_yn=.*@remote_bankup_yn=n@' ./options.conf
  81. echo "${CMSG}Web uninstall completed${CEND}"
  82. }
  83. Print_DB() {
  84. [ -e "${db_install_dir}" ] && echo "${db_install_dir}"
  85. [ -e "/etc/init.d/mysqld" ] && echo "/etc/init.d/mysqld"
  86. [ -e "/etc/my.cnf" ] && echo "/etc/my.cnf"
  87. }
  88. Uninstall_DB() {
  89. [ -e "${db_install_dir}" ] && { 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; }
  90. id -u mysql >/dev/null 2>&1 ; [ $? -eq 0 ] && userdel mysql
  91. [ -e "${db_data_dir}" ] && /bin/mv ${db_data_dir}{,$(date +%Y%m%d%H)}
  92. sed -i 's@^dbrootpwd=.*@dbrootpwd=@' ./options.conf
  93. sed -i "s@${db_install_dir}/bin:@@" /etc/profile
  94. echo "${CMSG}DB uninstall completed${CEND}"
  95. }
  96. Print_PHP() {
  97. [ -e "${php_install_dir}" ] && echo "${php_install_dir}"
  98. [ -e "/etc/init.d/php-fpm" ] && echo "/etc/init.d/php-fpm"
  99. [ -e "/usr/local/imagemagick" ] && echo "/usr/local/imagemagick"
  100. [ -e "/usr/local/graphicsmagick" ] && echo '/usr/local/graphicsmagick'
  101. [ -e "/usr/local/openssl100s" ] && echo '/usr/local/openssl100s'
  102. }
  103. Uninstall_PHP() {
  104. [ -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; }
  105. [ -e "${php_install_dir}/bin/phpize" -a ! -e "${php_install_dir}/etc/php-fpm.conf" ] && rm -rf ${php_install_dir}
  106. [ -e "/usr/local/imagemagick" ] && rm -rf /usr/local/imagemagick
  107. [ -e "/usr/local/graphicsmagick" ] && rm -rf /usr/local/graphicsmagick
  108. [ -e "/usr/local/openssl100s" ] && rm -rf /usr/local/openssl100s
  109. sed -i "s@${php_install_dir}/bin:@@" /etc/profile
  110. echo "${CMSG}PHP uninstall completed${CEND}"
  111. }
  112. Print_HHVM() {
  113. [ -e "/usr/bin/hhvm" ] && echo "/usr/bin/hhvm"
  114. [ -e "/etc/hhvm" ] && echo "/etc/hhvm"
  115. [ -e "/var/log/hhvm" ] && echo "/var/log/hhvm"
  116. [ -e "/etc/supervisord.conf" ] && echo "/etc/supervisord.conf"
  117. [ -e "/etc/init.d/supervisord" ] && echo "/etc/init.d/supervisord"
  118. }
  119. Uninstall_HHVM() {
  120. [ -e "/etc/init.d/supervisord" ] && { service supervisord stop > /dev/null 2>&1; rm -rf /etc/supervisord.conf /etc/init.d/supervisord; }
  121. [ -e "/usr/bin/hhvm" ] && { rpm -e hhvm; rm -rf /etc/hhvm /var/log/hhvm /usr/bin/hhvm; }
  122. echo "${CMSG}HHVM uninstall completed${CEND}"
  123. }
  124. Print_PureFtpd() {
  125. [ -e "$pureftpd_install_dir" ] && echo "$pureftpd_install_dir"
  126. [ -e "/etc/init.d/pureftpd" ] && echo "/etc/init.d/pureftpd"
  127. }
  128. Uninstall_PureFtpd() {
  129. [ -e "$pureftpd_install_dir" ] && { service pureftpd stop > /dev/null 2>&1; rm -rf $pureftpd_install_dir /etc/init.d/pureftpd; }
  130. echo "${CMSG}Pureftpd uninstall completed${CEND}"
  131. }
  132. Print_Redis() {
  133. [ -e "$redis_install_dir" ] && echo "$redis_install_dir"
  134. [ -e "/etc/init.d/redis-server" ] && echo "/etc/init.d/redis-server"
  135. }
  136. Uninstall_Redis() {
  137. [ -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-*; }
  138. [ -e "${php_install_dir}/etc/php.d/ext-redis.ini" ] && rm -rf ${php_install_dir}/etc/php.d/ext-redis.ini
  139. echo "${CMSG}Redis uninstall completed${CEND}"
  140. }
  141. Print_Memcached() {
  142. [ -e "${memcached_install_dir}" ] && echo "${memcached_install_dir}"
  143. [ -e "/etc/init.d/memcached" ] && echo "/etc/init.d/memcached"
  144. [ -e "/usr/bin/memcached" ] && echo "/usr/bin/memcached"
  145. }
  146. Uninstall_Memcached() {
  147. [ -e "${memcached_install_dir}" ] && { service memcached stop > /dev/null 2>&1; rm -rf ${memcached_install_dir} /etc/init.d/memcached /usr/bin/memcached; }
  148. [ -e "${php_install_dir}/etc/php.d/ext-memcache.ini" ] && rm -rf ${php_install_dir}/etc/php.d/ext-memcache.ini
  149. [ -e "${php_install_dir}/etc/php.d/ext-memcached.ini" ] && rm -rf ${php_install_dir}/etc/php.d/ext-memcached.ini
  150. echo "${CMSG}Memcached uninstall completed${CEND}"
  151. }
  152. Menu(){
  153. while :; do
  154. printf "
  155. What Are You Doing?
  156. \t${CMSG}0${CEND}. Uninstall All
  157. \t${CMSG}1${CEND}. Uninstall Nginx/Tengine/Apache/Tomcat
  158. \t${CMSG}2${CEND}. Uninstall MySQL/MariaDB/Percona/AliSQL
  159. \t${CMSG}3${CEND}. Uninstall PHP
  160. \t${CMSG}4${CEND}. Uninstall HHVM
  161. \t${CMSG}5${CEND}. Uninstall PureFtpd
  162. \t${CMSG}6${CEND}. Uninstall Redis
  163. \t${CMSG}7${CEND}. Uninstall Memcached
  164. \t${CMSG}q${CEND}. Exit
  165. "
  166. echo
  167. read -p "Please input the correct option: " Number
  168. if [[ ! $Number =~ ^[0-7,q]$ ]]; then
  169. echo "${CWARNING}input error! Please only input 0,1,2,3,4,5,6,7 and q${CEND}"
  170. else
  171. case "$Number" in
  172. 0)
  173. Print_Warn
  174. Print_web
  175. Print_DB
  176. Print_PHP
  177. Print_HHVM
  178. Print_PureFtpd
  179. Print_Redis
  180. Print_Memcached
  181. Uninstall_status
  182. if [ "${uninstall_yn}" == 'y' ]; then
  183. Uninstall_Web
  184. Uninstall_DB
  185. Uninstall_PHP
  186. Uninstall_HHVM
  187. Uninstall_PureFtpd
  188. Uninstall_Redis
  189. Uninstall_Memcached
  190. else
  191. exit
  192. fi
  193. ;;
  194. 1)
  195. Print_Warn
  196. Print_web
  197. Uninstall_status
  198. [ "${uninstall_yn}" == 'y' ] && Uninstall_Web || exit
  199. ;;
  200. 2)
  201. Print_Warn
  202. Print_DB
  203. Uninstall_status
  204. [ "${uninstall_yn}" == 'y' ] && Uninstall_DB || exit
  205. ;;
  206. 3)
  207. Print_PHP
  208. Uninstall_status
  209. [ "${uninstall_yn}" == 'y' ] && Uninstall_PHP || exit
  210. ;;
  211. 4)
  212. Print_HHVM
  213. Uninstall_status
  214. [ "${uninstall_yn}" == 'y' ] && Uninstall_HHVM || exit
  215. ;;
  216. 5)
  217. Print_PureFtpd
  218. Uninstall_status
  219. [ "${uninstall_yn}" == 'y' ] && Uninstall_PureFtpd || exit
  220. ;;
  221. 6)
  222. Print_Redis
  223. Uninstall_status
  224. [ "${uninstall_yn}" == 'y' ] && Uninstall_Redis || exit
  225. ;;
  226. 7)
  227. Print_Memcached
  228. Uninstall_status
  229. [ "${uninstall_yn}" == 'y' ] && Uninstall_Memcached || exit
  230. ;;
  231. q)
  232. exit
  233. ;;
  234. esac
  235. fi
  236. done
  237. }
  238. if [ $# == 0 ]; then
  239. Menu
  240. elif [ $# == 1 ]; then
  241. case $1 in
  242. all)
  243. Print_Warn
  244. Print_web
  245. Print_DB
  246. Print_PHP
  247. Print_HHVM
  248. Print_PureFtpd
  249. Print_Redis
  250. Print_Memcached
  251. Uninstall_status
  252. if [ "${uninstall_yn}" == 'y' ]; then
  253. Uninstall_Web
  254. Uninstall_DB
  255. Uninstall_PHP
  256. Uninstall_HHVM
  257. Uninstall_PureFtpd
  258. Uninstall_Redis
  259. Uninstall_Memcached
  260. else
  261. exit
  262. fi
  263. ;;
  264. web)
  265. Print_Warn
  266. Print_web
  267. Uninstall_status
  268. [ "${uninstall_yn}" == 'y' ] && Uninstall_Web || exit
  269. ;;
  270. db)
  271. Print_Warn
  272. Print_DB
  273. Uninstall_status
  274. [ "${uninstall_yn}" == 'y' ] && Uninstall_DB || exit
  275. ;;
  276. php)
  277. Print_PHP
  278. Uninstall_status
  279. [ "${uninstall_yn}" == 'y' ] && Uninstall_PHP || exit
  280. ;;
  281. hhvm)
  282. Print_HHVM
  283. Uninstall_status
  284. [ "${uninstall_yn}" == 'y' ] && Uninstall_HHVM || exit
  285. ;;
  286. pureftpd)
  287. Print_PureFtpd
  288. Uninstall_status
  289. [ "${uninstall_yn}" == 'y' ] && Uninstall_PureFtpd || exit
  290. ;;
  291. redis)
  292. Print_Redis
  293. Uninstall_status
  294. [ "${uninstall_yn}" == 'y' ] && Uninstall_Redis || exit
  295. ;;
  296. memcached)
  297. Print_Memcached
  298. Uninstall_status
  299. [ "${uninstall_yn}" == 'y' ] && Uninstall_Memcached || exit
  300. ;;
  301. *)
  302. Usage
  303. ;;
  304. esac
  305. else
  306. Usage
  307. fi