uninstall.sh 14 KB

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