uninstall.sh 14 KB

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