uninstall.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. # http://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 http://oneinstack.com #
  17. #######################################################################
  18. "
  19. . ./options.conf
  20. . ./include/color.sh
  21. . ./include/get_char.sh
  22. . ./include/check_db.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
  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. [ -e "/etc/init.d/nginx" ] && echo '/etc/init.d/nginx'
  57. [ -e "/etc/logrotate.d/nginx" ] && echo '/etc/logrotate.d/nginx'
  58. [ -d "$apache_install_dir" ] && echo "$apache_install_dir"
  59. [ -e "/etc/init.d/httpd" ] && echo "/etc/init.d/httpd"
  60. [ -e "/etc/logrotate.d/apache" ] && echo "/etc/logrotate.d/apache"
  61. [ -d "$tomcat_install_dir" ] && echo "$tomcat_install_dir"
  62. [ -e "/etc/init.d/tomcat" ] && echo "/etc/init.d/tomcat"
  63. [ -e "/etc/logrotate.d/tomcat" ] && echo "/etc/logrotate.d/tomcat"
  64. [ -d "/usr/java" ] && echo '/usr/java'
  65. }
  66. Uninstall_Web() {
  67. [ -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; }
  68. [ -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; }
  69. [ -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; }
  70. [ -d "$tomcat_install_dir" ] && { killall java > /dev/null 2>&1; rm -rf $tomcat_install_dir /etc/init.d/tomcat; }
  71. [ -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; }
  72. [ -e "$wwwroot_dir" ] && /bin/mv ${wwwroot_dir}{,$(date +%Y%m%d%H)}
  73. sed -i 's@^website_name=.*@website_name=@' ./options.conf
  74. sed -i 's@^local_bankup_yn=.*@local_bankup_yn=y@' ./options.conf
  75. sed -i 's@^remote_bankup_yn=.*@remote_bankup_yn=n@' ./options.conf
  76. echo "${CMSG}Web uninstall completed${CEND}"
  77. }
  78. Print_DB() {
  79. [ -e "$db_install_dir" ] && echo "$db_install_dir"
  80. [ -e "/etc/init.d/mysqld" ] && echo "/etc/init.d/mysqld"
  81. [ -e "/etc/my.cnf" ] && echo "/etc/my.cnf"
  82. }
  83. Uninstall_DB() {
  84. [ -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}*.conf; }
  85. id -u mysql >/dev/null 2>&1 ; [ $? -eq 0 ] && userdel mysql
  86. [ -e "$db_data_dir" ] && /bin/mv ${db_data_dir}{,$(date +%Y%m%d%H)}
  87. sed -i 's@^dbrootpwd=.*@dbrootpwd=@' ./options.conf
  88. sed -i "s@$db_install_dir/bin:@@" /etc/profile
  89. echo "${CMSG}DB uninstall completed${CEND}"
  90. }
  91. Print_PHP() {
  92. [ -e "$php_install_dir" ] && echo "$php_install_dir"
  93. [ -e "/etc/init.d/php-fpm" ] && echo "/etc/init.d/php-fpm"
  94. [ -e "/usr/local/imagemagick" ] && echo "/usr/local/imagemagick"
  95. [ -e "/usr/local/graphicsmagick" ] && echo '/usr/local/graphicsmagick'
  96. }
  97. Uninstall_PHP() {
  98. [ -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; }
  99. [ -e "$php_install_dir/bin/phpize" -a ! -e "$php_install_dir/etc/php-fpm.conf" ] && rm -rf $php_install_dir
  100. [ -e "/usr/local/imagemagick" ] && rm -rf /usr/local/imagemagick
  101. [ -e "/usr/local/graphicsmagick" ] && rm -rf /usr/local/graphicsmagick
  102. sed -i "s@$php_install_dir/bin:@@" /etc/profile
  103. echo "${CMSG}PHP uninstall completed${CEND}"
  104. }
  105. Print_HHVM() {
  106. [ -e "/usr/bin/hhvm" ] && echo "/usr/bin/hhvm"
  107. [ -e "/etc/hhvm" ] && echo "/etc/hhvm"
  108. [ -e "/var/log/hhvm" ] && echo "/var/log/hhvm"
  109. [ -e "/etc/supervisord.conf" ] && echo "/etc/supervisord.conf"
  110. [ -e "/etc/init.d/supervisord" ] && echo "/etc/init.d/supervisord"
  111. }
  112. Uninstall_HHVM() {
  113. [ -e "/etc/init.d/supervisord" ] && { service supervisord stop > /dev/null 2>&1; rm -rf /etc/supervisord.conf /etc/init.d/supervisord; }
  114. [ -e "/usr/bin/hhvm" ] && { rpm -e hhvm; rm -rf /etc/hhvm /var/log/hhvm /usr/bin/hhvm; }
  115. echo "${CMSG}HHVM uninstall completed${CEND}"
  116. }
  117. Print_PureFtpd() {
  118. [ -e "$pureftpd_install_dir" ] && echo "$pureftpd_install_dir"
  119. [ -e "/etc/init.d/pureftpd" ] && echo "/etc/init.d/pureftpd"
  120. }
  121. Uninstall_PureFtpd() {
  122. [ -e "$pureftpd_install_dir" ] && { service pureftpd stop > /dev/null 2>&1; rm -rf $pureftpd_install_dir /etc/init.d/pureftpd; }
  123. echo "${CMSG}Pureftpd uninstall completed${CEND}"
  124. }
  125. Print_Redis() {
  126. [ -e "$redis_install_dir" ] && echo "$redis_install_dir"
  127. [ -e "/etc/init.d/redis-server" ] && echo "/etc/init.d/redis-server"
  128. }
  129. Uninstall_Redis() {
  130. [ -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-*; }
  131. [ -e "$php_install_dir/bin/phpize" ] && sed -i '/redis.so/d' $php_install_dir/etc/php.ini
  132. echo "${CMSG}Redis uninstall completed${CEND}"
  133. }
  134. Print_Memcached() {
  135. [ -e "$memcached_install_dir" ] && echo "$memcached_install_dir"
  136. [ -e "/etc/init.d/memcached" ] && echo "/etc/init.d/memcached"
  137. [ -e "/usr/bin/memcached" ] && echo "/usr/bin/memcached"
  138. }
  139. Uninstall_Memcached() {
  140. [ -e "$memcached_install_dir" ] && { service memcached stop > /dev/null 2>&1; rm -rf $memcached_install_dir /etc/init.d/memcached /usr/bin/memcached; }
  141. [ -e "$php_install_dir/bin/phpize" ] && sed -i '/memcache.so/d' $php_install_dir/etc/php.ini
  142. [ -e "$php_install_dir/bin/phpize" ] && sed -i '/memcached.so/d' $php_install_dir/etc/php.ini
  143. echo "${CMSG}Memcached uninstall completed${CEND}"
  144. }
  145. Menu(){
  146. while :
  147. do
  148. printf "
  149. What Are You Doing?
  150. \t${CMSG}0${CEND}. Uninstall All
  151. \t${CMSG}1${CEND}. Uninstall Nginx/Tengine/Apache/Tomcat
  152. \t${CMSG}2${CEND}. Uninstall MySQL/MariaDB/Percona
  153. \t${CMSG}3${CEND}. Uninstall PHP
  154. \t${CMSG}4${CEND}. Uninstall HHVM
  155. \t${CMSG}5${CEND}. Uninstall PureFtpd
  156. \t${CMSG}6${CEND}. Uninstall Redis
  157. \t${CMSG}7${CEND}. Uninstall Memcached
  158. \t${CMSG}q${CEND}. Exit
  159. "
  160. echo
  161. read -p "Please input the correct option: " Number
  162. if [[ ! $Number =~ ^[0-7,q]$ ]];then
  163. echo "${CWARNING}input error! Please only input 0,1,2,3,4,5,6,7 and q${CEND}"
  164. else
  165. case "$Number" in
  166. 0)
  167. Print_Warn
  168. Print_web
  169. Print_DB
  170. Print_PHP
  171. Print_HHVM
  172. Print_PureFtpd
  173. Print_Redis
  174. Print_Memcached
  175. Uninstall_status
  176. if [ "$uninstall_yn" == 'y' ];then
  177. Uninstall_Web
  178. Uninstall_DB
  179. Uninstall_PHP
  180. Uninstall_HHVM
  181. Uninstall_PureFtpd
  182. Uninstall_Redis
  183. Uninstall_Memcached
  184. else
  185. exit
  186. fi
  187. ;;
  188. 1)
  189. Print_Warn
  190. Print_web
  191. Uninstall_status
  192. [ "$uninstall_yn" == 'y' ] && Uninstall_Web || exit
  193. ;;
  194. 2)
  195. Print_Warn
  196. Print_DB
  197. Uninstall_status
  198. [ "$uninstall_yn" == 'y' ] && Uninstall_DB || exit
  199. ;;
  200. 3)
  201. Print_PHP
  202. Uninstall_status
  203. [ "$uninstall_yn" == 'y' ] && Uninstall_PHP || exit
  204. ;;
  205. 4)
  206. Print_HHVM
  207. Uninstall_status
  208. [ "$uninstall_yn" == 'y' ] && Uninstall_HHVM || exit
  209. ;;
  210. 5)
  211. Print_PureFtpd
  212. Uninstall_status
  213. [ "$uninstall_yn" == 'y' ] && Uninstall_PureFtpd || exit
  214. ;;
  215. 6)
  216. Print_Redis
  217. Uninstall_status
  218. [ "$uninstall_yn" == 'y' ] && Uninstall_Redis || exit
  219. ;;
  220. 7)
  221. Print_Memcached
  222. Uninstall_status
  223. [ "$uninstall_yn" == 'y' ] && Uninstall_Memcached || exit
  224. ;;
  225. q)
  226. exit
  227. ;;
  228. esac
  229. fi
  230. done
  231. }
  232. if [ $# == 0 ];then
  233. Menu
  234. elif [ $# == 1 ];then
  235. case $1 in
  236. all)
  237. Print_Warn
  238. Print_web
  239. Print_DB
  240. Print_PHP
  241. Print_HHVM
  242. Print_PureFtpd
  243. Print_Redis
  244. Print_Memcached
  245. Uninstall_status
  246. if [ "$uninstall_yn" == 'y' ];then
  247. Uninstall_Web
  248. Uninstall_DB
  249. Uninstall_PHP
  250. Uninstall_HHVM
  251. Uninstall_PureFtpd
  252. Uninstall_Redis
  253. Uninstall_Memcached
  254. else
  255. exit
  256. fi
  257. ;;
  258. web)
  259. Print_Warn
  260. Print_web
  261. Uninstall_status
  262. [ "$uninstall_yn" == 'y' ] && Uninstall_Web || exit
  263. ;;
  264. db)
  265. Print_Warn
  266. Print_DB
  267. Uninstall_status
  268. [ "$uninstall_yn" == 'y' ] && Uninstall_DB || exit
  269. ;;
  270. php)
  271. Print_PHP
  272. Uninstall_status
  273. [ "$uninstall_yn" == 'y' ] && Uninstall_PHP || exit
  274. ;;
  275. hhvm)
  276. Print_HHVM
  277. Uninstall_status
  278. [ "$uninstall_yn" == 'y' ] && Uninstall_HHVM || exit
  279. ;;
  280. pureftpd)
  281. Print_PureFtpd
  282. Uninstall_status
  283. [ "$uninstall_yn" == 'y' ] && Uninstall_PureFtpd || exit
  284. ;;
  285. redis)
  286. Print_Redis
  287. Uninstall_status
  288. [ "$uninstall_yn" == 'y' ] && Uninstall_Redis || exit
  289. ;;
  290. memcached)
  291. Print_Memcached
  292. Uninstall_status
  293. [ "$uninstall_yn" == 'y' ] && Uninstall_Memcached || exit
  294. ;;
  295. *)
  296. Usage
  297. ;;
  298. esac
  299. else
  300. Usage
  301. fi